ssh-keygen 排错一则

一段时间没用ssh key登录方式,想在两台服务器上使用key的方式,免得每次登陆都要输入密码,时间长了就觉得麻烦。

Server1:RHEL4U4的

[nianzong@apache .ssh]$ uname -a
Linux apache 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 i686 i386 GNU/Linux

Server2:这是CentOS4.6

[nianzong@mail .ssh]$ uname -a
Linux mail 2.6.9-67.ELsmp #1 SMP Fri Nov 16 12:48:03 EST 2007 i686 i686 i386 GNU/Linux

以前做ssh key登录方式时都是用的root帐号,基本都是无往不利的,权限采用默认即可。今天实验中两台机器帐号都是nianzong,一个普通的帐号。按照如下步骤:

1. ssh-keygen -t rsa  ;一路回车
2. 将产生的公钥id_rsa.pub scp到 Remote server
3. cat id_rsa.pub >> authorized_keys

最后ssh登录竟然还提示需要密码,前面怀疑ssh配置、防火墙爱那个等,调试后仍然不行。然后用root帐号redo了一遍,一切ok。看来跟那些玩意儿都没关系。

ssh -v看不出啥玩意来,再tail -f /var/log/secure看到有如下log:

Jul 31 07:45:22 mail sshd[668]: Failed gssapi-with-mic for nianzong from ::ffff:192.168.1.184 port 38315 ssh2
Jul 31 07:45:22 mail sshd[668]: Failed gssapi-with-mic for nianzong from ::ffff:192.168.1.184 port 38315 ssh2
Jul 31 15:45:22 mail sshd[667]: Authentication refused: bad ownership or modes for file /home/nianzong/.ssh/authorized_keys
Jul 31 07:45:22 mail sshd[668]: Failed publickey for nianzong from ::ffff:192.168.1.184 port 38315 ssh2

google,baidu没什么有价值的文章,仔细看了下这个关键字“bad ownership”,ls -lh查看两边的拥有者和组都是nianzong,应该不会有错啊。检查了一下用root做实验时的authorized_keys的权限是600,而当前nianzong的是644,改成600后就OK了,虽然成功使用key登录了,但是看了下日志:

Jul 31 08:50:24 mail sshd[19330]: Failed gssapi-with-mic for nianzong from ::ffff:192.168.1.184 port 38335 ssh2
Jul 31 08:50:24 mail sshd[19330]: Failed gssapi-with-mic for nianzong from ::ffff:192.168.1.184 port 38335 ssh2
Jul 31 08:50:24 mail sshd[19330]: Postponed publickey for nianzong from ::ffff:192.168.1.184 port 38335 ssh2
Jul 31 16:50:24 mail sshd[19329]: Accepted publickey for nianzong from ::ffff:192.168.1.184 port 38335 ssh2
Jul 31 08:50:24 mail sshd[19330]: Accepted publickey for nianzong from ::ffff:192.168.1.184 port 38335 ssh2

对于log中的Failed gssapi-with-mic,root帐号登录时也是有的,这是什么错误至今未明,只有以后再查了。

ok,throubleshooting到此结束。