Set up ssh keys
Steps
1, Create RSA key pair
1 | ssh-keygen -t rsa |
Answer the question and enter passphrase.
By default, the public key is now located in /home/user/.ssh/id_rsa.pub and the private key is now located in /home/user/.ssh/id_rsa
2, Copy public key to server
1 | cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" |
3, Disable password for root login
1 | vim /etc/ssh/sshd_config |
Change the line PermitRootLogin yes to:
1 | PermitRootLogin without-password |
Save and quit, then reload ssh:
1 | reload ssh |
Now you can’t login via ssh root@123.45.56.78 by using root’s password.