在两个不同的帐户上使用相同的公共ssh密钥

时间:2010-11-03 00:37:41

标签: authentication private public ssh-keys dsa

情况就是这样:我有一台住在我家的机器(我叫它叫house_machine),我办公室里有另一台机器(称之为office_machine)。我使用ssh与dsa密钥身份验证和没有密码身份验证从office_machine访问home_machine。我在home_machine上设置了一个ssh服务器,并将office_machine上生成的公钥添加到home_machine上的authorized_keys文件中。这很好 - 我可以使用密钥而不是密码从office_machine进入home_machine。

现在的问题是:我希望能够通过使用属于office_machine的公钥访问其他办公室时访问home_machine。即我想将公钥(id_dsa.pub)放在USB驱动器上,然后将其复制到另一个办公室的.ssh目录中。从我在这个网站上看到的,其他人似乎已经能够做这种事情,但它不起作用。当我尝试将id_dsa.pub放在新机器上并执行ssh -v user@home_machine时,调试消息以:

结束
debug1: Offering public key: .ssh/id_dsa
debug1: Server accepts key: pkalg ssh-dss blen 433
debug1: read PEM private key done: type DSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

我的临时解决方案是在home_machine上的sshd_config中设置“PasswordAuthentication yes”,只需使用密码即可访问home_machine。但是这使得使用密钥授权无效。

提前感谢!

1 个答案:

答案 0 :(得分:2)

您需要复制的不仅仅是公钥 - 您需要私钥。

在ssh中,您将公众放在服务器端,但客户端需要拥有私钥。

您希望将id_dsa文件(而不是id_dsa.pub)复制到您的USB密钥(确保它受密码保护,以防它丢失!)。

然后,您可以使用该密钥从任何有权访问该密钥的计算机登录home_machine:

ssh -i / path / to / id_dsa user @ home_machine

(看起来你可能已经在office_machine上有一个不同的私钥,根据你粘贴的内容来判断 - 你可能会考虑使用ssh-agent

另外,检查/ var / log / secure以查看sshd可能拒绝密钥身份验证的原因(通常是.ssh目录及其祖先的权限问题)。

相关问题