Ubuntu uses RSA key to login SSH

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


in terminal.


then copy your public key to the .ssh  folder in the server.

Execute the following commands on the server

cd .ssh

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

PermitRootLogin yes

and if you don’t need to log in with typing username and password, change

PasswordAuthentication no

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.



translated 2021-09-24

Leave a Reply