Run SSH command in background

Do you have to run a big command that requires 30 minutes, 1 hour, 2 hours or 6 hours? Unfortunately SSH connections times out.

Here's a simple trick on how to run a ssh command in the background so you can run your command and maybe sleep for a while or continue with your life.

 

In your terminal, run:

nohup YOUR_COMMAND your_command_parameters > my.log 2>&1 &

 

And just in case you were thinking how to close the command, in your terminal, run:

ps -ef | grep 'YOUR_COMMAND'

It will return something like this:

UID        PID  PPID  C STIME TTY          TIME CMD
root       361     1  0 Oct19 ?        00:00:04 YOUR_COMMAND

Get the PID to kill the command

kill 361

 

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.