Reusing SSH connection
Linux, SSH August 25th, 2008
Very often, while working on a network node via SSH, we need multiple connections to the same node. For example, say you are connected to a node A, and then you need to transfer a file to the same node from your local machine. Then we have to scp, which establishes a fresh connection to that machine and one has to enter the password again. So, it takes some time as well as it is irritating to enter password again and again.
Here’s the remedy :
Open the file /etc/ssh/ssh_config on your local machine as root to edit. Or if you are not the root user, you can create a fileĀ ~/.ssh/configĀ for user level SSH configurations.
Add the following lines at the end of the file you opened just now:
ControlMaster auto
ControlPath /tmp/ssh-%r@%h:%p
Save the file and you are done !!
Now check out (One can try it this way) -Open a terminal and connect to a server :
$ ssh s.siddharth@202.141.81.145
The connection gets established after entering the proper password.
Then in another terminal try to copy a file from your local machine to the same server :
$ scp -r ~/pintos s.siddharth@202.141.81.145
This time, you don’t need to wait for a fresh connection, neither you will have to enter the password again. File transfer starts instantaneously. SSH shared the already established connection.
Similarly you can open another terminal without waiting and entering the password again.
One can check out more configurations for SSH by checking out the man pages of ssh_config
$ man ssh_config
Hope you liked this tip !!