Ever wanted to access your Android phone's terminal from your Linux desktop? Whether you're transferring files, running commands remotely, or just exploring your device's capabilities, SSH access opens up a world of possibilities. However, getting that initial connection working can be frustrating when you're met with cryptic "Access Denied" errors.
This guide will walk you through setting up a reliable SSH connection between your Pop!_OS machine and Android device using Termux, troubleshooting common issues, and ensuring secure access.
Why SSH to Android?
SSH access to your Android device transforms how you interact with it. You can transfer files without cables, run automated scripts, access your phone's filesystem, and even use it as a development environment. It's particularly useful for developers, system administrators, and anyone who prefers command-line efficiency.
Setting Up Termux for SSH Access
Installing and Configuring Termux
Termux stands out as the most capable terminal emulator for Android. Unlike other solutions, it provides a genuine Linux environment with package management and full SSH server capabilities.
Download Termux from F-Droid rather than Google Play. The F-Droid version receives more frequent updates and has fewer restrictions.
Once installed, open Termux and update the package repositories:
pkg update && pkg upgrade
This ensures you have the latest security patches and features.
Installing OpenSSH Server
Install the OpenSSH server package:
pkg install openssh
Termux's OpenSSH implementation is full-featured and includes all the security features you'd expect from a modern SSH server.
Starting the SSH Service
Launch the SSH daemon:
sshd
The SSH server will start immediately and begin listening for connections. Unlike traditional Linux systems, Termux doesn't use systemd, so the service won't automatically restart on reboot.
Finding Your Android's Network Address
Determine your Android device's IP address:
ip addr show wlan0
Look for the inet
line under the wlan0
interface. You'll see something like 192.168.1.155/24
- the IP address is the part before the slash.
Understanding Termux SSH Configuration
Port Configuration
Here's where many people get stuck: Termux uses port 8022 for SSH, not the standard port 22. This is because Android's security model prevents non-system apps from binding to privileged ports (those below 1024).
Your SSH command will look like this:
ssh -p 8022 [username]@[ip_address]
Username Discovery
Termux uses Android's internal username system. Find your username by running:
whoami
You'll see something like u0_a123
- this is your Android user ID that you'll need for SSH connections.
Configuring Authentication
The Password Authentication Challenge
By default, Termux disables password authentication for security reasons. Most SSH "Access Denied" errors stem from this configuration.
To enable password authentication for testing purposes, first set a password:
passwd
Then edit the SSH configuration:
nano $PREFIX/etc/ssh/sshd_config
Find the line containing PasswordAuthentication
and change it to:
PasswordAuthentication yes
If the line doesn't exist, add it to the file.
Restart the SSH service:
pkill sshd && sshd
Testing the Connection
Now attempt to connect from your Pop!_OS machine:
ssh -p 8022 u0_a123@192.168.1.155
Replace u0_a123
with your actual username and 192.168.1.155
with your Android's IP address.
Setting Up Key-Based Authentication
Why Use SSH Keys?
Password authentication works for testing, but key-based authentication is more secure and convenient. Once set up, you won't need to enter passwords for each connection.
Generating SSH Keys
On your Pop!_OS machine, generate an SSH key pair if you don't already have one:
ssh-keygen -t ed25519 -C "your_email@example.com"
The Ed25519 algorithm provides excellent security with smaller key sizes compared to RSA.
Copying Keys to Android
The easiest method is using ssh-copy-id
:
ssh-copy-id -p 8022 u0_a123@192.168.1.155
This command automatically copies your public key to the Android device's authorized keys file.
If ssh-copy-id
fails, you can manually copy the key:
cat ~/.ssh/id_ed25519.pub | ssh -p 8022 u0_a123@192.168.1.155 'mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys'
Disabling Password Authentication
For better security, disable password authentication once key-based auth is working:
nano $PREFIX/etc/ssh/sshd_config
Change or add:
PasswordAuthentication no
Restart the SSH service:
pkill sshd && sshd
Troubleshooting Common Issues
Connection Refused Errors
If you get "Connection refused," the SSH service isn't running or isn't listening on the expected port. Check if the service is running:
pgrep sshd
If no process ID appears, start the service again:
sshd
Network Connectivity Problems
Ensure both devices are on the same WiFi network. Test basic connectivity:
ping 192.168.1.155
If ping fails, you have a network issue rather than an SSH problem.
Permission Denied with Keys
If key authentication fails, check the key permissions on both devices:
# On Pop!_OS
ls -la ~/.ssh/
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
On Android (via Termux):
chmod 700 ~/.ssh/
chmod 600 ~/.ssh/authorized_keys
Automating SSH Server Startup
Creating a Startup Script
Since Termux doesn't automatically start SSH on boot, create a simple script:
nano ~/start_ssh.sh
Add:
#!/data/data/com.termux/files/usr/bin/bash
sshd
echo "SSH server started on port 8022"
Make it executable:
chmod +x ~/start_ssh.sh
Using Termux:Boot
For automatic startup, install the Termux:Boot add-on from F-Droid. Create a startup script in the required directory:
mkdir -p ~/.termux/boot/
echo 'sshd' > ~/.termux/boot/start_ssh
chmod +x ~/.termux/boot/start_ssh
Advanced Configuration
Custom SSH Configuration
Create an SSH config file on your Pop!_OS machine for easier connections:
nano ~/.ssh/config
Add:
Host android-phone
HostName 192.168.1.155
Port 8022
User u0_a123
IdentityFile ~/.ssh/id_ed25519
Now you can connect simply with:
ssh android-phone
File Transfer Operations
Use SCP for file transfers:
scp -P 8022 file.txt u0_a123@192.168.1.155:~/
Or use rsync for more advanced synchronization:
rsync -avz -e "ssh -p 8022" ~/Documents/ u0_a123@192.168.1.155:~/backup/
Security Considerations
Firewall Configuration
Consider enabling UFW on your Pop!_OS machine and configuring appropriate rules:
sudo ufw allow from 192.168.1.0/24 to any port 22
Regular Security Updates
Keep both systems updated:
# Pop!_OS
sudo apt update && sudo apt upgrade
# Termux
pkg update && pkg upgrade
Conclusion
Setting up SSH access between Pop!_OS and Android via Termux opens up powerful possibilities for file management, remote administration, and development workflows. The key is understanding Termux's unique port configuration and authentication requirements.
Remember that the SSH server in Termux won't survive app kills or device reboots, so you'll need to restart it periodically. Consider this when planning automated workflows or remote access scenarios.
With proper configuration, you'll have a secure, efficient way to access your Android device's terminal from your Linux desktop, making cross-device development and file management significantly easier.
Top comments (0)