配置ssh公钥后免密码ssh登录失败

在公司的服务器上配置过ssh公钥,之前一直可以免密码登录。但是最近登录时,每次都提示要输入密码。尝试了删除known_hosts,重新把id_rsa.pub添加到服务器~/.ssh/authorized_keys下也没有用。
通过查看系统的登录验证日志文件/var/log/auth.log,看到每次登录时有以下报错:

Mar  7 11:52:10 coffeeserver sshd[6761]: Authentication refused: bad ownership or modes for directory /home/coffee/.ssh

原来是.ssh目录的权限设置不正确。
网上查了一下资料:

SSH doesn’t like it if your home or ~/.ssh directories have group write permissions. Your home directory should be writable only by you, ~/.ssh should be 700, and authorized_keys should be 600
You can also get around this by adding StrictModes off to your ssh_config file, but I’d advise against it - fixing permissions is the way to go.

执行一下:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

这时ssh免密码登录就正常了。

参考:
使用SSH遇到Authentication Refused: Bad Ownership or Modes for Directory

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值