2

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?

3 Answers 3

2

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.

1
  • You were right, my problem were the permissions. When I set the permissions according with what is recommended in the OpenSSH FAQ item 3.14, it worked. openssh.org/faq.html#3.14
    – lpacheco
    Jan 11, 2011 at 15:38
4

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

4
  • notice that you can debug with ssh -vvv <rest of command> and you will see which keys are tested, @desasteralex solution should be ok as you force the key used, without informations several key are used, maybe not the one you want.
    – regilero
    Jan 10, 2011 at 21:42
  • @regilero: Agree, but I came to the conclusion that lpacheco is using several keys already, see: "$user1@hostA> ssh user1@hostB". The public key of user1 already exists in the authorized_keys file on hostB, and so the user does on hostB. Jan 10, 2011 at 21:59
  • If I owned both accounts, I could do that, but I own user2 and want to allow user1 to connect as user2 in a single machine. I understand that if I give user1 the private key of user2, he would be able to connect as user2 to any other machine that user2 has access, right?
    – lpacheco
    Jan 11, 2011 at 15:46
  • @Ipacheco: Yes, if user1 got the private key of user2, he/she can connect to every machine on which the public key of user2 has been added to the authorized_keys file. Exception: user1 needs to know the username of user2 on the destinated machine (depends on into which users authorized_keys file you've placed the public key). Jan 11, 2011 at 23:07
2

You could also place the pub key of user1 in the authorized_keys file of user2 on hostB.

1
  • That's what I did, but it isn't working.
    – lpacheco
    Jan 11, 2011 at 9:39

You must log in to answer this question.

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