服务器设置密钥登录

cd ~/.ssh

ssh-keygen -b 2048 [-f '生成文件名'] -t rsa

添加公钥到 authorized_keys 文件

cat id_rsa.pub > authorized_keys

生成的文件下到本地



ssh -i .ssh/user_ssh/id_rsa root@host

如果要禁止密码登录 

vim /etc/ssh/sshd_config


RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody


#默认PasswordAuthentication 为yes,即允许密码登录,改为no后,禁止密码登录
PasswordAuthentication no
PermitEmptyPasswords no

重启服务

systemctl restart sshd

🙈🙈🙈🙈👌👌👌👌👌