Linux Commands and Scripts

How To Generate SSH Key In Linux

Secure Shell (knowns as SSH) is a cryptographic network protocol to perform network service securely over an unsecured network. Using SSH we can be logging into the server and provides a secure encrypted connection between two hosts over an insecure network.

We can log in into the server with SSH using a password but the password can be cracked with a brute force attack. An SSH key is nearly impossible to decode by brute force.

In this article, we will learn how to generate the SSH key in Linux. For this demonstrate, we are using CentOS 7.

To generate SSH RSA key pair, the first step is to run the following command:

# ssh-keygen -t rsa

We need to follow a couple of steps to store the keys are a passphrase

Enter file in which to save the key (/home/user/.ssh/id_rsa):

You can press Enter to use default settings.

Enter passphrase (empty for no passphrase):

Entering a passphrase does have its benefits: the security of a key, no matter how encrypted, still depends on the fact that it is not visible to anyone else. So, it will protect from unauthorized users.

how to generate ssh key in linux

Now, your SSH key is generated.

To copy SSH key to the new server:

ssh-copy-id user@[Server IP]

You need to enter the user password to copy the SSH key pair.

Today, we have learned to generate an SSH key pair and copy it into the server.

[Need assistance to fix this error or install tools? We’ll help you.]

Related Articles