ssh localhost “Permission denied (publickey)

再次遇到 SSH Server And “Permission denied (publickey)

用这个关键词搜索才找到howtogeek上答案: sshd : Authentication refused: bad ownership or modes for directory /

直接用我文章题目中的搜索,这次不管用。

看log

    $ grep sshd /var/log/audit/audit.log  

这个命令很有用。它会告诉你原因。

May 17 16:21:25 localhost sshd[30255]: Authentication refused: bad ownership or modes for directory /home/username

原因很清楚了。是目录权限不对。

方法是:

Fixing Authentication refused: bad ownership or modes for directoryFrom HowToGeekIf you get this error in your logs when trying to setup public key authenticated automatic logins, the problem is a permissions one.You’ll need to perform the following commands on the user account you are trying to setup:

    chmod go-w ~/
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/authorized_keys

http://www.howtogeek.com/wiki/Fixing_Authentication_refused:_bad_ownership_or_modes_for_directory

    chmod go-w ~/  这个很重要。如果你的用户目录被设定为其它用户和组用户可以写,那么即时你更改了 .ssh 目录和其文件也不管用!!!!! 我浪费了多少时间啊。 :( 我做了下面两步,但还是不行。 Permission denied (publickey).

Make sure you do the following:

Make sure the permissions of the .ssh folder are 0700Make sure the permissions of the authorized_keys file are 0600Make sure the user owns the .ssh folder and contents (normally that’s the case but just to make sure)http://blog.artooro.com/2010/02/19/ssh-server-and-permission-denied-publickey/

$ grep sshd /var/log/audit/audit.log

May 17 16:21:25 localhost sshd[30255]: Authentication refused: bad ownership or modes for directory /home/fltrpMay 17 16:21:35 localhost sshd[30257]: Authentication refused: bad ownership or modes for directory /home/fltrphttp://serverfault.com/questions/230771/ssh-configuration-publickeys-permission-denied-publickey-password-error


原文地址:

http://pengyou.rijiben.org/2012/2012-08-29-%E5%86%8D%E6%AC%A1%E9%81%87%E5%88%B0_SSH_Server_And_Permission_denied_publickey.html


public-key生成命令(客户端)

# ssh-keygen -t dsa -f ~/.ssh/id_dsa

# cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

[注释:~/.ssh/id_dsa.pub文件为公钥,拷贝到Server的~/.ssh/目录中,执行cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys,权限只给用户本人,否则无法连接]

允许root直接登录

编辑/etc/ssh/sshd_config, 重新启动sshd

PermitRootLogin yes

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值