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

6

This should work:

ssh username@example.com
ssh root@example.com

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 username@example.com
ssh -i ~/.ssh/root_id_rsa root@example.com

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
  • awesome, the -i argument works! Thanks very much! – AGamePlayer Feb 5 '15 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.