Due to the recent need to log in to the laboratory server, I learned how to log in to SSH using RSA. Take a note.
The principle of key form login is: Use a key generator to make a pair of keys: a public key and a private key. Add the public key to an account on the server, and then use the private key on the client to complete the authentication and login.
So first we create an RSA key. Type
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): %default press Enter
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): %passphrase for unlocking your keys when using it
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa %private key
Your public key has been saved in /root/.ssh/id_rsa.pub %public key
then copy your public key to the
.ssh folder in the server.
Execute the following commands on the server
cat id_rsa.pub >> authorized_keys
make sure the privileges are correct
chmod 600 authorized_keys
chmod 700 ~/.ssh
to let sever accept the RSA login, we need to open
/etc/ssh/sshd_config and add/uncomment:
if you want to keep login with root, stay
and if you don’t need to log in with typing username and password, change
and restart ssh service.
service sshd restart
Note that if you want to copy the private key to other Linux computers for use, you must copy the id_rsa file generated earlier to the client’s .ssh folder, and then adjust the permissions, otherwise, an error will be encountered.
chmod 600 id_rsa
and add the keys to client ssh.
ssh-add -l %查看已添加的密钥