It’s common to need programs/commands to keep running after exiting SSH, but I always forget how to do it. Since I usually set it up as an alias for quick use, I tend to lose track of the details over time and have to look it up again. That’s why I’m writing this note to document it.
To keep commands running after closing the SSH connection, you’ll need the nohup command—its usage is similar to time. Here’s a typical example:
nohup jupyter lab --ip 0.0.0.0 --no-browser --port=8888 --allow-root &
jupyter lab --ip 0.0.0.0 --no-browser --port=8888 --allow-root (the program you want to run).& sends the process to the background.nohup.out FileIf you run the command above (especially when wrapped in an alias), a nohup.out file will be automatically created. This is because many commands generate output (normally sent to standard output), and nohup redirects this output to nohup.out by default—this can get messy if left unchecked.
Add > /dev/null 2>&1 at the end to discard all output (send it to a “null device”):
alias jr="nohup jupyter lab --ip 0.0.0.0 --no-browser --port=8888 --allow-root > /dev/null 2>&1 &"
Now you can exit SSH freely, and the command will keep running without generating extra files!
I hope these will help someone in need~