Reputation:
I have an Ubuntu server with two users: user1 and user2. I have generated a SSH key locally and copied the public part to both users' authorized_keys file. I am able to login as both users:
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:~$
But, if I don't mention the username authentication fails:
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).
Please help me how do I solve this issue.
Upvotes: 1
Views: 7668
Reputation: 76
SSH is trying to login with srimanth username and since it doesn't exist on remote machine it fails. You must provide a remote valid username, or you will not be able to log into the remote machine.
As you had generated key and added it to authorized_keys file for both users, when you login with any of them, ssh is able to authenticate you using your private key.
If you don't want to specify username on the login, you have two options (it will still use the username to login but you can avoid specifying it on the command):
Add srimanth user to the remote server and add the public key to its authorized_keys file, so that from your machine when you are logged in as srimanth, and try to SSH, it uses the same username and lets you login to the remote machine.
Add an entry to your SSH config to use specific username when you are connecting to a particular host:
Host dev HostName SERVER Port 22 User DEFAULTUSER
Upvotes: 3
Reputation: 1943
If you don't specify the login username, ssh will try to log into the instance with your current user name: In your case, and by looking at your question, this would be srimanth.
For this to work, srimanth user account must exists first on the server, or a default userlogin for the instance in srimanth user SSH configuration file must be defined as describe in this answer from Learath2 to this question.
See Adding and Deleting Users to create an user account in an Ubuntu server.
Upvotes: 0