I know you can suspend a ssh session with ~^z, but is there also a way to background it so that it continues working while you do something else in the local shell?
I know you can suspend a ssh session with ~^z, but is there also a way to background it so that it continues working while you do something else in the local shell?
If you're trying to run a process remotely, and you don't care about keeping the ssh session open, you may want to look at using
screen
. It will allow you to run your process in the "background", and it will keep running after you logout.First,
ssh
over to the remote box, then from there usescreen
and start your process, and you can give yourscreen
a session name if you want. You won't really notice anything different, but start your process in that session. You can than exit out of thescreen
session by using the commandCtrl-a d
. It will look something like this:You can then exit out of your ssh session, and the process will keep running. To reconnect to the
screen
session later on, ssh back to the remote box and usescreen -r
to reconnect. You can usescreen -ls
to list the sessions.Or, if
screen
isn't installed, you could use thenohup
command on the remote box. Wikipedia explains that well:So you could do something like:
After ~^z execute
bg
and the stopped process will continue to execute in background. Works with all processes not just ssh.P.S.: With
fg
you foreground the backgrounded process again. And just for the record: The ~ is only needed to distinguish whether the suspension should be on the local machine (with ~ --> the ssh client) or on the server (without ~ --> whatever process is currently running in foreground on the server)