Finally decided to use Ubuntu for your Desktop OS? That’s great. Oh, you also have an Ubuntu (cloud) Server? Even better.
You may be using some of our recommended Linux distros for gaming. This tutorial will work on just about any Debian-based distro, including, but not limited to:
- Ubuntu 20.04
- Ubuntu 22.04
- Ubuntu 21.10
- Any flavor of Ubuntu, including Ubuntu MATE, Ubuntu Budgie, Ubuntu GNOME, Kubuntu, Lubuntu, Xubuntu…
- Debian 7, 8, 9 or any other Debian release.
Now, you can directly access your Ubuntu server via the desktop version of Ubuntu, straight from your Terminal. No need for PuTTy or other 3-rd party apps to access your server.
Note that you may already have SSH installed on your Ubuntu, so just try logging into your server or run this command to check if SSH is currently running:
ps -aux | grep ssh
Ok, so onto our SSH installation instructions. You can also install SSH via a GUI, but where’s the fun in that? You already started using a server anyway. So here are the instructions on how to enable SSH via terminal:
Open up Terminal
Either open it via your menu or just press Ctrl + Alt + T
Install OpenSSH
From the official website:
OpenSSH is the premier connectivity tool for remote login with the SSH protocol. It encrypts all traffic to eliminate eavesdropping, connection hijacking, and other attacks. In addition, OpenSSH provides a large suite of secure tunneling capabilities, several authentication methods, and sophisticated configuration options.
In other words, you need to install OpenSSH so you can log into your server.
Install it by running the following command in your terminal:
sudo apt-get install openssh-server -y
After the installation is done, you’ll have SSH enabled on your Ubuntu desktop.
Configure SSH
Now that you’ve installed SSH, you can configure it. Like changing the default port (recommended for security reasons), disabling “root” user login etc.
For now, we’ll just update our default SSH port (which is 22). First, open up the ssh configuration file by running the following command:
sudo nano /etc/ssh/sshd_config
If you don’t have nano installed (it’s a text editor), run this command:
sudo apt-get install nano -y
Once you open the file, find and change the following line from:
# Port 22
to
Port 1337
Use a different port number, whichever one you want to.
Once you are done, save and close the file with Ctrl + W
, then Y
and hit Enter/Return
Before restarting SSH you need to configure your firewall to allow the port you provided before. If you’re using UFW, just run:
sudo ufw allow 1337
You need to check with your internet provider and your modem/router(s) if you need to allow the new port.
Now, restart SSH for the changes to take effect. Run the following command:
sudo service ssh restart
And that’s it. You are done.
Now you can use SSH to log into your server. Just open up Terminal and run:
ssh username@ip -p1337
To log into your server via SSH, right from your Ubuntu desktop terminal. Of course, change ‘username’, ‘ip’ and the port number you’re using on your Ubuntu server
For more information, read this:
11 thoughts on “How to Enable SSH on Ubuntu (22.04, 20.04, 21.10, etc.)”
could you please help with this error
“ssh: connect to host 192.168.43.100 port 535: Connection refused”
I’m a newbie to these Linux system utilites.
The “Connection refused” error can be caused by a number of things. Firewalls, ports, a misconfiguration etc. It’s best if you google the error and try the solutions there.
Yeah.
If I had a dollar for every “Just do this!” that just promptly fails, I’d have 1337 dollars.
I get “Connection refused” after following your instructions verbatim. What did you forget?
The “Connection refused” error can be caused by a number of things. Firewalls, ports, a misconfiguration etc. It’s best if you google the error and try the solutions there.
Here are the useful steps to localize the error (in my case it was wrong value of ListeningAddress in the sshd_config file, but in your case it can be different).
Here is some useful information:
# Set in the /etc/hosts.allow file (which is deprecated, but just for case) your allowed IP range for SSH (correct with your values):
ssh:localhost:allow
sshd:localhost:allow
ssh:192.168.0.:allow
sshd:192.168.0.:allow
# Check authentification-log for authentification/access problems:
sudo grep ‘sshd’ /var/log/auth.log
# Check which addresses and ports the SSH is listening to:
sudo netstat -anp | grep sshd
# check journal for start problems:
journalctl -xe
# Try ssh in the test-mode (if doesn’t start) and check the console message in this case:
sudo sshd -t
# Depending on checks-results above – you will see where to search problem (i.e. service doesn’t run or run, but but listening at wrong adresses or ports, or addresses and ports are correct, but then some rules are missing by firewall etc.).
See how many ways exist to restrict the access for SSH (and there not all ways are listed):
https://askubuntu.com/questions/115940/how-can-i-setup-ssh-so-that-it-is-restricted-to-my-local-network
Did you checked with firewall??? On ubuntu try with this: “sudo ufw status” to see status of your firewall?
If you’re new to UBUNTU or Linux, try on google “Linux Commands” … I’m sure this is firewall problem (allo it and try then….) 😉
Why change the port number?
It’s the default port number and it’s the first one hackers are trying to attack. If it’s not the default one they might skip your IP or at least go through the trouble of scanning/sniffing for your actual port number.
You’re better off actually securing your server with a firewall though.
Thank you! Mine’s on a local network only. I’ve not install UFW but, doing a scan, it seems only ports 22 and 80 are open.
Thanks again – really good guide.
How do I get the password?
Thanks