Running Linux Terminal through Flutter App using Firebase

Apeksh Agarwal
3 min readOct 1, 2020

In this project, I made a Flutter app through which you can run Linux terminal commands.

Overview:

A short overview of this project is that in this app you can run your Linux commands which behind the scene run on an Linux server in cloud through cgi and then the output is stored in Firebase and the data is retrieved from there to the app.

Pre-Requisites:

  1. Knowledge of Flutter
  2. Knowledge of Authentication and Firestore in Firebase
  3. Knowledge of cgi and web-server in Linux
  4. How to query through url
  5. My repository: https://github.com/Apeksh742/Flutter_linux_terminal

Here we go:

Step 1: Create a flutter project and link it with your Firebase account. I have already discussed on how to connect your app to Firebase console. You can refer that blog from here.

Step 2: I also implemented a Firebase Authentication method in this app to get a unique uid of every user to create unique document . If you know authentication, you can implement otherwise you can use from my repository.

Step 3: Run a Linux server on a cloud platform. In that server do following necessary actions:

  • Install httpd server and we will create a python cgi file which will run commands on that server. Run below commands in respective order.
yum install httpdsystemctl start httpd cd /var/www/cgi-binvim cmd.py

Then save the file and make it executable chmod +x cmd.py . It will look like this

  • You will also have to modify user permissions in the server. It is a must step.
vim /etc/sudoers

In this add below lines properly and then forcefully save and exit.

root    ALL=(ALL)  ALL   # Already Present
apache ALL=(ALL) NOPASSWD: ALL #Add this

Step 4: Now you can test this by running on your browser.

hhtp://<public-ip>/cgi-bin/cmd.py?x=<command>

If you see the output like this, then you are good to proceed further otherwise you have made some mistake.

Step 4: Use http package from flutter packages. Then create a method to do query task on the web-server. I used TextFormField to get command from the user.

Then for showing live updates, i have used Stream Builder in my Widget tree for that.

For complete widgets and UI part (although i have made that very simple ), you can refer from my github repo.

That’s it for this task.

Few sample shots are given below:

Below photo shows data of different users in stored in Firestore .

So that’s it folks for this blog. Hope you liked it. See you in next blog.

LinkedIn Profile: https://www.linkedin.com/in/apeksh-agarwal-0543bb192/

Github Profile: https://github.com/Apeksh742

--

--