配置ssh免密登录

配置ssh免密登录:

<strong>原理解析</strong>

client A免登录到server B: 

1.在A上生成公钥私钥。 

2.将公钥拷贝给server B,要重命名成authorized_keys(从英文名就知道含义了) 

3.client A向Server B发送一个连接请求。 

4.Server B得到client A的信息后,在用户的authorized_key中查找,如果有相应的用户名和IP,则随机生成一个字符串,并用client A的公钥加密,发送给client A。 

5.client A得到Server B发来的消息后,使用私钥进行解密,然后将解密后的字符串发送给Server B。Server B进行和生成的对比,如 果一致,则允许免登录。 

总之:A要免密码登录到B,B首先要拥有A的公钥,然后B要做一次加密验证。对于非对称加密,公钥加密的密文不能公钥解开,只能 私钥解开

问题:

登录服务器的时候仍然要求输入密码。刚开始我以为添加ssh公钥的时候粘贴有问题,经过重新添加一次公钥后,仍然让输入密码,怀疑是~/.ssh/authorized_keys文件权限的问题。再通过查看日志,提示authorized_keys的权限错误。查看authorized_keys这个文件的权限为了664,/etc/ssh/sshd_config文件中设置有StrictModes yes 难怪添加了公钥仍然被要求输入密码

原因:

  This file is not highly sensitive, but the recommended permissions are read/write for the user, and not accessible by others。If this file, the ~/.ssh directory, or the user’s home directory are writable by other users,then the file could be modified or replaced by unauthorized users.  In this case, sshd will not allow it to be used unless the StrictModes option has been set to “no

将文件权限改为600 

<strong>chmod 600 authorized_keys</strong>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值