Search code examples
linuxsshrhel7public-key-exchange

SSH Key Exchange with alternate user


So I am using RHEL 7. I have two servers with the following user accounts

  1. root (obvious)
  2. admin

I want the setup to work in the following manner.

passwordless SSH from server 1 to server 2 using the admin user, but the SSH initiation is done from the root user always.

We are not allowed to do ssh key exchange for the root user, but the app that we are working with uses root to ssh to the other nodes.

I hope I am making sense here :)

SSH using root user to server2, but internally it should use admin user's key and connect to server2 using admin user.

I have tried to confiure /etc/ssh/ssh_config file and added host/user config there, now I am able to run ssh server2 from root user and it connects to server2 using my defined admin user in the ssh_config file but it prompts for a password every time which I don't want.

Key exchange with admin is already done and tested to be working fine when I issue ssh as admin user.

Thanks in advance.


Solution

  • In the same file /etc/ssh/ssh_config you need to add the key to use, something like this:

    Host srv2
     User admin
     IdentityFile /home/admin/.ssh/id_rsa