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:
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:
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:
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 “10.0.2.15”:
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:
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:
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:
The service will reload and the status can be checked using the status option with the systemctl command:
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.