How do you set the default ssh path for non-interactive logins in Lion?

How/where do you set the default path when using ssh to access a Mac OS X Lion system? Compare the output of the following two scenarios, both accessing the same Lion system via ssh:


balboa> ssh osx03 echo \$PATH
/usr/bin:/bin:/usr/sbin:/sbin
balboa> ssh osx03
Last login: Fri Feb 10 15:03:20 2012 from balboa
osx03> echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/electriccloud/electriccommande r/bin:/usr/X11/bin


Notice that in the second (interactive) case, the path was updated with all the modifications in the /etc/paths and /etc/paths.d/*, but neither one of these affects the path in the first (non-interactive) case. So how do I change the path in the first case? I need this to get some automated builds working.


Thanks,
Alfred

Posted on Feb 27, 2012 7:19 AM

Reply
11 replies

Feb 27, 2012 7:52 AM in response to etresoft

Thanks for your quick response. I agree that in general it is not a good idea to rely on the PATH setting. However, for this automated build, where I need to use a third party tool which I have added to /etc/paths, I'd like ssh to honor that (or find another way to have ssh update it's PATH). Otherwise, I would have to update a lot of library functions to explicitely use the path, but as these libraries are multi-platform (Linux, Mac, Windows), it would be a bit messy.


Alfred

Feb 27, 2012 12:54 PM in response to avoncampe

I think that additional /etc/path and /etc/path.d information gets loaded when /etc/profile is invoked


# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
        eval `/usr/libexec/path_helper -s`
fi

if [ "${BASH-no}" != "no" ]; then
        [ -r /etc/bashrc ] && . /etc/bashrc
fi


Now why that would not be invoked for a non-interactive session is something I do not know.

Feb 28, 2012 5:41 AM in response to etresoft

Maybe I should have been more specific from the outset. We are using Electric Commander do automate our builds. The EC agent has a problem accessing the user's keychain in Mac OS Lion, so we are using the EC ssh proxy agent feature to get around that issue. But with the ssh proxy agent, we just get the standard built-in to sshd path and all the EC libraries that use the ectool command line tool are failing. Yes, we could update all the libraries with the appropriate conditionals (because they are multi-platform), but I thought it may be easier to modify the path instead.


If we could figure out why the EC agent cannot access the user's keychain in Lion, I wouldn't have this problem in the first place. And when I say the user's keychain, I mean the user that the EC agent is running as. By running a simple EC job that does a "security list-keychains" in both Lion and Snow Leopard, we get the following output:


Lion:

"/Library/Keychains/System.keychain"

"/Library/Keychains/applepushserviced.keychain"

"/Library/Keychains/System.keychain"



Snow Leopard:

"/Users/epdbuild/Library/Keychains/login.keychain"

"/Library/Keychains/System.keychain"


If I could figure out how to access the login.keychain from the EC agent in Lion, then I wouldn't need to deal with changing the ssh path in the first place.


Alfred

Feb 28, 2012 5:54 AM in response to avoncampe

If it is a specific usert account that gets invoked by your build agent, then maybe you can setup the extra PATH information in one of the user's config files


.bash_profile (or .bash_login, or .profile)


"man sshd" talks about ~/.ssh/environment, as well as ~/.ssh/rc and /etc/ssh/sshrc (I've never played with these, so your mileage may vary).


You may also want to look at the destination system's existing bash initialization file to see if there is logic that messes with the PATH based on whether it is being run interactive vs as a subshell. It would not be the first time ssh has been tripped up by the user's shell initialization file.

Mar 22, 2012 3:12 PM in response to etresoft

I understand the general principle in using absolute paths in non-interactive sessions, but the simple fact is that this isn't always an option, particularly when you're using third-party tools that make use of ssh as an underlying communications mechanism.


A prime example of this that I'm encountering at the moment is git. I have git installed from the standard Mac OS X package, in the path it defaults to: /usr/local/git/bin. If you try to use git to access a remote repo on another machine directly, using ssh-based authentication, it will fail with the following message:


$ git remote -v

remoteMachine me@remotemachine:path/to/remote/repo (fetch)

remoteMachine me@remotemachine:path/to/remote/repo (push)

$ git fetch remoteMachine

Password:

bash: git-upload-pack: command not found

fatal: The remote end hung up unexpectedly


Linking all of the git executables into /usr/bin of course fixed this issue, though that's not my favorite solution. I did try to add the following to ~/.ssh/environment:


PATH=/usr/local/git/bin:$PATH


But that didn't affect my non-interactive path. I poked through different ssh man pages to see if it was possible, but couldn't find anything. Editing ~/.bash_profile didn't help either. sshd seems to keep pretty strict control over the PATH value.

Mar 22, 2012 4:23 PM in response to BobHarris

Yeah, I set it up properly in my .bash_profile. I just avoided that nomenclature in the .ssh/environment definition, because the man page says that it specifically looks for "lines of the format ``VARNAME=value''".


It looks like the behavior is PATH-specific. If I do:


ssh remoteHost env


I can see that it's picking up all of the other environment variables I configure in my .bashrc file (which in turn is sourced from my .bash_profile script). But it won't take my path changes. I'm sure this is security-related. I'm just not sure how to override it.

Mar 22, 2012 4:48 PM in response to khawkins_sf

Turns out it's possible with the ~/.ssh/environment approach I tried, but the sshd configuration has to support it, which it doesn't by default. I edited /etc/sshd_config with the following value:


PermitUserEnvironment yes


I was then able to add a PATH value to ~/.ssh/environment, which would then be read. NB: Setting in here will override the entire variable value, without the ability to be additive. E.g.


PATH=/usr/local/bin:$PATH


Will not work. Your path will end up being, literally:


/usr/local/bin:$PATH


You can basically do something like:


echo "PATH=$PATH" > ~/.ssh/environment


And go with the full path you've got at the time. I think I'm actually leaning towards just keeping the /usr/bin symbolic links, as all the conditional one-off path logic and configuration changes actually feel more hack-ish to me, at the end of the day.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How do you set the default ssh path for non-interactive logins in Lion?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.