Main Menu

Search

LINUX: How to Set Passwordless SSH for root users between two Linux Hosts when Root password is Not known And there is just Sudo Root Access?

Lets Assume we have linux-host-1 from which we want to login as root passwordless ssh to linux-host-2 (for which we do not have root password and just have sudo root access). Lets assume appuser has sudo root access.

Below are steps to follow to enable passwordless ssh for root user from linux-host-1 to linux-host-2:

STEP A: On linux-host-1 perform below steps:

1. Login to linux-host-1 as appuser and sudo to root user

2. Copy ssh public key from linux-host-1 using scp to appuser home directory on @linux-host-2. Below is command to run.

ssh-copy-id -i /root/.ssh/id_dsa.pub appuser@linux-host-2

Above command sets passwordless SSH to appuser (for which we have sudo to root) from linux-host-1 to linux-host-2.

3. Now check if SSH login from linux-host-1 to linux-host-2 using appuser works without password prompt using below command.  You should be able to login without being prompted for password.

ssh appuser@linux-host-2

STEP B: On linux-host-2 perform below steps:

1. Now on linux-host-2 login as appuser and then sudo to root

2. Copy authorized keys from appuser to .ssh of root user on linux-host-2. Below are commands to run.

cd /home/appuser/.ssh


cp -rp authorized_keys ~/.ssh/
3. Now Change ownership of the copied authorized keys to root using below command on linux-host-2.
chown -R root:root ~/.ssh/authorized_keys

STEP C: Validate if passwordless SSH using root user works from  linux-host-1 to linux-host-2 using below steps.

1. Login to linux-host-1 as appuser and sudo to root.

2. Run below command to check if passwordless login as root from linux-host-1 to linux-host-2 works.

ssh root@linux-host-2


Products to which Article Applies



All Linux Operating Systems





tarun boyella

No comments:

Post a Comment