2007年10月4日 星期四

[ssh]Server refused our key

為了讓努力不懈的大陸網友能有繼續努力永不休止的機會, Server 的 ssh 全面使用 ssh-key 認證,密碼登入沒有了。

不過,改用過程中發生一件怪事,我的帳號沒有問題,可以用 ssh-key 登入 ssh console / sftp ,但是同事的帳號卻發生 "Server refused our key" 的訊息拒絕連線。

經過一番檢查,原來是 ~/.ssh/authorized_keys 的權限錯了。

authorized_keys 的 group 和 others 不能有 w 權限。這其實蠻合理的,否則 public key 被別人改了,自己不就不能連進主機了嗎?!

OpenSSH Manualssh 說明裡有寫到:

~/.ssh/authorized_keys

Lists the public keys (RSA/DSA) that can be used for logging in as this user. The format of this file is described in the sshd(8) manual page. This file is not highly sensitive, but the recommended permissions are read/write for the user, and not accessible by others.

所以,只要

cd ~/.ssh
chmod 600 authorized_keys

搞定。

順便記一下, authorized_keys 可以放多個 public key ,但格式是每行一個 key ,不能自己亂斷行。

沒有留言:

張貼留言