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
Hostname machineA.com
port 22
User lala
# machineB config file
Host machineB
Hostname machineB.com
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!


Comments

Popular posts from this blog

Exception: Could not find a default OpenFlow controller in Mininet

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

v4l2: open /dev/video0: Permission denied