我有一个 Ubuntu 服务器,有两个用户:user1 和 user2。我在本地生成了一个 SSH key 并将公共(public)部分复制到两个用户的 authorized_keys 文件中。我能够以两个用户的身份登录:
srimanth@local:~$ ssh user1@server
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.16.0-31-generic x86_64)
...
Last login: Fri Mar 20 04:11:08 2015 from A.B.C.D
user1@server:~$
srimanth@local:~$ ssh user2@server
Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.16.0-31-generic x86_64)
...
Last login: Thu Mar 19 22:45:26 2015 from A.B.C.D
user2@server:~$
但是,如果我不提及用户名身份验证失败:
srimanth@local:~$ ssh -v server
...
debug1: Connection established.
debug1: identity file /home/srimanth/.ssh/id_rsa type -1
...
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: srimanth@local
debug1: Trying private key: /home/srimanth/.ssh/id_rsa
...
debug1: No more authentication methods to try.
Permission denied (publickey).
请帮助我如何解决这个问题。
最佳答案
SSH 正在尝试使用 srimanth 用户名登录,并且由于它在远程计算机上不存在,因此失败。您必须提供远程有效用户名,否则您将无法登录远程计算机。
由于您已经为两个用户生成了 key 并将其添加到 authorized_keys 文件中,因此当您使用其中任何一个登录时,ssh 能够使用您的私钥对您进行身份验证。
如果您不想在登录时指定用户名,您有两个选择(它仍将使用用户名登录,但您可以避免在命令中指定它):
主机开发
主机名服务器
端口 22
用户 DEFAULTUSER
关于authentication - SSH访问,不提及远程服务器的用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29159533/