Running an SSH server on your Android phone lets you execute commands, manage files, or run scripts from any computer on the same network – all without rooting the device. The solution uses Termux, a lightweight Linux environment that runs in user space, and the OpenSSH package that ships with it. Below is a complete, hands‑on walkthrough that takes you from a fresh device to a permanently‑running SSH daemon.
/storage/xxxx-xxxx.pkg update && pkg upgrade -y
openssh-server utilities:
pkg install openssh -y
termux-services (provides sv to manage daemons) and termux-boot (for auto‑start):
pkg install termux-services termux-boot -y
Running the daemon as the default u0_aXXX user works, but creating a separate, non‑privileged Unix user makes key management cleaner.
pkg install proot -y
proot-distro install alpine
proot-distro login alpine
sshuser and set a password (you will later use key‑auth, so the password is just a fallback):
adduser sshuser
passwd sshuser
exit) and return to the main Termux session.sshuser is accessible:
mkdir -p /data/data/com.termux/files/home/sshuser/.ssh
If you skip the chroot step, simply use the default Termux home directory (/data/data/com.termux/files/home) and treat it as the SSH user’s home.
Key‑based authentication is far more secure than password login. Generate a key pair on the Android device and copy the public key to the authorized_keys file.
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_ed25519 -N ""
-t ed25519 creates a modern, small key.-a 100 adds 100 KDF rounds for extra hardening.-N "" leaves the passphrase empty – you can add one later if you wish.chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
authorized_keys file and add the public key:
cat ~/.ssh/id_ed25519.pub > ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
Now the device can accept SSH connections that present the matching private key.
OpenSSH reads a configuration file at /data/data/com.termux/files/usr/etc/ssh/sshd_config. Adjust a few options for security and convenience.
nano (install it if needed: pkg install nano):
nano $PREFIX/etc/ssh/sshd_config
# Disable password authentication – rely on keys only
PasswordAuthentication no
# Permit only the user you created (replace with your actual user)
AllowUsers sshuser
# Change the default port if you want to avoid automated scans (optional)
#Port 2222
# Restrict login to the local network (optional, see firewall section)
#ListenAddress 192.168.1.100
Ctrl+O, Enter, Ctrl+X).sshd -t
If nothing is printed, the file is syntactically correct.sshd -D
You should see a line like Server listening on 0.0.0.0 port 8022. If you changed the port, the number will differ.
ssh -i /path/to/private/key -p 8022 sshuser@ANDROID_IP
Replace ANDROID_IP with the phone’s IP address (check with ifconfig or ip addr inside Termux).
Ctrl+C in Termux to stop the foreground daemon.Android kills background processes when the screen turns off, but the termux-services package can keep a daemon alive, and termux-boot lets you launch scripts automatically after a reboot.
sshd service:
sv enable sshd
sv status sshd
You should see run: sshd.~/.termux/boot directory that runs scripts after each boot.mkdir -p ~/.termux/boot
cat > ~/.termux/boot/start-ssh.sh <<'EOF'
#!/data/data/com.termux/files/usr/bin/sh
# Ensure the service is enabled (idempotent)
sv enable sshd
# Start it if it isn’t already running
sv up sshd
EOF
chmod +x ~/.termux/boot/start-ssh.sh
sv status sshd
If the service does not start, check the boot log with logcat | grep termux to see any permission errors.
Running a network service on a mobile device introduces attack surface. Below are quick hardening steps.
sshd_config and set Port 2222. Remember to update the client command.PermitRootLogin no is present (it is by default in Termux).ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N "" -q -b 256 and replace the public key on the server.ssh -i ~/.ssh/id_ed25519 -p 8022 sshuser@192.168.1.45
ssh -i C:\Users\You\.ssh\id_ed25519 -p 8022 sshuser@192.168.1.45
Install a terminal app (e.g., Termux) or an SSH client like JuiceSSH. In JuiceSSH add a new host:
192.168.1.458022sshuser~/.ssh/authorized_keys on the phone).ip addr show wlan0 inside Termux.Allow inbound on port 8022 is enabled for the Termux app.cat ~/.ssh/authorized_keys on the phone and compare.authorized_keys file permissions are 600 and the .ssh directory is 700.PasswordAuthentication yes, you can temporarily enable password login to test the connection, then switch back.sshd service with sv enable sshd and confirm it is marked as run.ss -ltnp | grep :8022 to see which process occupies the port. If another app uses it, change the SSH port in sshd_config and restart the service.pkg update && pkg upgrade -y.~/.ssh/authorized_keys file and remove stale keys.sv disable sshd
and remove the boot script from ~/.termux/boot.With these steps completed, your Android phone now runs a lightweight, secure SSH server that survives reboots and can be reached from any device on your local network. The same setup can be extended to remote access over the Internet by configuring port‑forwarding on your router, but remember that exposing SSH to the public internet carries additional risks – always keep key‑based auth, a non‑standard port, and a strong firewall rule.
Enjoy the flexibility of managing your Android device from the comfort of a terminal, whether you’re automating backups, tweaking system files, or just experimenting with Linux commands on the go.









