Zettel 202109122305 : Passwordless SSH Key setup for RedHat/CentOS
Running these commands will set up passwordless SSH between two servers. You do this by generating a public and private key pair. Then, you share the public key with the server with which you want to connect.
First, create your key pair:
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/$username/.ssh/id_rsa):
Created directory '/home/$user/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/$user/.ssh/id_rsa
Your public key has been saved in /home/$user/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:QO+nBQ/I01h9an9TuWVed0eKlL4rLAXQDu+pDsUK1sk $user@localhost
The key's randomart image is:
+---[RSA 3072]----+
| .... . |
| oo*. . + .|
| *== = . o.|
| o o +++o o ..O|
| o E o.S++. . +B|
| . . o o+. o o..|
| o ..o o . |
| .. . o . |
| .. . . |
+----[SHA256]-----+
If you enter a passphrase, you won’t have a passwordless key. So, press Enter without adding a passphrase for your key.
Next, send your new key to the server with which you want to connect:
$ ssh-copy-id -i ./ssh/id_rsa.pub $user@remote-server
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:
"/home/$user/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s),
to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed --
if you are prompted now it is to install the new keys
$user@remote-server password:
Number of key(s) added: 1
You’ll need to enter your password this one time. After that, ssh-copy-id will send your public key over to the remote server.
This implies that the same user should already exist on the remote-server.
Finally, enjoy your Passwordless SSH key.
The next time you connect via SSH, you won’t need to submit your password.
September 13, 2021 unlinked cli