SSH lets you control your Ubuntu computer from another machine over the network
SSH (find Shell) is a way to log into and control a computer remotely. When you enable SSH on Ubuntu, you can open a terminal on another computer — your laptop, a server, or even your phone — type commands, and run them on your Ubuntu machine as if you were sitting at it. The connection is encrypted, so your password and commands stay private.
Most Ubuntu machines do not have SSH turned on by default. You need to install the SSH server software, start it, and then you can connect from elsewhere. The whole process takes about five minutes if you have administrator access to the Ubuntu machine.
Key Takeaways
- SSH is not installed on Ubuntu by default, so you must install the openssh-server package first using the apt package manager.
- After installation, the SSH service starts automatically, but you can check its status and restart it if needed using systemctl commands.
- You need your Ubuntu machine's IP address to connect to it remotely; find it by typing hostname -I in the terminal.
- Once SSH is running, you connect from another machine by typing ssh username@ip-address in a terminal and entering your password.
- SSH works over your local network by default; connecting from the internet requires port forwarding on your router and carries security risks.
Install the SSH server on Ubuntu
Open a terminal on your Ubuntu machine. You can do this by pressing Ctrl+Alt+T, or by clicking the Activities button and typing "terminal".
Type this command and press Enter:
sudo apt update
This refreshes the list of available software. It will ask for your password. Type it and press Enter.
Now type this command:
sudo apt install openssh-server
Press Enter. The system will show you how much disk space the software needs and ask if you want to continue. Type y and press Enter. The installation takes a minute or two depending on your internet speed.
Check that SSH is running
After installation finishes, SSH starts automatically. To confirm it is running, type this command:
sudo systemctl status ssh
You should see output that says "active (running)" in green. If it says "inactive (dead)", type this command to start it:
sudo systemctl start ssh
To make sure SSH starts every time you reboot your Ubuntu machine, type:
sudo systemctl enable ssh
You only need to run this command once. After that, SSH will turn on automatically whenever the machine boots.
Find your Ubuntu machine's IP address
To connect to your Ubuntu machine from another computer, you need its IP address — a unique number that identifies it on your network. In the same terminal, type:
hostname -I
You will see one or more numbers separated by spaces, like 192.168.1.50. This is your machine's IP address on your local network. Write it down or copy it.
If you see multiple addresses, the one starting with 192.168 or 10. is usually the one you want. Ignore addresses that start with 127.
Connect to your Ubuntu machine from another computer
On the computer you want to connect from — your laptop, desktop, or another machine — open a terminal. On Windows, you can use PowerShell (right-click the Start button and select "Windows PowerShell"). On Mac or Linux, open Terminal.
Type this command, replacing username with your Ubuntu login name and 192.168.1.50 with the IP address you found:
ssh username@192.168.1.50
Press Enter. The first time you connect, you will see a message asking if you trust this computer. Type yes and press Enter. Then type your Ubuntu password and press Enter. You are now logged in remotely. Any command you type runs on the Ubuntu machine.
To disconnect, type exit and press Enter.
SSH over the internet requires extra setup and carries risks
The steps above work on your local network — the same WiFi or ethernet network your Ubuntu machine is on. If you want to connect from outside your home or office network, you need to set up port forwarding on your router, which is more complex and exposes your machine to the internet.
If you do set up internet access, change your SSH password to something very strong, or better yet, use SSH keys instead of passwords. SSH keys are harder to break into than passwords. You can learn about them in your SSH server's documentation, but they require extra setup steps.
For most people, SSH over the local network is enough. If you need remote access from anywhere, consider using a VPN (Virtual Private Network) instead, which is safer than exposing SSH directly to the internet.
Troubleshooting common SSH problems
If you cannot connect, first check that SSH is still running by typing sudo systemctl status ssh on the Ubuntu machine. If it says "inactive", run sudo systemctl start ssh again.
If you get a "connection refused" error, double-check the IP address. Type hostname -I again on the Ubuntu machine and make sure you are using the right number. Also make sure both computers are on the same network.
If you get a "permission denied" error, you typed the wrong password or the wrong username. Try again, paying attention to uppercase and lowercase letters — passwords are case-sensitive.
Frequently Asked Questions
Can I use SSH on a computer that is turned off?
No. Your Ubuntu machine must be powered on and connected to the network. If you need to turn it on remotely, you would need to set up Wake-on-LAN, which is a separate feature that lets you send a signal to wake the machine from sleep or hibernation.
Is SSH safe to use?
SSH is safe on your local network. The connection is encrypted, so no one on your WiFi can read your password or commands. On the internet, SSH is less safe because attackers can try to guess your password. Using SSH keys instead of passwords makes it much safer for internet use.
Can I use SSH on Windows or Mac?
Yes. Windows 10 and later have SSH built into PowerShell. Mac and Linux have it in Terminal. You use the same ssh username@ip-address command on all three systems to connect to your Ubuntu machine.
What if I forget my Ubuntu password?
You will not be able to connect via SSH without the correct password. You would need to log in directly on the Ubuntu machine to reset it, or boot into recovery mode. This is why SSH passwords should be something you can remember or store securely.
Do I need to do anything special to use SSH on a laptop that moves between networks?
No. SSH works the same way whether you are on your home WiFi, your office network, or a coffee shop network — as long as both computers are on the same network. If your Ubuntu machine is on a different network, you cannot reach it unless you set up port forwarding and internet access, which is more advanced.