Ubuntu

How to Set Up SSH Keys on Ubuntu 22.04

Secure Shell Technology or SSH is a network communication protocol that permits two systems to securely communicate in an unsecured network. This cryptographic protocol is also utilized for commandline executables or remote login programs such as terminal applications. Users who want to use SSH for connecting to other remote systems must have SSH configured on both client and server machines.

This write-up will demonstrate the method to set up SSH keys on Ubuntu 22.04. So, let’s start!

How to set up SSH keys on Ubuntu 22.04

Want to set up SSH keys on your Ubuntu 22.04 system? If yes, then check out the following step-by-step procedure.

Step 1: Update system repositories

First of all, open up the terminal by hitting “CTRL+ALT+T” in Ubuntu 22.04 and write out the below-given commands for updating the system repositories:

$ sudo apt update

Upgrade the system packages as well:

$ sudo apt upgrade

Step 2: OpenSSH installation

In the next step, execute the below-given command to install OpenSSH on your Ubuntu 22.04:

$ sudo apt install openssh-server -y

Wait for a few minutes, as the installation of OpenSSH will take some time to complete:

Step 3: Enable SSH

Then, enable SSH by utilizing the given command “systemctl” command:

$ sudo systemctl enable --now ssh

Step 4: Verify SSH status

After successful installation of OpenSSH and enabling the SSH on Ubuntu 22.04, you must validate the current SSH status to check if it is active or not:

$ sudo systemctl status ssh

The below-given output signifies that we have SSH is active and running on our system:

Step 5: Configure Firewall

Now, it’s time to configure Firewall to allow the connections for port “22”:

$ sudo ufw allow 22/tcp

Then, enable your UFW Firewall on Ubuntu 22.04 system:

$ sudo ufw enable

Step 6: Connect to a remote system via SSH

At this point, we have successfully set up SSH on Ubuntu 22.04, and our system is now all ready to connect to a remote system. Make sure that OpenSSH is also installed on the corresponding server.

For the purpose of connecting to an SSH server, you have to utilize their “username” and “IP address” in the following way:

$ ssh username@ip-address.

For instance, to connect with the “linuxuser-VBox” system with the IP address “10.0.2.15”:

$ ssh linuxuser-VBox@10.0.2.15

At the first-time connection with the specified system; you will be asked to verify if you want to establish a connection or not, so, enter “yes” to move ahead:

Then, type out your system password, and within few mini seconds your system will be connected to the specified remote system:

You can also list down the directories of the connected system with the help of the “ls” command:

$ ls

The output of the “ls” command will verify if the remote connection is successfully established or not:

After performing the required operation on the connected remote system, you can disable SSH with the help of the following command:

$ sudo systemctl disable ssh --now

How to uninstall SSH from Ubuntu 22.04

To uninstall SSH from Ubuntu 22.04, write-out the following command in terminal:

$ sudo apt autoremove openssh-server -y

We have compiled the easiest method to set up SSH on Ubuntu 22.04. Give it a try to establish a connection with any remote system.

Conclusion

To set SSH on Ubuntu 22.04, firstly, install the OpenSSH server by utilizing the “$ sudo apt install openssh-server -y” command. Then, configure the Firewall to open port “22” with the “$ sudo ufw allow 22/tcp” command. After doing so, enable UFW Firewall and execute the “$ ssh [email protected]” command for connecting to a remote system. This write-up discussed the method to set up SSH on Ubuntu 22.04.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.