1.Use ssh-key instead of password
- Add a new user on server. (e.g. bird)
adduser bird
passwd bird
usermod -aG wheel bird #add user to sudo group
- Generate ssh-key at local computer
ssh-keygen
- Copy your local public key to server
ssh-copy-id $user@Your_server_ip -p[port]
- Change authority of file or dirctory
chmod 600 /home/bird # Some OS do not need this step ?
chmod 700 /home/bird/.ssh
chmod 600 /home/bird/.ssh/authorized_keys
- At server terminal type:
vi /etc/ssh/sshd_config
- So change sshd_config file as follow:
RSAAuthentication yes
PubkeyAuthentication yes
# set your ssh key position
AuthorizedKeysFile /home/bird/.ssh/authorized_keys
PasswordAuthentication no
ChallengeResponseAuthentication no
PermitRootLogin without-password
- Then reload sshd
systemctl restart sshd
systemctl reload sshd
- Now test your ssh key pair. It is success if login without password prompt.
ssh bird@123.123.123.123 -p [port]
If something wrong happened, use "ssh -v bird@your_server_ip" to debug.