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 am trying to execute a command from ssh directly and I need to change the PATH of the directories.

> ssh myserver 'echo $PATH'
myuser@myserver's password:

I am getting /usr/local/bin, but I need only /bin instead of that. I have .bashrc and .bash_profile set in my home directory but the PATH is not taking from there. I tried to change /etc/bashrc and /etc/profile but still no luck.

I have seen the sshd_config file that ssh is compiled with PATH=/usr/local/bin:/bin:/usr/bin . So is there a way to change this default path.?

> cat /etc/ssh/sshd_config
#       $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin
share|improve this question

I'm guessing you are using OpenBSD, which the default shell is ksh (not bash), unless you've changed it. When you run a command through SSH, it is invoked non-interactively. In the case of tsh, I don't think there is a way to force it to set the path by modifying config. There are two options I can think of off the top of my head.

One, you can specify the path before executing your command.

ssh myhost 'PATH=/my/path; echo $PATH'

Two, you can set PermitUserEnvironment to yes in /etc/ssh/sshd_config, then create a file in ~/.ssh/environment that contains something like...


Hope this helps!

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.