2

I have a remote server at www.example.com

And when I use ssh-key login it, everything looks fine. I read some tutorials, established the private/public key pair, etc.

The login looks like:

ssh -lusername example.com #it's working fine

But I want to login as another username, on the same server. I am confused.

ssh -lroot example.com #it's NOT working fine, I have to enter the password

What should I do in this case?

fyi, the root has already got a authorized_keys file by my friend (we share the server) so I have generated a new pub key and append it to the original one.

Thanks

1 Answer 1

6

This should work:

ssh [email protected]
ssh [email protected]

If the private key for root/username isn't being differentiated properly, you can try explicitly calling it out with:

ssh -i ~/.ssh/username_id_rsa [email protected]
ssh -i ~/.ssh/root_id_rsa [email protected]

If the second option still doesn't work then something is wrong with your setup of the public-key on the remote server (check the /var/log/secure or /var/log/auth files on the remote host for more information)

Check that the:

  1. Permission of the .ssh directory is 700.
  2. Permission of authorized_keys file is 600.

Edit, you can also do:

touch ~/.ssh/config
vi ~/.ssh/config

#Add the following:

Host usernameHostname
HostName example.com
User username
IdentityFile ~/.ssh/username_id_rsa

Host rootHostname
HostName example.com
User root
IdentityFile ~/.ssh/root_id_rsa

# Save the file with ' :wq '

Now just type:

ssh usernameexample
[OR]
ssh rootexample
1
  • awesome, the -i argument works! Thanks very much! Feb 5, 2015 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .