When using ssh with priv/pub keys, how to connect to the destination using a user different from the origin machine?
- by lpacheco
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?