• 密钥登录
  • 禁用密码
  • 首页
  • 渗透
  • 折腾
  • 转载
  • 关于Me
  • 榜上有名
  • 文章存档
  • 友情链接

不妨看看这里

会员面板

Base64 Image

centos 禁用密码启用秘钥登陆

  • Mr.Wu
  • 2022-06-20
  • 0

密钥登录

在服务器创建密钥 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
© 2025 MrWu
Theme by Wing-child
  • {{ item.name }}
  • {{ item.name }}