ssh localhost 「Permission denied (publickey)

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

用這個關鍵詞搜索才找到howtogeek上答案: sshd : Authentication refused: bad ownership or modes for directory /html

直接用我文章題目中的搜索,此次無論用。ssh

看log

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

這個命令頗有用。它會告訴你緣由。this

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

緣由很清楚了。是目錄權限不對。orm

方法是:

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:server

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

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

chmod go-w ~/  這個很重要。若是你的用戶目錄被設定爲其它用戶和組用戶能夠寫,那麼即時你更改了 .ssh 目錄和其文件也無論用!!!!! 我浪費了多少時間啊。 :( 我作了下面兩步,但仍是不行。 Permission denied (publickey).

Make sure you do the following:blog

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/ip

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

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

相關文章
相關標籤/搜索