Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to shoot a command to server to be run say forever! under "screen session" using ssh.

so I am using something like

ssh -t root@server screen -S myinf "python &"

where is the script. The problem the "python" doesn't go in a background and neither a screen called "myinf" is created.

I appreciate your hints.

share|improve this question
nohup is your friend. It will keep the command running even after ssh session closes. – Jim G. Jul 16 '13 at 19:38
Thanks, it would be great to help me out to integrate screen session as well :) – user702846 Jul 16 '13 at 20:19
up vote 1 down vote accepted

This is because screen as invoked by you requires a pty to function. You will need to start screen in detached mode:

ssh root@server screen -d -m -S myinf python
share|improve this answer
it work; may I ask why when I replace "python" with a simple "ls" command it does not work ? – user702846 Jul 17 '13 at 5:04
oh, it does work, but ls will terminate quickly, taking screen with it. You're likely to be too slow to ever see the session :) – Dennis Kaarsemaker Jul 17 '13 at 5:54
can I specify a pending time or something similar to avoid the quick termination ?! thank you. – user702846 Jul 22 '13 at 22:19

do this

 ssh -t root@server "nohup bash -c '( ( /usr/bin/python &> /dev/null ) & )'"

this is because the tty that opened need to close and thus cannot keep the command running. to see the output, change /dev/null to an actual file name.

i have not tried to use remote screen so I omitted that. you may be able to get it to work but maybe the syntax is off a little bit.

share|improve this answer

You don't need the quotes or the ampersand. Use the -d -m options to start screen in a detached mode instead. Take a look at the man page for more infomation.

A working example command line is:

ssh $host screen -S myinf -d -m tail -F /var/log/dmesg
share|improve this answer
sudo for what !? I don't have sudo access ! – user702846 Jul 16 '13 at 23:01
It isn't important for the discussion. I used sudo to read a log file since I don't have on my test host. The important part is that everything after the options is considered a command line to run inside the screen session. – Rik Schneider Jul 16 '13 at 23:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.