Ubuntu install OpenSSH is something every Linux user should be familiar with. You don’t have to be a system admin to get comfortable with OpenSSH. Ideally, when you want to connect to a server, ssh is the best secure option to use.
SSH (Secure Shell) is a network protocol that authenticates and creates a secure connection between a server and a client to create a remote connection. This post focuses on installing openssh-server.
How to Install SSH Server
Installing an SSH server is a quick process. You only need to run a few commands, and your server will be all set, waiting for you to connect to it. Follow the steps below.
Step 1: Update Your Repository
Before we install our SSH server, let’s update the repository to ensure we get the latest available SSH server version. For this guide, we are using Ubuntu 22.04, but the steps work for other Ubuntu versions.
Read Also: Snap vs Apt: A Complete Review.
$ sudo apt update
Step 2: Install SSH Server
Ubuntu install openssh is achieved in two ways. If you want to install it on a client machine, you will install openssh-client. However, if installing an SSH server, we will install the openssh-server package.
Run the below command.
$ sudo apt install openssh-server
The openssh-server will check for incoming SSH connection requests from client devices and authenticate them to establish the remote connection. We already have openssh-server installed for our case.
For your case, ensure you enter your password to start the installation and allow the process to complete.
Step 3: Check Status
After the installation is complete, the next step is to check the status of the openssh-server. Run the below command.
$ sudo systemctl status ssh
Suppose you get its status as inactive. Run the command below.
$ sudo systemctl start ssh
Still, you can set SSH to start at boot time on your server by enabling it using the following command:
$ sudo systemctl enable ssh
Step 4: Configure Firewall
Even after installing the SSH server, you may get errors when establishing the remote connection if you’ve not configured your Ubuntu firewall.
The firewall utilizes the set rules to allow or reject remote connections. For this case, SSH uses the default port 22 for connection. Therefore, we must configure the firewall to accept port 22 connections.
Use the below command.
$ sudo ufw allow ssh
Also, ensure that the firewall is enabled. You can check its status to ensure the rule allowing remote connection via port 22 has been added.
$ sudo ufw enable $ sudo ufw status
For this example, port 22 will accept connections from anywhere. However, if you only wanted to connect with a specific client device, you would add its IP instead.
Step 5: Test the Remote Connection
The last step in our Ubuntu install OpenSSH guide is to verify that we can connect to our server via SSH.
First, get the IP address of your server. We’ve used the ip a command and filtered the results using grep to get the inet associated with a specific network interface. Ensure you use the correct network interface for your case.
$ ip a | grep enp
Once you have the server’s IP, open your client device and connect to that IP via SSH. You must also add the username for your server.
Here’s an example.
$ ssh linuxgeekery@192.168.0.103
Since we are establishing the connection for the first time, we will be prompted to accept the authentication key. Type ‘yes’ and proceed by pressing the enter key.
Next, add your server’s password. Once the password is authenticated, you will receive a welcome message confirming the successful connection.
You can further verify the SSH connection by running the whoami command to see the logged in user. Lastly, exit the connection.
$ whoami
$ exit
Conclusion
This post shared all the steps for Ubuntu install OpenSSH. The steps include screenshots to ensure you don’t get stuck installing and setting up the SSH server. Moreover, we’ve connected to the server via SSH to test the connection. Follow these steps to easily install SSH on your server.