How to leave a command running when your SSH session is disconnected.

Posted: March 14, 2015. At: 10:37 PM. This was 3 years ago. Post ID: 8101

If you want to leave a command running if you are disconnected from your SSH session, then the nohup command can come in handy.

This is a good example, this will run the nmap scan and then logout the user. When you re-connect, it will still be running.

nohup sudo nmap -A -T2 -P0 hackthissite.com -oN nmap-log.log &exit

So, this is a good way to run a command over SSH that will take a long time. The -oN nmap-log.log parameter to nmap will output the scan results into a file named nmap-log.log for later perusal when you log back in. Otherwise, the penetration tester would have to wait for ages whilst a long nmap scan completed. This is a very useful Linux tip and well worth knowing when the user is accessing a machine like Amazon AWS over an Internet connection and the connection is not always reliable.

Very old CRT terminal.
Very old CRT terminal.

This way, the user can run commands over a flaky Internet connection, and the command will still be running when the user is disconnected. This is why the Linux command line is so powerful.

No comments have been made. Use this form to start the conversation :)

Leave a Reply