Ssh – How to run a process overnight on a remote server after quitting out ssh

processremotessh

I'm really new to linux (like earlier this week is when I started) so excuse me if this is a really simple question. I am running a program on a remote server and it's a lengthy process dealing with a couple hundred gb of data so I wanted to leave it running overnight. Long story short I ssh in, I start the program, watch to see that it's running and then close out of terminal. I come back this morning and see it stopped exactly where it was when I terminated my ssh the night before. Is there a way to keep the process running on the server when I close out?

Best Answer

As the other answers suggest. You can use nohup <command> &.

You can also use screen, this (basically) is a detachable terminal. You can start a terminal using the command screen and when you want to detach from it. Ctrl+ad. And to reattach your terminal run screen -r <terminal_name>. If you have more then one detached terminal's, you can use the command screen -r to see the names of the detached terminal's.

Screen is a full-screen window manager that multiplexes a physical ter‐ minal between several processes (typically interactive shells). Each virtual terminal provides the functions of a DEC VT100 terminal and, in addition, several control functions from the ISO 6429 (ECMA 48, ANSI X3.64) and ISO 2022 standards (e.g. insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows moving text regions between windows.

EDIT:

You can also use tmux. Have a look here for a basic "how to use tmux".

tmux is a terminal multiplexer. What is a terminal multiplexer? It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more.

Related Question