Whenever we run a very long jobs on server over ssh, then sometimes the ssh-session will disconnected for various reasons. And when we again try connect to the server, then it will start another ssh-session. Now at that situation reconnect to a disconnected ssh session with the help of tmux utility. tmux is a terminal multiplexer, which can be used to multiplex several virtual consoles, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session. It is useful for dealing with multiple programs from a command-line interface, and for separating programs from the Unix shell that started the program. First install tmux in your system if it not installed.
Check out our other posts about SSH :
How to install OpenSSH Server on Ubuntu Linux 16.04
How to Set up SSH keys on a linux based Client/Server
A Beginners Guide To SSH : How to start with SSH
$ sudo apt-get install tmux
So, in order to make your ssh-session capable to reconnect, first connect to your ssh-server $ ssh test@ubuntusrv
test@ubuntusrv's password:
$
After the connection start tmux $ tmux
Now start your jobs or whatever you want. For example i am downloading ubuntu iso. $ wget http://mirrors.piconets.webwerks.in/ubuntureleases/16.04.3/ubuntu-16.04.3-desktop-amd64.iso
--2017-12-28 10:18:54-- http://mirrors.piconets.webwerks.in/ubuntureleases/16.04.3/ubuntu-16.04.3-desktop-amd64.iso
Resolving mirrors.piconets.webwerks.in (mirrors.piconets.webwerks.in)... 43.240.66.200
Connecting to mirrors.piconets.webwerks.in (mirrors.piconets.webwerks.in)|43.240.66.200|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1587609600 (1.5G) [application/octet-stream]
Saving to: ‘ubuntu-16.04.3-desktop-amd64.iso’
ubuntu-16.04.3-desktop-amd64.iso 0%[ ] 3.43M 51.1KB/s eta 9h 7m
Now i forcefully disconnected the session. Now again ssh into your server $ ssh test@ubuntusrv
test@ubuntusrv's password:
$
And then type 'tmux ls' command, which list all sessions managed by the server $ tmux ls
0: 1 windows (created Thu Dec 28 10:25:47 2017) [197x53] (attached)
our session id is 0. To connect session 0 type $ tmux attach -t <session_id>
$ tmux attach -t 0
$ wget http://mirrors.piconets.webwerks.in/ubuntureleases/16.04.3/ubuntu-16.04.3-desktop-amd64.iso
--2017-12-28 10:18:54-- http://mirrors.piconets.webwerks.in/ubuntureleases/16.04.3/ubuntu-16.04.3-desktop-amd64.iso
Resolving mirrors.piconets.webwerks.in (mirrors.piconets.webwerks.in)... 43.240.66.200
Connecting to mirrors.piconets.webwerks.in (mirrors.piconets.webwerks.in)|43.240.66.200|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1587609600 (1.5G) [application/octet-stream]
Saving to: ‘ubuntu-16.04.3-desktop-amd64.iso’
ubuntu-16.04.3-desktop-amd64.iso. 1%[> ] 16.42M 43.5KB/s eta 9h 32m
and Thats it.Check out our other posts about SSH :
How to install OpenSSH Server on Ubuntu Linux 16.04
How to Set up SSH keys on a linux based Client/Server
A Beginners Guide To SSH : How to start with SSH