How to access a ssh account through ssh multihop

If you have a machineA without open ports to Internet, but you can access to it on your local network, a solution is access throught a DMZ machineB with ssh.

Just use this command:

ssh -t userB@machineB ssh userA@machineA

Also, you can create an alias on your ~/.bashrc file:

alias ssh_machineA='ssh -t userB@machineB ssh userA@machineA' 

Other option, is to do it throught ProxyCommand. Add to your ~/.ssh/config file these lines:

# machineA config file
Host machineA
port 22
User lala
# machineB config file
Host machineB
port 22
user lala
ProxyCommand ssh -q machineA nc -q0 machineB 22

If you run ssh, you probably you will get this message:

ssh machineB
nc: getaddrinfo: Name or service not known
ssh_exchange_identification: Connection closed by remote host

To fix it, change the last line by:

ProxyCommand ssh -W %h:%p machineB

Enjoy it!


Popular posts from this blog

from: can't read /var/mail/ in Python scripts

How to fix Android when developer options are not available for this user

How to install a WhatsApp bot based on Python