Running SSH commands (remotely)

Consider a login on ta Host machine. To run a command (let us try a simple ls to list the current directory), just type:

ssh -X login@IPhostMachine ls

In practice, commands are longer and you would rather use double quotes around the command(s)

ssh -X login@IPhostMachine "cd temp; ls"

SSH logs you in the home directory (e.g., /home/login).

Then, you can type most of the unix commands. You need to be careful with single and double quotes.

Note also that to run a command in the background, you need this kind of syntax:

    ssh login@host "nohup myprogram > foo.out 2> foo.err < /dev/null &"

This simple one may not work:

    ssh login@host "myprogram &"

Indeed, backgrounded job can cause the shell to hang on logout.

Please follow and like us:
This entry was posted in Linux and tagged . Bookmark the permalink.

One Response to Running SSH commands (remotely)

  1. Jochen says:

    The screen program could be mentioned in this context, which allows you to open a (/several) shell(s) which stay open even if the connection is interrupted. I use it to run simulations on a remote PC if it takes longer time.

    IIRC the shell hangs on logout if stderr, stdout are not redirected to some other place.

    As you state you’re also interested in Python you might be interested in this question and answers on stackoverflow

Leave a Reply

Your email address will not be published.