绑定秘钥对功能解析及无法登录案例一

绑定秘钥主机上发生什么

  1. 会修改/ect/ssh/sshd.config增加:
    PasswordAuthentication no

ChallengeResponseAuthentication no
如果原来已经有,也会进行修改。作用是不允许密码登录。

  1. 在 root 目录下创建.ssh 目录,并在目录下创建authorized_keys文件。
    BaiduShurufa_2017_6_30_20_47_10
  2. authorized_keys 内容:
    1

解除绑定发生什么

  1. 会修改/ect/ssh/sshd.config 修改成如下:
    PasswordAuthentication yes

ChallengeResponseAuthentication yes
作用是允许密码登录。

  1. 清空/root/.ssh/authorized_keys 的内容。
    2

绑定秘钥对无法登录案例一:

  1. 现象就是登录的时候选择了正确的秘钥对,确认后有弹回到登录界面。
    BaiduShurufa_2017_6_30_20_54_26
  2. 通过链接管理终端进行核查:
    查看/var/log/secure日志:
Jun 30 20:53:25 iZ2ze*******j4koh7x4Z sshd[13194]: Server listening on 0.0.0.0 port 22.
Jun 30 20:54:09 iZ2ze*******j4koh7x4Z sshd[13205]: Authentication refused: bad ownership or modes for file /root/.ssh/authorized_keys
Jun 30 20:55:53 iZ2ze*******j4koh7x4Z sshd[13206]: Received disconnect from ***.***.***.***: 0: 

ip已使用* 代替。
日志看是 /root/.ssh/authorized_keys 权限不正确,经核实这个文件需要 600 权限。
使用命令进行修改:

chmod 600 /root/.ssh/authorized_keys

在测试还是不行,日志:

Jun 30 21:04:31 iZ2zec*******j4koh7x4Z sshd[13271]: Authentication refused: bad ownership or modes for directory /root/.ssh
Jun 30 21:04:33 iZ2ze*******j4koh7x4Z sshd[13272]: Received disconnect from ***.***.***.***: 0: 

还是一样权限不对,不过是 /root/.ssh努力权限不对,经核实这儿目录需要 700 权限

chmod 700 /root/.ssh/

在测试还是不行,日志:

Jun 30 21:09:00 iZ2zec*******j4koh7x4Z sshd[13301]: Authentication refused: bad ownership or modes for directory /root
Jun 30 21:09:02 iZ2zec*******j4koh7x4Z sshd[13302]: Received disconnect from  ***.***.***.***: 0

还是一样权限不对,不过是 /root/努力权限不对,经核实这儿目录需要 550 权限

chmod 550 /root/

修改后测试登录成功。

  1. 问题最终发现是因为运行了chmod -R 777 /root 导致目录权限不正确,导致使用秘钥对无法登录,系统默认目录的权限不建议修改。

秘钥对参考:

参考:https://help.aliyun.com/document_detail/51792.html?spm=5176.product25365.6.682.aAQiJH

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值