I'm quite new to ubuntu and I need to do something but I don't know how.

Let's supose that I want to connect to a server, start a big compilation (hours) and I don't want to keep connected to the server while it compiles.

Now if I disconnect and connect again, I cannot see the output of the compilation (I assume the connection creates a new session)

Is there a way to connect, launch something, disconnect and when connecting again resume the previous connection so I can see all the output to the console that has been done so far? (Like if I do a remote desktop, but in ssh)



Actually I'm interested in recovering the console session. Imagine that the compilation or any other thing that I might be running at some point asks user input in order to continue.

Toy example:

1) I connect by ssh

2) I run sudo apt-get dist-upgrade

3) This will ask me confirmation to upgrade (I know I can pass some flags to avoid confirmation but I don't want to)

4) I disconnect

5) I connect again and I want to be able to see the history and the console asking me confirmation to upgrade

6) I confirm to upgrade and disconnect again.


You want a persistent terminal multiplexer, such as tmux or GNU screen.

These allow you to open one or more shell sessions within a single connection; detach from them (either deliberately, say at the end of your workday, or unintentionally, as due to network problems) and later reconnect to the same shell session(s).

There are many subcommands and possible customizations, but a typical use would be as

$ tmux      /* starts new shell, with tmux status bar at the bottom of terminal window */
$           /* do stuff */
$ Ctrl-b d  /* key escape sequence to detach from tmux session */
$ exit

            /* ... time passes; much later you ssh back in ... */

$ tmux attach

            /* and you're back on the session you detached from */

As an additional note, while I provided links to the project webpages, both options are packaged for ubuntu and can be installed via sudo apt install, if not already installed on whichever OS version you are running.

  • Yes, that's exactly what I was looking for. Thanks – Sembei Norimaki Sep 7 '16 at 22:20

You may start the command like

nohup <your command>  &

This will not only detach the process from your ssh shell (otherwise the process will be killed upon logout), but also creates a file named nohup.out that contains all the output of your process.

  • But it outputs into a file. Is there a way to recover the console output? Let's supose that instead of a compilation is something that at some point asks the user to input something. I updated the question – Sembei Norimaki Sep 6 '16 at 15:26
  • There is a tool that allows you to interrupt a ssh session and pick it up afterwards. I only don't find it's name right now... try googeling – PaulS Sep 6 '16 at 15:28
  • You also may have a look here xmodulo.com/how-to-suspend-ssh-session-in-linux.html – PaulS Sep 6 '16 at 15:31

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.