I need to connect to hostB using user2 from hostA where I´m connected using user1.
I've run ssh-keygen for user1 on hostA and copied the public key generated in id_rsa.pub to the 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?
You need to tell your ssh to use the private key of user2 instead of yours (user1):
$user1@hostA> ssh -i /path/to/private_key_of_user2 user2@hostB
sshd will ignore your files if it doesn't like the permissions. I was able to duplicate this behavior by setting "user2"s ~/.ssh directory world writable.
You could also place the pub key of user1 in the
authorized_keys
file of user2 on hostB.