The requirement to ssh to server without password
To ssh without password, you must meet the condition:
- Private key in client
~/.ssh/
- Public key in server
~/.ssh/authorized_keys
Steps to setup
Create ssh key pairs by ssh-keygen
1
2
3
4
5
6
7# Generate key
ssh-keygen
# Check the generated key pair
ls ~/.ssh
-rw------- 1 sing staff 1679 Jun 8 2018 id_rsa
-rw-r--r-- 1 sing staff 404 Jun 8 2018 id_rsa.pubLogin to your server
Copy the content of the publicKey (id_rsa.pub) to server’s
~/.ssh/authorized_keys
1
echo "#123;public key content}" >> ~/.ssh/authorized_keys
Make sure the sshd setting
/etc/ssh/sshd_config
allow publickey authentication,1
PubkeyAuthentication yes
Restart by
sudo systemctl restart ssh
if you modify the sshd setting.Modify ssh config (~/.ssh/config) in your client to indicate which ssh key to use
1
2Host <server ip>
IdentityFile ~/.ssh/id_rsaVerify ssh without password
1
ssh username@serverip