We will be able to ssh from one remote-1 machine into another remote-2 machine without typing its IP and the password in the terminal.

Prerequisite

A user with sudo privileged access to the remote servers

Implementation

1. Log in to a remote-1  server

ssh user@ip


2. As a root user run the below command to add the remote-1 server key to the remote-2 server to log in without a password

ssh-copy-id user@remote-2 IP
===
Provide the required password
===

3. Log in to a remote-2 server and edit the sudoers file

vi /etc/sudoers

5. Copy and paste the below line under the section #includedir /etc/sudoers.d to avoid entering the password while doing sudo su

Then save and exit from the file

user ALL=(ALL) NOPASSWD: ALL


7. In the remote-1 server under as a root user, add the alias in the .bashrc file

cd /root
vi .bashrc

====
Copy and paste the below line. Modify the IP and name accordingly without adding space
====

alias name=’ssh user@remote-2 IP’


8. Then execute the .bashrc script with the below command

source ~/.bashrc

9. Then try to access the remote-2 server with the alias name from the remote-1 server, we should able to log in without password and IP address

Leave a Reply