I am trying to ssh into a remote machine and run a shell script, which opens a GUI. I want the GUI to open on the remote machine and remain open (so I am using DISPLAY=:0 nohup). I tried:

ssh -t <user-name>@<remote-host> "DISPLAY=:0 nohup ~/<script-to-be-run>.sh"

This worked great, but I can't send another command without closing the window because the GUI called in the shell script ties up the command line. I tried using "DISPLAY=:0 nohup ~/<script-to-be-run>.sh &" and "DISPLAY=:0 nohup ~/<script-to-be-run>.sh && exit", but these produce the same result: the GUI opens and the command line is left hanging.

I read about using screen to detach the command from the shell session, but this doesn't seem to work. On the remote machine (NOT running through ssh, just sitting in front of it), I tried:

screen -m -S 'test' 'DISPLAY=:0 nohup ~/<script-to-be-run>.sh'

but I get an error:

Cannot exec 'DISPLAY=:0 nohup ~/<script-to-be-run>.sh':No such file or directory.

The command DISPLAY=:0 nohup ~/<script-to-be-run>.sh works just fine when run on the remote machine (while sitting in front of it). Anyone know how to get this command to work with screen so that I can run the single GUI command in its own terminal container?

1 Answer 1


Normally, screen accepts a command and arguments, so this might work:

screen -m -S 'test' nohup ~/<script-to-be-run>.sh

Because it is not expecting a variable assignment, and the variable might otherwise be reset, you would probably have to add env to set the variable:

screen -m -S 'test' env DISPLAY=:0 nohup ~/<script-to-be-run>.sh'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .