Ssh password less login with different ID

Hi,

I have setup password less ssh connection between Server A and Server B and I am able to connect with User2.

But my requirement is, User 1 run a script in Server A to ssh into Server B as User 2 but it is asking password every time I execute.

Server A:
Login as User 1 and execute sh script, it has
/usr/bin/ssh -t user2@ServerB -- Asking password here

Server 2:
user 2 has permission to execute ServerB script

Please help me to solve this issue.

How is ssh from server A to server B, setup. Did you setup this server wide or user wide. In other words, did you setup a system key or user key for user 1?

Set it up for user2 the same way you set it up for user1 -- append into their authorized_keys. The same key will work for both.

We have setup a public key using ssh-keygen and copied (ssh-copy-id) the id_rsa.pub file for both User 1 and User 2.

Even after setting up User 1 password less login it is not working.

I am able to ssh server A to Server B

as
Login as User1 at ServerA and ssh as User1@Server B
or
Login as User2 at ServerA and ssh as User2@Server B

but not able to do

login as User1 at ServerA and ssh as User2@Server B

Then I'm pretty sure the private id_rsa is different for the two users. Make sure either id_rsa is the same on server A or serverA:user1's public id_rsa.pub is appended to serverB:user2's authorized_key and vice versa.

I tried with the public key.. still it is not working...

that is I copied ServerA: user1 id_rsa.pub key and added in ServerB:User2 authorizedLkey file.
Also I tried
copying ServerA:User2 id_rsa.pub and added in ServerB:User1 auth key file.

does not work, still asking password.

Check permissions on your home directories, ls -ld ~/

Being world-accessible will stop autologin from working. ssh is picky about permissions.

No permission issue.. I have permission :frowning:

Check the log files. Increase loglevel / verbosity.