How to generate SSH keys on Ubuntu 22.04

SSH (Secure Shell) is a method to communicate with another computer via a secure method. In this way we can access the machine to manage it or transfer some files. For this we need to install the SSH server on the client as well as on the host machine, and then we can access that client machine from the host machine through the command line interface.

To connect to the authorized client Computer we generate the SSH keys which are unique and able to connect to the host computer after entering these unique SSH keys into the client computer. So, in this blog, we are going to explore a method that we can use to generate the SSH keys on Ubuntu.

How to generate the SSH keys on Ubuntu

First, let’s make sure the SSH server is installed on both the client and host machines. If it’s not installed, install it first by following our dedicated installation guide.

To start generating SSH keys on Ubuntu, let’s start with the client machine. First check whether keys have already been generated or not. To verify, use the command entered below:

$ ls -l ~/.ssh/I would_*.pub

In the above image we can see that there is no directory which means there are no SSH keys on the client machine, so now let’s generate the SSH key on the client machine with the command:

$ ssh-keygen

When you run the above command:

  • You will be prompted to enter a directory where you want to save the SSH keys and if you press the “ENTER” button without entering a directory, the SSH keys will be saved to the default path shown on the next line .
  • Later you will be asked to enter a passphrase and re-enter it to confirm the passphrase. The passphrase is used to provide more security.

Once the key is generated, the next step is to verify SSH key generation by running the following command:

$ ls ~/.ssh/I would_*

So it showed the SSH key file.

Now copy the SSH keys on the computer we want to connect to remotely (host). To do this, we should know the IP address as well as the username of this machine. In our case, the username is “hammad” and the IP address is “”:

$ ssh-copy-id hammad@

You will be prompted to enter the remote (host) computer’s password; Enter the password and press “Enter”:

The SSH keys have been successfully copied to the host computer.

Finally we connect to the computer with the command:

$ sh hammad@

As you can see, we are logged into the machine.

How to configure SSH on Ubuntu 22.04?

If you want to disable the authentication method, just open the ssh_config file on the client machine with the nano text editor:

$ sudo nano /Etc/sh/sshd_config

Find the line “password authentication ‘ and then changed the ‘Yes” With “no“:

Kill the file and reload the service from ssh using the systemctl command:

$ sudo Restart systemctl sh

The service will reload and the status can be checked using the status option with the systemctl command:

$ sudo Systemctl status sh


The SSH server is used to connect remotely to the other machines and to establish a secure connection with them we generate the SSH keys on Ubuntu 22.04. This blog has explained the method to generate the SSH keys on Ubuntu.

Related Posts