ssh连接可以以用户名和口令的形式来连接也可以采用public key方式来实现客户端的认证。这也就是通常大家所说的免输密码的方式登录。
在实际操作的时候,只需要做很少的工作:
1)在client端使用ssh-keygen命令生成公钥和私钥
2) 拷贝client端的公钥到服务器端,可以使用scp命令
3) 将公钥中的内容写入到服务器的~/.ssh/authorized_keys文件中:cat id_rsa.pub >> ~/.ssh/authorized_keys
正常情况下这样就搞定了,linux比较好玩的就是经常容易发生一些意外的小插曲,解决这些意外的小插曲常常也会带来一些意外的小收获。今天我就又遇上了一段小插曲,一切操作正常,但就是还得输密码,参看各种书籍资料之后终于找到问题了,在这里有解释:http://www.openssh.com/faq.html#3.14
写道
Typically this is caused by the file permissions on $HOME, $HOME/.ssh or $HOME/.ssh/authorized_keys being more permissive than sshd allows by default.
In this case, it can be solved by executing the following on the server.
$ chmod go-w $HOME $HOME/.ssh
$ chmod 600 $HOME/.ssh/authorized_keys $ chown `whoami` $HOME/.ssh/authorized_keys
If this is not possible for some reason, an alternative is to set StrictModes no in sshd_config, however this is not recommended.
我的问题是出在.ssh目录的权限过大,之前是775,chmod -R go-w .ssh之后问题就解决了,不是很能理解为什么权限过大了会有问题,如果权限有问题那也是权限过小时有问题,总之问题解决了并且进一步熟悉了linux对文件权限的管理In this case, it can be solved by executing the following on the server.
$ chmod go-w $HOME $HOME/.ssh
$ chmod 600 $HOME/.ssh/authorized_keys $ chown `whoami` $HOME/.ssh/authorized_keys
If this is not possible for some reason, an alternative is to set StrictModes no in sshd_config, however this is not recommended.