Generate RSA Key

$ ssh-keygen -t rsa -b 4096

Copy the Public Key to the Server

$ ssh-copy-id -i ~/.ssh/id_rsa user@host

Replace ‘user’ with your server username and ‘host’ with your server address

Modify Server Configuration File

After copying the ID, we need to log in to the server first and modify the SSHD configuration file to enable PubkeyAuthentication and disable PasswordAuthentication:

PubkeyAuthentication yes
PasswordAuthentication no

Save the modified configuration file, then restart the SSHD service:

systemctl restart sshd

Modify Local Configuration File

Modify the content of ~/.ssh/config (create it if it doesn’t exist):

Host *
  IgnoreUnknown UseKeychain
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

This means that all Hosts will use the id_rsa we just generated. Of course, you can also configure different Hosts separately.

This completes the entire configuration process. Now you can test whether you can log in.

I hope this is helpful, Happy hacking…