How-to Make a Process Continue to Run After Closing an SSH client

If you are connected to a remote server via SSH, you may want to start a time-consuming task or a background task in the server and right after starting it, close your SSH client, because you need to turn off your computer to “save the earth”, reduce your electricity bill, or simply because you need to bring your laptop with you.

The problem is that if you close your SSH client, the terminal session will be terminated together all processes launched from this terminal. There are 2 tools to solve this issue: GNU screen and nohup.

GNU screen

screen may not be installed in your Linux distribution. In Debian/Ubuntu you can install it with apt-get:

sudo apt-get install screen

In your SSH terminal, start GNU screen:

screen

Press enter to discard the text, run your command and press Ctrl+a+d (and not Ctrl+Alt+d) to detach the screen. That’s it. You can now close your SSH client. Next time your connect via SSH, you can go back to your screen as follows:

screen -r

nohup

nohup command is even simpler, but you won’t be able to revert to your old screen:

nohup command &

nohup is simpler to use and should already be installed in your Linux distribution, but screen will allow you to continue working in the exact same screen and with the environment you had before closing your SSH client.

Share this:
FacebookTwitterHacker NewsSlashdotRedditLinkedInPinterestFlipboardMeWeLineEmailShare

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX RK3588 mini-ITX motherboard

2 Replies to “How-to Make a Process Continue to Run After Closing an SSH client”

  1. I would add http://tmux.sourceforge.net/
    I personally find it better than screen.
    A quick shortcut cheatsheet for it:

    tmux – start it
    tmux attach – attach to already running session

    Ctrl-B D -> detach tmux
    Ctrl-B C -> create new tab
    Ctrl-B N -> switch next tab (right)
    Ctrl-B P -> switch previous tab (left)

    Have fun 🙂

  2. hi,

    using nohup on debian ive found it less than reliable for running webdav .. thanks for posting the alternatives i’ll give them a try ..ian

Leave a Reply

Your email address will not be published. Required fields are marked *

Boardcon Rockchip and Allwinner SoM and SBC products
Boardcon Rockchip and Allwinner SoM and SBC products