A couple of tricks that I use when working with ssh
If you are on a Linux machine and you often have to go through ssh to different hosts, then a small trick will help you not to enter the password if you are connecting to a host with which you already have a connection:
vi ~/.ssh/config
add lines
host *
controlmaster auto
controlpath /tmp/ssh-%r@%h:%p
In this case, “host *” means that this trick will apply to all hosts. If you want, you can change the mask at your discretion.
')
Also often there is a situation when you need to connect 2 machines in different networks. For example, one machine uses for tests a database that is located on a server on another network shared by the Internet. In such cases it is very convenient to use ssh tunnels.
ssh -p22 -2 -N -C -f -L 6632: 192.168.100.72: 66320 tunnel@88.88.88.88
in this case
6632 - the port on the local machine to which you connect to get to the port of the machine in the remote network.
192.168.100.72:66320 - IP address and port of the machine in the remote network.
tunnel@88.88.88.88 - username and IP address of the server that is located in the remote network and looks into the Internet through it, we actually prokidyval tunnel.
I hope this will be useful.