We use a smartphone in conjunction with Linux

We use a smartphone in conjunction with Linux

Android and Linux distributions are not just related operating systems – they are based on the same kernel and at a low level are very similar. In Android runs most Linux commands, here you can install the bash, write scripts and even run servers. Installing SSH on your smartphone, you can go to it with the company and even use rsync to synchronize files. That’s all we’ll talk about today.



Let’s start with the favorite tool of all advanced Android users – ADB. We have already written about it many times, but here we just have to repeat ourselves. So, the ADB stands for Android Debug Bridge, and in fact it’s a kind of management system of the smartphone with the company. ADB allows you to install and run the software, move files from and to the device and perform many other tasks.

To configure the ADB in Windows, would have to install drivers and reboot the machine, in Linux it just works. Simply activate ADB on your smartphone (Settings → For developers → Debug via USB) and install the package with the utility adb on your system:

$ sudo apt-get install adb
// Arch Linux
$ sudo pacman -S android-tools android-udev

Then you need to connect your smartphone to the combo and start giving commands.

Get the list of connected devices:

$ adb devices

Installation on a connected APK device:

$ adb install file.apk

Moving a file to the device:

$ adb push file /sdcard/

Download a file from the device:

$ adb pull /sdcard/DCIM/Camera/photo.jpg photo.jpg

Take a screenshot and download it to your computer:

$ adb shell screencap /sdcard/screenshot.png
$ adb pull /sdcard/screenshot.png
$ adb shell rm /sdcard/screenshot.png

Pressing the Power button:

$ adb shell input keyevent 26

And of course, ADB can be used to access the smartphone command line:

$ adb shell

It is important to note that not only can ADB work over USB, it can also work over Wi-Fi, but this requires root rights to the device and the app WiFi ADB. Start the app, turn on the switch, and connect to your smartphone with adb connect and the IP address shown by the app:

$ adb connect IP address

In some distributions ADB may not work without root rights. This happens because there are no special Udev rules in the distribution. You will have to either install them as a separate package (android-udev in Arch Linux), or configure Udev yourself.

Have you already used ADB?

  • Yes, but only by USB
  • Yes, and over Wi-Fi too
  • Still no, we have to try!


ADB can also be used to synchronize files between devices (there is even an option sync), but it is more convenient to use the script adb-sync. All you need to do is download and run it. For example, this way you can synchronize music on your device and on your PC:

$ adb-sync ~/Music/ /sdcard/Music

And so do the same synchronization, but with the removal of files that were deleted on your PC:

$ adb-sync --delete ~/Music/ /sdcard/Music

An easy way to download files to a computer (backwards synchronization):

$ adb-sync --reverse /sdcard/Downloads/ ~/Downloads


Another interesting way to access files on your device using ADB is to use adbfs, a pseudo FS that allows you to mount your device as if it were a flash drive or any other drive.

The easiest way to install adbfs is in Arch Linux. Here it is in the AUR so all you have to do is execute one command:

$ yaourt -S adbfs-rootless-git

In Ubuntu and other systems adbfs will have to be built manually:

$ sudo apt-get install libfuse-dev android-tools-adbb
$ git clone git://github.com/spion/adbfs-rootless.git
$ cd adbfs-rootless 
$ make

And then you can connect the file system:

$ mkdir ~/Android
$ adbfs ~/Android

For shutdown:

$ fusermount -u ~/Android

Why else would you use Adb-sync?

    • A external antivirus scan of new files from your smartphone
    • To accurate time synchronization by atomic clock
    • In order to steal data from smartphones if debugging is allowed



Another option to connect the device as a file system is go-mtpfs, a file system that allows to transfer data via MTP. This is the protocol used in smartphones without a memory card.

In Arch Linux it is very easy to install go-mtpfs:

$ yaourt -S go-mtpfs

In other distributions it is a bit more complicated:

$ sudo apt-get install golang-go libusb1-devel
$ mkdir /tmp/go
$ export GOPATH=/tmp/go
$ go get github.com/hanwen/go-mtpfs
$ go install github.com/hanwen/go-mtpfs

From there it’s as simple as with adbfs:

$ mkdir ~/Android
$ go-mtpfs ~/Android

For shutdown:

$ fusermount -u ~/Android


The idea of using ADB to communicate with the device may seem strange, given that for Android there are several different SSH-servers at once, not requiring root rights. So it is, in many cases SSH will be more convenient and effective. As an implementation of the server, I advise to choose SimpleSSHD, a simple free wrapper for the time-tested SSH server DropBear for embedded systems. If you have a root then I also recommend to install BusyBox On Rails, the command line toolkit closest to Linux distributions.

