How to generate ssh keys on ubuntu 22. 04

How to Generate SSH Keys on Ubuntu 22.04

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

To connect to the authorized client machine, we generate the SSH keys which are unique and can connect to the host machine after entering those unique SSH keys into the client machine. So, in this blog, we will explore a method by which we can generate the SSH keys on Ubuntu.

How
Sponsored
to generate the SSH keys on Ubuntu

First, we will make sure that the SSH server is installed on both the client and host machine. If it is not installed, install it first by following our dedicated installation guide.

To begin with the generation of SSH keys on Ubuntu, we will start with the client machine. First, verify whether there are keys already generated or not. To verify, use the command typed below:

See also  How to Customize the Fonts in Google Chrome
$ ls -l ~/.ssh/id_*.pub

How to generate ssh keys on ubuntu 22. 04 1

In the above figure, we can see that there is no directory which means that there is no SSH keys on the client machine, so now we will generate the SSH key on the client machine using the command:

$ ssh-keygen

How to generate ssh keys on ubuntu 22. 04 2

When you run the above command:

  • it will ask you to enter some directory where you want to store the SSH keys, and if you press “ENTER” key without typing any directory, then it will store the SSH keys on the default path which is displayed in next line.
  • Later, it will ask you to enter a passphrase and re-type it again to confirm the passphrase, the passphrase is used to have more security.

How to generate ssh keys on ubuntu 22. 04 3

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

$ ls ~/.ssh/id_*

How to generate ssh keys on ubuntu 22. 04 4

So, it has displayed the SSH keys file.

Now, to copy the SSH keys on the machine to which we want to connect remotely(host). For this, we should know the IP address as well as the username of that machine. In our case, the user name is “hammad”, the ip address is “10.0.2.15”:

$ ssh-copy-id hammad@10.0.2.15

How to generate ssh keys on ubuntu 22. 04 5

It will ask you to enter the password of the remote(host) machine; enter the password and hit “Enter”:

Sponsored

How to generate ssh keys on ubuntu 22. 04 6

The SSH keys are successfully copied to the Host machine.

Finally, we will connect with the machine, using the command:

$ ssh hammad@10.0.2.15

How to generate ssh keys on ubuntu 22. 04 7

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

How to configure SSH on Ubuntu 22.04?

If you want to disable the identification method, then simply open the “ssh_config” file in the client machine using the nano text editor:

$ sudo nano /etc/ssh/sshd_config

How to generate ssh keys on ubuntu 22. 04 8

Find out the line “PasswordAuthentication ” and then changed the “Yes” with “no”:

How to generate ssh keys on ubuntu 22. 04 9

Exit from the file and reload the service of ssh using the systemctl command:

$ sudo systemctl restart ssh

How to generate ssh keys on ubuntu 22. 04 10

The service is reloaded and status can be verified using the option of status with the systemctl command:

$ sudo systemctl status ssh

How to generate ssh keys on ubuntu 22. 04 11

Conclusion

The SSH server is used to connect with the other machines remotely and to have a secure connection with them, we generate the SSH keys on Ubuntu 22.04. In this blog, the method of generating the SSH keys on Ubuntu has been explained.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply