When using ssh with priv/pub keys, how to connect to the destination using a user different from the origin machine?

Posted by lpacheco on Server Fault See other posts from Server Fault or by lpacheco
Published on 2011-01-10T21:02:57Z Indexed on 2011/01/10 21:55 UTC
Read the original article Hit count: 214

Filed under:
|

I need to connect to hostB using user2 from hostA where I´m connected using user1.

I've run ssh-keygen -t rsa on hostA and copied the public key generated in ~/.ssh/id_rsa.pub to the ~/.ssh/authorized_keys of user2 in hostB.

Then I tried to connect from hostA to hostB using the command:

   $user1@hostA> ssh user2@hostB

I still get a request for password:

   user2@hostB's password:

If I try to connect using the same user on both hosts, it works correctly:

   $user1@hostA> ssh user1@hostB
   Enter passphrase for key '/home/user1/.ssh/id_rsa':

What am I missing?

© Server Fault or respective owner

Related posts about ssh

Related posts about authentication