How to Set Up a Persistent SSH Server on Android Using Termux (No Root)

16 min read Learn step‑by‑step how to turn any Android phone into a persistent SSH server with Termux, without rooting. Includes auto‑start, key‑based auth, and troubleshooting. October 11, 2026 18:30 How to Set Up a Persistent SSH Server on Android Using Termux (No Root)

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.

Before You Start

  • Device requirements: Android 7.0 (Nougat) or newer. Most modern phones meet this.
  • Battery & network: Plug the phone in and connect to a stable Wi‑Fi network. SSH over cellular can work, but it may incur data charges.
  • Permissions: You will need to grant Termux storage access (Settings > Apps > Termux > Permissions > Storage) and allow it to run in the background.
  • Optional – external storage: If you plan to store SSH keys on the SD card, make sure the card is formatted as exFAT or FAT32 and is mounted as /storage/xxxx-xxxx.

Step 1 – Install Termux and Required Packages

  1. Open the Google Play Store (or F-Droid for the latest build) and install Termux.
  2. Launch Termux. The first launch will download additional data – let it finish.
  3. Update the package repository and upgrade existing packages:
    pkg update && pkg upgrade -y
  4. Install OpenSSH and the openssh-server utilities:
    pkg install openssh -y
  5. Install termux-services (provides sv to manage daemons) and termux-boot (for auto‑start):
    pkg install termux-services termux-boot -y
  6. Give Termux permission to run in the background (Android 10+ may require you to disable battery optimisation for Termux under Settings > Apps > Termux > Battery). This ensures the SSH daemon stays alive when the screen is off.

Step 2 – Create a Dedicated SSH User (Optional but Recommended)

Running the daemon as the default u0_aXXX user works, but creating a separate, non‑privileged Unix user makes key management cleaner.

  1. Start a temporary shell as root‑like inside Termux:
    pkg install proot -y
  2. Create a minimal chroot environment (this step is optional; you can skip if you prefer the default user):
    proot-distro install alpine
  3. Enter the Alpine distro:
    proot-distro login alpine
  4. Inside Alpine, add a new user named sshuser and set a password (you will later use key‑auth, so the password is just a fallback):
    adduser sshuser
    passwd sshuser
  5. Exit the distro (type exit) and return to the main Termux session.
  6. Make sure the home directory for 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.

Step 3 – Generate SSH Keys

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.

  1. In the Termux prompt, run:
    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.
  2. Set correct permissions:
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/id_ed25519
  3. Create the 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.

Step 4 – Configure the OpenSSH Daemon

OpenSSH reads a configuration file at /data/data/com.termux/files/usr/etc/ssh/sshd_config. Adjust a few options for security and convenience.

  1. Open the config file with nano (install it if needed: pkg install nano):
    nano $PREFIX/etc/ssh/sshd_config
  2. Make the following changes (add lines if they don’t exist):
    # 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
  3. Save and exit (Ctrl+O, Enter, Ctrl+X).
  4. Test the configuration syntax:
    sshd -t
    If nothing is printed, the file is syntactically correct.

Step 5 – Start the SSH Daemon Manually (First Test)

  1. Start the daemon in the foreground to watch for errors:
    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.

  2. From another device on the same Wi‑Fi (e.g., a laptop), try to connect:
    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).
  3. If the connection succeeds, you have a working SSH server. Press Ctrl+C in Termux to stop the foreground daemon.

Step 6 – Make the SSH Daemon Start at Boot

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.

  1. Enable the sshd service:
    sv enable sshd
  2. Verify that the service starts now:
    sv status sshd
    You should see run: sshd.
  3. Install the Termux:Boot add‑on from the Play Store (or F‑Droid). This creates a ~/.termux/boot directory that runs scripts after each boot.
  4. Create a startup script:
    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
  5. Reboot the phone (or simply toggle airplane mode) and verify that the daemon is running:
    sv status sshd

If the service does not start, check the boot log with logcat | grep termux to see any permission errors.

Step 7 – Harden the Server (Optional but Strongly Recommended)

Running a network service on a mobile device introduces attack surface. Below are quick hardening steps.

  • Change the default port: Edit sshd_config and set Port 2222. Remember to update the client command.
  • Limit network exposure: Use a firewall app such as NetGuard to allow inbound connections only from your home subnet.
  • Disable root login: Ensure PermitRootLogin no is present (it is by default in Termux).
  • Rotate keys periodically: Run ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N "" -q -b 256 and replace the public key on the server.

Step 8 – Connect from Common Clients

From Linux/macOS

ssh -i ~/.ssh/id_ed25519 -p 8022 sshuser@192.168.1.45

From Windows (PowerShell)

ssh -i C:\Users\You\.ssh\id_ed25519 -p 8022 sshuser@192.168.1.45

From Another Android Device

Install a terminal app (e.g., Termux) or an SSH client like JuiceSSH. In JuiceSSH add a new host:

  • Address: 192.168.1.45
  • Port: 8022
  • User: sshuser
  • Authentication: Public key, then point to the private key file you transferred (or generate a new pair on the client and add its public key to ~/.ssh/authorized_keys on the phone).

Step 9 – Troubleshooting Common Issues

Note: Many problems stem from Android’s aggressive battery optimisation or from network configuration mismatches.
  • Cannot connect – timeout
    • Confirm the phone’s IP address hasn’t changed (DHCP lease). Use ip addr show wlan0 inside Termux.
    • Check that the SSH port (default 8022) is not blocked by your router’s firewall.
    • Disable battery optimisation for Termux (Settings > Apps > Termux > Battery > Unrestricted).
    • If you use NetGuard, ensure the rule Allow inbound on port 8022 is enabled for the Termux app.
  • "Permission denied (publickey)"
    • Verify that the public key on the server matches the private key you are using on the client. Run cat ~/.ssh/authorized_keys on the phone and compare.
    • Make sure the authorized_keys file permissions are 600 and the .ssh directory is 700.
    • If you kept PasswordAuthentication yes, you can temporarily enable password login to test the connection, then switch back.
  • SSH daemon stops after screen off
    • Enable the sshd service with sv enable sshd and confirm it is marked as run.
    • In Android 12+, you may need to grant the "Allow background activity" permission (Settings > Apps > Termux > Advanced > Battery).
  • Port already in use
    • 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.

Step 10 – Clean Up and Future Maintenance

  • Regularly update Termux packages: pkg update && pkg upgrade -y.
  • Periodically review the ~/.ssh/authorized_keys file and remove stale keys.
  • If you ever decide to stop using SSH, disable the service:
    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.

User Comments (0)

Add Comment
We'll never share your email with anyone else.