Share files between your phone and laptop

Requirements:
Laptop: openssh, a file manager
Phone: Termux or an SSH server app, a file manager capable of connecting to a file server
Prerequisite: Both devices should be connected to the same network

Getting things ready

Normally, a Linux distro comes with openssh pre-installed. If not, it should be available in your distro’s repository.

Have SSH server run at startup with (run as root)

systemctl enable sshd.service
systemctl start sshd.service

If you are one of those people who uses OpenRC, run (as root)

rc-update add sshd default
rc-service sshd start

If you do not fall in either category, then you probably know what to do.

The config file is /etc/ssh/sshd_config.

On Phone

Now there are multiple ways to get SSH server on your phone. You can get one on Termux, or install one of the several apps on Play Store or F-Droid.

I personally use SSH/SFTP Server – Terminal (contains ads), it is good enough and just werks™. You set up a new username and password, select required directories and start. By default it listens on port 2222 .

If you are using Termux, you can install the openssh package and start with sshd. By default it listens on port 8022.

The config file is `$PREFIX/etc/ssh/sshd_config.

You can have sshd start on boot by configuring Termux:Boot.

Connecting through SFTP

Once you have got the server up and running, all that remains is you connect through SFTP and start transferring files. On your laptop, use a file manager that supports connecting through SFTP (nautilus, dolphin, etc.). You either type the address in the address bar or in a separate “Network Location” (depends on the file manager). Whatever the case, you enter your IP address with port (sftp://[YOUR IP ADDRESS]:[PORT]). It should ask for your username and password (for the machine you are trying to connect). Once you are connected, it should display your files. Now copy files and folders like you normally do.

On your phone, install a file manager that supports SFTP. I use Cx File Explorer. Go to Network > New location > Remote > SFTP. Enter username, password, address and port of your laptop and you should be good to go.

Alternatively, you can also use command line to transfer files using the tool sftp. You connect using sftp -P [port] [username]@[ip address]. This method works both on laptop and in Termux.

Something about SSH

If you are entirely new to SSH, you should look into setting up a key pair for your devices. It is more secure than using your password.

Did you find this article valuable?

Support Aditya's blog by becoming a sponsor. Any amount is appreciated!