DEV Community

mohammad hassani
mohammad hassani

Posted on

πŸ“± Connecting to Ubuntu Terminal from Android Phone β€” Step by Step

In this guide, you will learn how to connect to the terminal (SSH) of the Ubuntu system via the Internet or local network with your Android phone and also be able to manage connections, receive notifications, or block people from accessing it.


🧩 1. Enabling SSH on Ubuntu

First, SSH must be installed and enabled on the Ubuntu system:

sudo apt update
sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh
Enter fullscreen mode Exit fullscreen mode

To make sure it is enabled:

sudo systemctl status ssh
Enter fullscreen mode Exit fullscreen mode

🌐 2. Finding the system IP

If the phone and the system are on the same network (for example, shared Wi-Fi), get the system's local IP with this command:

hostname -I
Enter fullscreen mode Exit fullscreen mode

You will see an IP like 192.168.1.100.


πŸ“² 3. Connecting from an Android phone

Install one of the following SSH client apps on your phone:

Enter the connection information:

  • Host/IP: Local or public IP of the system

  • Port: 22

  • Username: Ubuntu username

  • Password: User password

And connect easily.


πŸ•΅οΈβ€β™‚οΈ 4. Find out who is connected?

To see who is connected via SSH:

who
Enter fullscreen mode Exit fullscreen mode

or:

w
Enter fullscreen mode Exit fullscreen mode

And to see the login history:

last -i
Enter fullscreen mode Exit fullscreen mode

And detailed SSH logs:

sudo journalctl -u ssh
Enter fullscreen mode Exit fullscreen mode

πŸ”” 5. Get notified when someone connects

To get a desktop notification when someone connects via SSH, edit the following file:

sudo nano /etc/ssh/sshrc
Enter fullscreen mode Exit fullscreen mode

and add this line to it (replace user_id with your user ID):

DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus notify-send "πŸ” New SSH connection" "User $(whoami) connected from $(echo $SSH_CONNECTION | awk '{print $1}')."
Enter fullscreen mode Exit fullscreen mode

By saving the file and restarting ssh, you will now get a notification every time someone connects.


β›” 6. Block or prevent connections

🎯 Kick out current access

  1. Find the PID with:
ps aux | grep sshd
Enter fullscreen mode Exit fullscreen mode
  1. Then:
sudo kill -9 [PID]
Enter fullscreen mode Exit fullscreen mode

πŸ”’ Block the offending IP with UFW

sudo ufw deny from 192.168.1.17
Enter fullscreen mode Exit fullscreen mode

🚫 Prevent specific user login

In the SSH configuration file:

sudo nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode

Add:

DenyUsers ali
Enter fullscreen mode Exit fullscreen mode

And then restart SSH:

sudo systemctl restart ssh
Enter fullscreen mode Exit fullscreen mode

β›” Close SSH completely

To stop SSH completely:

sudo systemctl stop ssh
Enter fullscreen mode Exit fullscreen mode

And to prevent SSH from running automatically on reboot:

sudo systemctl disable ssh
Enter fullscreen mode Exit fullscreen mode

🌍 Connect via the Internet (if you have a server)

If outside the network Are you local or have a server:

  • Use services like Tailscale or ZeroTier to connect remotely without any hassle.
  • Or set up a VPS server and make your home system accessible via Reverse SSH Tunnel.

🧠 Summary

Tools Applications
openssh-server Setting up SSH on Ubuntu
Termius / JuiceSSH SSH connection from phone
who, ps, ufw Checking and controlling connections
notify-send Notify new user login

πŸ”₯ Now you can control your Linux system from anywhere with your phone β€” with complete security and management!

Top comments (0)