Take the 2-minute tour ×

Is there any way that ssh can specify the working directory on the remote host when executing bash scripts through ssh? So that the bash scripts can use relative path in it instead of absolute path. The below example seems not working. Please help, thanks.

Example for bash script on remote host:

./executable -o arg1 -i arg2

Example for command send on local:

ssh id@remote.hostname '/path/to/script/myscript.sh'
share|improve this question

1 Answer 1

up vote 5 down vote accepted

Your working directory on the target system should be the login users's home directory. run

 ssh id@server pwd

If you want to be in a particular directory before running the program, then do this:

 ssh id@server "cd /path/to/dir && pwd"

Do note the double quotes, without quotes, it will get treated as two commands.

share|improve this answer

Your Answer


