linux – Do not interrupt the execution of the command even after the connection with the server is broken

Question:

I transfer 27tb from one server to another via ssh:

 scp -r /home/ root@192.168.0.2:/home2/

I open the console in Mozilla (FireSSH), when I close the tab with the console, copying is interrupted, how can I continue copying with the terminal closed?

Answer:

in such cases, it is convenient to use the terminal's multiplexer .

when creating a new multiplexer session, a shell session will be (automatically) launched inside, where it will be possible to run a "long-running" program. even the loss of communication (between your local computer and the computer where you started the multiplexer session) will not stop the multiplexer session, and, accordingly, the shell session and the program running in it.

and, which is important, after reconnecting you will see everything (within the size of the multiplexer buffer, of course) that the "long-running" program outputs.


minimal usage examples for the most common gnu/screen and tmux multiplexers:

gnu/screen

  • view a list of sessions running on a given computer:

     $ screen ls
  • create a named session (or connect to an existing one):

     $ screen -RD имя_сессии
  • disconnect from session:

    ctrl+a d

tmux

  • view a list of sessions running on a given computer:

     $ tmux ls
  • create a named session:

     $ tmux new -s имя_сессии
  • connect to an existing session:

     $ tmux a -t имя_сессии
  • disconnect from session:

    ctrl+b d


the session will end when the shell session that is running inside the session terminates. this, as usual, can be done either with the command:

$ exit

or by pressing ctrl+d

Scroll to Top