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

1 Answer 1


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!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .