Friday, June 14, 2019

Access Your Android Phone's Storage, using Commands

There are a lot of apps for android, that enable file sharing over wifi. Some of them are free, and some of them are paid. But in this article, I will be sharing a kind of geek way on how to share your android phone's internal storage with your linux machine.

Install an app called termux from the play store. Download the app here: https://play.google.com/store/apps/details?id=com.termux . This app will add terminal emulation to your android
Once installed, allow termux to access to storage. You can do that by going to Settings --> Apps & Notifications --> Termux --> Permissions, and enable Storage

Optional: to make your typing experience better, I recommend this keyboard app: https://play.google.com/store/apps/details?id=org.pocketworkstation.pckeyboard

The http server of our choice is, the python's simple-http server. To use the simple-http, first you need to install python. Run below in your termux console
$ pkg install python -y

Get your phone's ip address. This can be easily done in termux
$ ip a | grep wlan0

Run http.server, to share your phone's internal storage over the wifi. /storage/emulated/0 is the default root directory for android phone's internal storage
$ python -m http.server /storage/emulated/0 

In your PC/laptop/other android, just use a browser to access the phone, via port 8000

Thursday, June 13, 2019

Accessing Android Phone via ssh

Sometimes, for whatever reason, you need to access your phone from your laptop. This can be done by installing openssh inside your phone.

First, you need an app called termux, to enable terminal emulator inside android. The app can be downloaded here, in google play store.

Once installed, fire up termux, and install openssh 
$ pkg install openssh

You need password to login via ssh, so set a password for your current user
$ passwd

You also need to know, what is the current username
$ whoami

Run sshd. By default sshd in termux runs on port 8022
$ sshd

Get the ip address of your android phone
$ ip addr show wlan0

Connect to your phone (replace 192.168.43.200 with the output of the ip addr command), using standard ssh client on linux/mac terminal, or putty on windows
$ ssh u0_a211@192.168.43.200 -p 8022 

In order to browse the whole internal storage of your phone, you need to enable storage permission for termux. That can be done by running:
$ termux-setup-storage

and clicking allow