SSH or secure shell is a communications protocol that lets you access a server remotely using the terminal. As you can probably guess by the name, the connection between the client and the server is encrypted.
By default, when you first install Ubuntu, SSH access is disabled for security reasons. So if you’re looking to access your server (or Ubuntu machine) remotely via SSH, you’re going to have to enable SSH on the server machine.
In this article, we’re going over how to enable SSH on Ubuntu 20.04 and 18.04 editions.
How to enable SSH on Ubuntu 20.04 and 18.04?
Enabling and working with SSH on Ubuntu is rather straightforward. Follow these steps.
Step 1: Open the Ubuntu terminal using the Ctrl + Alt +T keyboard shortcut and type in the following commands to install the openssh-server package.
sudo apt update
sudo apt install openssh-server
The SSH server will start automatically once the installation is complete. To check if the server is running or not, use the following command.
sudo systemctl status ssh
Step 2: If your UFW firewall is enabled, you’re going to have to open the SSH port to access your machine.
sudo ufw allow ssh
And that’s all you need to do to enable SSH on Ubuntu 20.04 and 18.04 editions. Now to access your machine, you can either use the inbuilt SSH clients that come in the macOS and Linux terminals, or if you’re on Windows, we recommend using PuTTY.
Also read: How to install themes in Ubuntu?
How to connect to the SSH server?
Enabling SSH on Ubuntu is rather easy; however, connecting to the machine can be a headache depending on how you plan to access your server.
Usually, you’d use this command to connect to an SSH server
Here username is the username you want to access on the server, and public-ip-address is the publically visible IP of the server. If you’re working on a local network, you can get away with local IP addresses as well.
Connecting to SSH behind a NAT
If you’re trying to access an SSH server on your home machine running behind a router, you’re most probably going to have to set up port forwarding for port 22 on your router.
Port 22 is the default SSH port used as a bridge between the server and the client. Most home use routers will have this port blocked out for security reasons, but you can set up port forwarding on your router to open the port.
Since firmware differs between different router manufacturers, there’s no standardised method to do this, but you can look up your router’s manual and find the steps you need to follow.
Note that you’ll also need the public IP for your router to connect to the SSH server. You can find out your public IP by using sites like whatismyip.com or whatismyipaddress.com. If you’re feeling lazy, you can Google it as well.
Also read: How to remove a Directory in Linux?
How to disable SSH on Ubuntu?
It’s good practice to disable communication protocols you’re not actively using. To disable SSH on Ubuntu, use the following command.
sudo systemctl disable --now ssh
You can re-enable SSH anytime using the same command with a slight change.
sudo systemctl enable --now ssh
Also read: How to clear apt cache?