centos 禁用密码启用秘钥登陆

Mr.Wu 5,615 1 正在检测是否收录...

密钥登录

在服务器创建密钥

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

打赏
发表评论 取消回复
表情 图片 链接 代码

  1. c0sMx
    c0sMx Lv 2

    已经禁用密码了[aru_18]

分享
微信
微博
QQ