51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

centos 禁用密码启用秘钥登陆

密钥登录

在服务器创建密钥
cd .ssh/
ssh-keygen -t rsa -C "xxxxxxx@email.com" -f ./id_rsa

-f 指定路径, ./ 指当前路径

在服务器上安装公钥
cat id_rsa.pub >> authorized_keys

设置文件权限
chmod 600 authorized_keys
chmod 700 ~/.ssh

禁用密码

修改配置文件,打开秘钥登录功能

#备份
cp /etc/ssh/sshd_config  /etc/ssh/sshd_config.bak
#删除配置项
sed -i '/PasswordAuthentication./d' /etc/ssh/sshd_config
sed -i '/PubkeyAuthentication./d' /etc/ssh/sshd_config
sed -i '/RSAAuthentication./d' /etc/ssh/sshd_config
sed -i '/AuthorizedKeysFile./d' /etc/ssh/sshd_config
#追加配置项
cat >>/etc/ssh/sshd_config<<EOF
PasswordAuthentication no
PubkeyAuthentication yes
RSAAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

重启sshd服务
systemctl restart sshd

赞(3)
未经允许不得转载:工具盒子 » centos 禁用密码启用秘钥登陆