SSH 公钥认证(无密码)

每次想配置public key来登陆我的Fedora,结果总是失败。过程大致如此。

使用puttygen.exe生成public key和private key,将public key加入远程linux服务器的$HOME/.ssh/authorized_keys文件中。使用putty的命令行操作(省事),“putty -i private-key.ppk xylz@10.2.17.xxx”,结果非常不幸登陆失败,服务器返回错误信息,“server refused our key”。不得其解,要知道我在/etc/ssh/sshd_config中有如下设置:

RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile      .ssh/authorized_keys

无意中找到一条消息说StrictModes no需要打开不然不能登录?试了下,果然可以登录了。然后我就去想为什么了?然后ssh对权限要求比较严格。

The option StrictModes specifies whether ssh should check user's permissions in their home directory
and rhosts files before accepting login. This option must always be set to yes because sometimes
users may accidentally leave their directory or files world-writable.

也就是说如果用户的HOME目录的权限过大就会导致无法通过验证,这样是为了降低用户的风险。然后我看了下我的HOME目录权限居然是777,呵呵,估计是以前使用apache的时候老出权限问题,一着急就给777了。

参考链接: