I did this:

ssh -f user@host "screen -dm -S screenName"

Now I want to add a bash script command to this line so that the command is executed then the screen detaches.


so I want to do so

ssh -f user@host "screen -dm -S screenName bash bashing.sh"


echo "testing it";

but actually nothing happens when I run the command over ssh.

Even when I just from the server run this command only screen -dm -S screenName bash bashing.sh.

edit 1:

I tried everything so far in the answers and comments and even in the suggested question as duplicate but nothing works for me, so any help would be still very appreciated.


  • Its not working – Omar K. Aly Mar 27 '18 at 15:52
  • 1
    "Sure it is - no, it's not - sure it is...". Please add failure details to your question. – NickD Mar 27 '18 at 18:18
  • ssh -f user@host "screen -dm -S screenName want to run bash script here " ====== so I did it like this ssh -f user@host "screen -dm -S screenName sh bashScript.sh" ====== and like this ssh -f user@host "screen -dm -S screenName ./bashScript.sh" ========== and like this ssh -f user@host "screen -dm -S screenName bash bashScript.sh" ======= and none of this run the script – Omar K. Aly Mar 28 '18 at 11:54
  • edit your question do not answer in comment please. Comment maybe deleted and are not made to last. – Kiwy Mar 28 '18 at 12:51
  • @OmarK.Aly where is your bash script ? – Kiwy Mar 28 '18 at 12:52
ssh -f user@host "screen -dm -S screenName sleep 123"
  • That kills the screen after the sleep time is done I want to run a command and keep the screen alive just detach from it – Omar K. Aly Mar 28 '18 at 12:01
  • 1
    ssh -f user@host "screen -dm -S screenName myscript" where myscript does something like sleep 123; bash. – NickD Mar 28 '18 at 13:15
  • @Nick actually my script should do this ====> #!/bin/bash echo "testing it"; ==== And instead of myscript I just used my script name ===> "bashing.sh" .... is that right ? – Omar K. Aly Mar 28 '18 at 13:25

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