Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

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/'
share|improve this question
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


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.