PopOS

How to Generate SSH Keys on Pop!_OS

SSH, or Secured Socket Shell, is the cryptographic protocol you can use to enable secure access for the server and devices over a specific network. It is also called Secure Shell, operated on a public key that gives a mechanism for mutual authentication between a server and users.

Moreover, SSH can establish an encrypted channel for the communication between client and server on an unsecured network. Hence, it is important to generate SSH keys. But many newbies do not know how to do it. So, this tutorial will briefly describe the methods to generate SSH keys on Pop!_OS.

How to Generate SSH Keys on Pop!_OS

To generate an SSH key, open the terminal and execute the following command:

ssh-keygen

The above command will generate an SSH key of 3072-bit RSA key pair. But if you want to go one step further, execute the following:

ssh-keygen -t rsa -b 4096

The -b 4096 with the ssh-keygen creates the 4096-bit key. Moreover, we have used RSA in the above, but you can also use the following algorithms:

Algorithm Full Form Description
RSA Rivest Shamir Adleman Key with a minimum size of 2048 based on the difficulty.
DSA Digital Signature Algorithm This key is used with the 1024 size.
ECDSA Elliptic Curves Digital

Signature Algorithm

This key is used to support the 256, 384, and 521 bits.

The system will ask you to provide the file’s name after executing the command.

You can either press the Enter button to generate a key in the default file or type the file name accordingly. Finally, generate the SSH key passphrase to finalize everything. This passphrase gives an extra layer of protection and security to prevent unauthorized user access.

Now, copy the public key so you can use the ssh-copy-id. So, you can use the command given below to copy the key:

ssh-copy-id <username>@<REMOTE_HOST>

Or

ssh-copy-id <username>@<SERVER IP_ADDRESS>

Add your system name from the username and <SERVER IP_ADDRESS> with the host’s IP address.

After that, it will scan the local account and the key you have created and then prompt you to enter the password of the remote user account.

In some cases, the terminal shows an error while copying the public key so you can use the following commands to copy the public key using SSH:

Suppose everything goes well with the above commands, type yes and press the Enter button to continue. Next, you must enter the server account’s password and press the Enter button to complete the process.

Now, you can log in to the remote server by using the command given below:

ssh <USERNAME>@<SERVER_IP ADDRESS>

Once you run the command, enter the passphrase to access the server or you may get logged out of the server.

If you want to disable password authentication, log in to the remote server with admin privileges. Now, execute the following command to open the /etc/ssh/sshd_config:

sudo nano /etc/ssh/sshd_config

In the config file, set the PasswordAuthentication from yes to no. Then, save the file. Finally, restart the SSH service through this command:

sudo systemctl restart ssh

With a successful restart, the system will close all the current sessions and implement all the changes.

Conclusion

So, this was about the easiest way to generate SSH keys on Pop!_OS. Generating SSH keys can be confusing if you do not use the command correctly. Sometimes users face issues while copying the host’s IP in their SSH key, so verify the host’s IP before copying it.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.