SimpleSSHD is very easy to use. You start, press START and connect to the specified IP address (port 2222):

$ ssh -p 2222

At the moment of connection, a one-time password will appear on the screen, which you should specify in the client. This is not a very convenient way to authenticate, but you can set up key authentication. Just rename your public key (~/.ssh/id_rsa.pub) to authorized_keys and put it in the ssh directory on your smartphone card.



SimpleSSHDV which article we have already put BusyBox and for what?

    • What to use Kali NetHunter
    • What to make a server from a smartphone and use the standard Linux

commands on it.

    • To work with databases on your smartphone


Bash, tmux, mc

The SSH server on your smartphone itself offers a lot of possibilities, but even more can be done if you install classic tools such as bash, tmux and mc on your smartphone. The latter will also allow you to comfortably walk on the memory card and clean up if necessary.

You can find out how to install the bash, tmux, mc and nano on your smartphone. I will immediately warn you that you will need root rights on your smartphone.

So, download Terminal IDE, rename the APK package to ZIP, unpack it, find assets/system-2.0.tar.gz.mp3, rename it by removing the mp3 extension, and unpack it. There will be a lot of directories and files inside of which we are only interested in system/bin and system/etc/terminfo. The first one contains the utilities we need; copy those you need to use into a separate directory. The second one is necessary for the correct functioning of the utilities.

The selected utilities and the terminfo directory skin the memory card of your smartphone. Then connect to it via SSH and enter the following commands to be able to modify the system directory:

$ su
# mount -o remount,rw /system

Next, copy all the necessary utilities into /system/xbin/ and install the execution bit on them (bash as an example):

# cp bash /system/xbin/
# chmod 755 /system/xbin/bash

Then create a /sdcard/ssh/.bashrc file and put the following lines in it:

export TERMINFO=/sdcard/terminfo
export TMPDIR=/data/local/tmp
export PS1="\[email protected]\h:\w \$".

Open the SimpleSSHD settings on your smartphone and in the Login Shell option specify /system/xbin/bash, stop and restart the server. The next SSH login will open bash and the utilities you copied will be available.

To make sure that Vim and mc work properly, also copy the etc/mc and etc/vim directories to the memory card, and add lines to the /sdcard/ssh/.bashrc file:

export MC_DATADIR=/sdcard/mc
export VIMRUNTIME=/sdcard/vim
Midnight commander running in Android



The SSH server allows us to use rsync, a powerful utility for synchronization and file backup. Rsync allows fast bidirectional synchronization of files between two machines (or a machine and a smartphone, as in our case) with only uploaded new and changed files and the ability to resume interrupted synchronization.

The simplest example of using rsync in conjunction with a smartphone:

$ rsync --update --progress -e 'ssh -p 2222' -azv ~/Photos

This command will copy all the photos from your smartphone into the ~/Photos directory, skipping those already in the directory. Linking the -azv options in this case means that the directory must be passed as is with all its subdirectories and permissions (-a flag) plus the use of compression (-z flag).

The reverse command is to copy data from the machine to your smartphone:

$ rsync --delete --progress -e 'ssh -p 2222' -azv ~/Books

Here we used the --delete flag to remove files that were removed from the local ~/Books directory.

By default, if a connection is broken, rsync will remove partially transferred files. To avoid this, you can use the --partial flag, which will force rsync to save the undelivered files and resume downloading them the next time it runs the command.



Ok, we connected to the smartphone, we synchronized the files, but what if we need the reverse SSH connection from the smartphone to the combo? In this case, any of the dozens of SSH-clients for Android will do (same ConnectBot, for example), if, of course, you are ready to enter commands on the touch keyboard of the small screen.

If you’re not ready, you can choose SSH button which allows you to run the desired command on the desired machine at the touch of a button. The SSH button’s interface is scary, but the application works fine. Just run the SSH button, then Menu → Add… and enter the command you want, SSH server address, login and password.

SSH button is useful to shut down or sleep (systemctl suspend and halt), start and stop torrents, and control music (for example, the mocp player I described in a previous article allows you to control yourself via the command line).



SSH button


Using Android in conjunction with Linux is really convenient. Unlike Windows, it does not need additional drivers, special servers and other strange things. In most cases you can do with standard Linux SSH and rsync, but you can always find more interesting tools on the web.



WARNING! All links in the articles may lead to malicious sites or contain viruses. Follow them at your own risk. Those who purposely visit the article know what they are doing. Do not click on everything thoughtlessly.


0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments

Do NOT follow this link or you will be banned from the site!
Would love your thoughts, please comment.x

Spelling error report

The following text will be sent to our editors: