How to generate SSH Keys in Linux?

Are you trying to generate ssh keys under Linux / UNIX operating systems for remote login?
This guide is for you.

An SSH key is an access credential in the SSH protocol. Its function is similar to that of user names and passwords.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Software Installation Tasks for their Linux Server.
In this context, we shall look into steps to create ssh keys as follows on any Linux or UNIX-like operating systems.

How to generate SSH Keys in Linux?

In Linux, you can use the ssh-keygen command to Generate SSH Keys.
Basically, the ssh-keygen command generates, manages and converts authentication keys for ssh client and server usage.
In order to generate ssh keys, simply log into your Server with an SSH tool such as putty as the root user and execute the command below;

$ ssh-keygen

This will generate SSH keys which will be stored in the "~/.ssh/" directory.
The ssh keys contains the following files;
/.ssh/id_rsa – Your private key. Do not share this file with anyone. Keep it private
/.ssh/id_rsa.pub – Your public key.
Please note that the passphrase must be different from your current password and do not share keys or passphrase with anyone. Also, make sure you have correct and secure permissions on /.ssh/ directory:

ls -ld /.ssh/
chmod 0600 /.ssh/

What to do after generating an SSH Keys?

You need to copy /.ssh/id_rsa.pub file to remote server so that you can login using keys instead of the password.
Use the following command to copy key to remote server called "server1.linuxapt.com" for root user:

ssh-copy-id root@server1.linuxapt.com

Then, to login simply enter:

ssh root@server1.linuxapt.com

[Need urgent assistance in solving Linux related errors? We are available to help you today.]

This article will help you to create and generate ssh keys using the ssh-keygen command.

Related Posts