我有3个CentOS VM,我正在尝试从任何主机到任何其他主机设置无密码ssh。 (称他们为db01
,db02
,dbmgr
)
我将RSA公钥复制到.ssh / authorized_keys 即
db01
- > .ssh / authorized_keys包含来自db02
,dbmgr
的公钥条目
db02
- > .ssh / authorized_keys包含来自db01
,dbmgr
的公钥条目
dbmgr
- > .ssh / authorized_keys包含来自db01
,db02
的公钥条目
我已验证主机上的公钥字符串
[abhyas_db01@abhyas ~]$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsT8zUe4or3VCN8C1k0XVyQ9erpEiXDKORnS9rujBTDw1bFdCDnQLngteu+dbHIeZ2O8vrtH6cJVdqSjhGJjlswnhOdH6IfxIrKDb+Rug4LhxSei6jTxH3gq0vmrPzsoy14J/Q1xxAEbtIyc2J6JmupKf/bmafITnijvFUgZ70xlzVs1cmzAaU6+A/te9Oc+HCvpGzDLLUNSQUq8rRhAm8IFDy3+qHk+h2+BQCMx0uDRKGaxXhqur/1l0nzJNL49gANTF4LYmdqU7Vb07Vm7BbIdKwxgc2njAqOPfhE3iBmAeOmmq715Dhf2OO4DY/OdnDSFDo+MZAscf/tk1ZA0hvw== abhyas_db01@abhyas.db01
[abhyas_db02@abhyas ~]$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEApkPWB3L9LJNyUW/iFKlJGKTSeIviBRrP6lTvmw7wPGMEto5TFvie4vogaGv6euUNLQiM7HdneNCoZjoeMDgOl7od9ZMZpXNslSX/tPZI0Ha55Mx2T5l7ka4t/Uzm/rzYz3GgNmag8o8buKDCfjXzAMJWU7DnkLFf04rFenzQC3twTIfQKXXnnOo5Fka1f6110xEDuHaRZ24Fesp7T67joSECwjTJvPfFXT3EUMCAXmuzBsFc2fXQmPM/MSGvrBY6pj6ntGQ6+R8OR1yS/2sZudmSb2uxsRnKdhue9E20HEE/tiyL6IByY9s70KRsNarB7GGvVPfZvTXu/N8/TkNHaQ== abhyas_db02@abhyas.db02
[abhyas_db02@abhyas ~]$
[abhyas_mgr@abhyas ~]$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArfc2PvbGmOX638qhFh2h2oZ3ZzP8r177BnclMe22xi+Fe8tj/RGVM5NQStAXulBlwVc2KSWgkAt5+oe7nDoVENWaetapTBaMwJcxiGyJPs7SIrcVOUI4CDaHbXQAM2Bs7EjsGfY7LlFyOCZZWnwEjRMW23wnis6200grleZftrU07Tk05v1rfihlY2pm2dV1mMckoyUOP7gn8MDvLCj6DlFPwcGw6h5siIU0UU0wiSxg8Q3zXdFaXnDXGp3lFic71TzfPidmimu8k2PDZhikz21ypxn1YaDluYJ6Wn+zTgkNFrdV6T7tT27RIzWXAJHT9OMnhpKFa+HTxbTKlecxqw== abhyas_mgr@abhyas.dbmgr
[abhyas_mgr@abhyas ~]$
[abhyas_db01@abhyas ~]$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEApkPWB3L9LJNyUW/iFKlJGKTSeIviBRrP6lTvmw7wPGMEto5TFvie4vogaGv6euUNLQiM7HdneNCoZjoeMDgOl7od9ZMZpXNslSX/tPZI0Ha55Mx2T5l7ka4t/Uzm/rzYz3GgNmag8o8buKDCfjXzAMJWU7DnkLFf04rFenzQC3twTIfQKXXnnOo5Fka1f6110xEDuHaRZ24Fesp7T67joSECwjTJvPfFXT3EUMCAXmuzBsFc2fXQmPM/MSGvrBY6pj6ntGQ6+R8OR1yS/2sZudmSb2uxsRnKdhue9E20HEE/tiyL6IByY9s70KRsNarB7GGvVPfZvTXu/N8/TkNHaQ== abhyas_db02@abhyas.db02
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArfc2PvbGmOX638qhFh2h2oZ3ZzP8r177BnclMe22xi+Fe8tj/RGVM5NQStAXulBlwVc2KSWgkAt5+oe7nDoVENWaetapTBaMwJcxiGyJPs7SIrcVOUI4CDaHbXQAM2Bs7EjsGfY7LlFyOC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ntGQ6+R8OR1yS/2sZudmSb2uxsRnKdhue9E20HEE/tiyL6IByY9s70KRsNarB7GGvVPfZvTXu/N8/TkNHaQ== abhyas_db02@abhyas.db02
我能够将db01
转换为db02
,反之则没有密码,我可以从{db01
和db02
转发dbmgr
1}}没有密码。
但是尝试从dbmgr
或db01
ssh到db02
请求输入密码。
我不确定我错过了什么。
编辑:通过查看日志来解决它。日志表明确实存在许可问题。 14:13:01 localhost sshd[3787]: debug1: userauth-request for user abhyas_mgr service ssh-connection method none
Sep 6 14:13:01 localhost sshd[3787]: debug1: attempt 0 failures 0
Sep 6 14:13:01 localhost sshd[3786]: debug1: PAM: initializing for "abhyas_mgr"
Sep 6 14:13:01 localhost sshd[3786]: debug1: PAM: setting PAM_RHOST to "abhyas.db01"
Sep 6 14:13:01 localhost sshd[3786]: debug1: PAM: setting PAM_TTY to "ssh"
Sep 6 14:13:01 localhost sshd[3787]: debug1: userauth-request for user abhyas_mgr service ssh-connection method publickey
Sep 6 14:13:01 localhost sshd[3787]: debug1: attempt 1 failures 0
Sep 6 14:13:01 localhost sshd[3787]: debug1: test whether pkalg/pkblob are acceptable
Sep 6 14:13:01 localhost sshd[3786]: debug1: temporarily_use_uid: 500/500 (e=0/0)
Sep 6 14:13:01 localhost sshd[3786]: debug1: trying public key file /home/abhyas_mgr/.ssh/authorized_keys
Sep 6 14:13:01 localhost sshd[3786]: debug1: fd 4 clearing O_NONBLOCK
Sep 6 14:13:01 localhost sshd[3786]: Authentication refused: bad ownership or modes for file /home/abhyas_mgr/.ssh/authorized_keys
Sep 6 14:13:01 localhost sshd[3786]: debug1: restore_uid: 0/0
Sep 6 14:13:01 localhost sshd[3786]: debug1: temporarily_use_uid: 500/500 (e=0/0)
Sep 6 14:13:01 localhost sshd[3786]: debug1: trying public key file /home/abhyas_mgr/.ssh/authorized_keys2
Sep 6 14:13:01 localhost sshd[3786]: debug1: Could not open authorized keys '/home/abhyas_mgr/.ssh/authorized_keys2': No such file or directory
Sep 6 14:13:01 localhost sshd[3786]: debug1: restore_uid: 0/0
Sep 6 14:13:01 localhost sshd[3786]: Failed publickey for abhyas_mgr from 192.168.102.131 port 54518 ssh2
^C
答案 0 :(得分:3)
这通常表示权限问题。确保在以下目录和文件上正确设置了权限:
可以使用chmod命令设置权限。例如:
chmod 500 /home/username/.ssh
正如Luis Colorado在下面指出的那样,OpenSSH允许的最大权限级别也是如此。如果设置过于松散(例如777),您将无法登录。有关详细信息,请参阅the OpenSSH faq。