Ideal case

Assuming everything is going well, the easiest way to do this is:

  1. Use the ssh-keygen command to generate a pair of Public and Private keys locally.

  2. Run the ssh-copy-id username@your-server-ip command to upload the local public key to the remote server

  3. Now use the SSH username@your-server-ip command to log in confidential-free

If you’ve already generated the key locally, you can skip the first step. SSH command to check whether the id_rsa and id_rsa.pub files exist. If yes, the id_rsa and id_rsa.pub files exist.

The reality

But often see others play very hi, to their own practical operation will appear all kinds of problems. Or the same words: the pit will not be less! If you encounter problems, you can look at common TROUBLESHOOTING listed below.

  1. If you specify a public key when you run the ssh-copy-id command, for example, ssh-copy-id -i ~/. SSH/id_rsa_other. pub username@your-server-ip, SSH /id_rsa.pub = ~/. SSH /id_rsa.pub = ~/. SSH /id_rsa.pub = ~/. SSH -i ~/. SSH/id_rsa_other. pub username@your-server-ip

  2. The SSH server may be configured to prohibit public key authentication. Check whether PubkeyAuthentication yes is correctly configured in the /etc/ssh/sshd_config file on the server

  3. The ROOT user may not be allowed to log in to the SSH server. Check the /etc/ssh/sshd_config file on the server and change it to yes if it contains PermitRootLogin no

The basic principle of

This is best illustrated by a sequence diagram 😛

The resources

  • Ssh-copy-id for copying SSH keys to servers | SSH.COM