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
To make sure it is enabled:
sudo systemctl status ssh
π 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
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
or:
w
And to see the login history:
last -i
And detailed SSH logs:
sudo journalctl -u ssh
π 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
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}')."
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
- Find the PID with:
ps aux | grep sshd
- Then:
sudo kill -9 [PID]
π Block the offending IP with UFW
sudo ufw deny from 192.168.1.17
π« Prevent specific user login
In the SSH configuration file:
sudo nano /etc/ssh/sshd_config
Add:
DenyUsers ali
And then restart SSH:
sudo systemctl restart ssh
β Close SSH completely
To stop SSH completely:
sudo systemctl stop ssh
And to prevent SSH from running automatically on reboot:
sudo systemctl disable ssh
π 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)