Main Menu

Search

Showing posts with label passwordless ssh. Show all posts
Showing posts with label passwordless ssh. Show all posts

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



LINUX: How To Setup SSH Keys To Enable Passwordless SSH Between Linux Hosts? (RSA)

This article provides detailed steps on setting up SSH keys to enable passwordless SSH between Linux hosts.

For example lets assume you want to enable passwordless SSH between two Linux hosts source-vm and target-vm, where source-vm is the host from which you want to connect to target-vm host via SSH without password prompt, below are steps to follow.

1. On source-vm cd .ssh directory inside user home directory. Below command can be used.
cd $HOME/.ssh

2. Create SSH rsa keypair using below command.
ssh-keygen -t rsa

Below is example output of above command.
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
0b:12:45:53:31:78:64:7d:68:b9:1c:54:36:2d:51:3e root@source-vm
The key's randomart image is:
+--[ RSA 2048]----+
|     .++*+.+=+.  |
|     ..o..*.oo.  |
|    .  . o + .E  |
|     .    o    . |
|    . . S        |
|     . . .       |
|        .        |
|                 |
|                 |
+-----------------+

Once above command is executed, we will see below files inside <user home>/.ssh directory on source-VM.

authorized_keys 
id_rsa 
id_rsa.pub 
known_hosts

3. Now copy the public key id_rsa.pub  from source-vm <userhome>/.ssh directory to target-vm <user_home> directory. This can be done using scp command.
ssh-copy-id -i $HOME/.ssh/id_rsa.pub <user>@target-vm

Other option is to copy public key from source-vm to target-vm as authorized_keys in ~/.ssh/ directory. For this below command can be used.
scp $HOME/.ssh/id_rsa.pub <user>@target-vm:~/.ssh/authorized_keys

4. Now test passwordless ssh from source-vm to target-vm using ssh command as follows on source-vm.
ssh <user>@target-vm

You should be logged into target-vm from source-vm without being prompted for password.


Products to which Article Applies



All Linux Operating Systems. The steps in this article should also work on other UNIX bases Operating systems.


Additional References