Big padlock along with the title "SSH". A physical server is visible in the background.

Manage SSH keys between a Linux client and Server

Published on

#sys-admin #linux

How to Create a New Ssh Key Pair

First, ensure the ssh agent is running:

Terminal window
eval "$(ssh-agent -s)"

Then, run command

Terminal window
ssh-keygen

and follow the on-screen prompts. It should generate your key inside the ~/.ssh/ directory.

A password may or may not be chosen to access the key pair. Using a password is of course more secure, but is in no way necessary.

From my experience, the ssh agent should automatically add the newly generated key to its store. But if doesn’t do it, you can simply use the following command to add the key pair manually:

Terminal window
ssh-add ~/.ssh/<name_of_cipher>

Copy Ssh Key Pair to Remote Server

One the key pair has been created, simply use the following command to copy it to the remote server:

Terminal window
ssh-copy-id <user>@<host>

The above command should ask for your password one last time.

You should now be able to connect to the remote server without using passwords, like so:

Terminal window
ssh <user>@<host>