Monday, February 05, 2024

Re: Proper way to set PATH environment with SSH non-interactive command

Thus said "Andy Bradford" on 04 Feb 2024 08:39:27 -0700:

> But is there a file that I can modify that will cause the shell proper
> to load some kind of environment setup also for non-interactive shells
> started with -c?

[For the archives]

As it turns out, given that the shell does not itself read any profile
configuration files for non-interactive shells, I can just update
/etc/login.conf using ~/bin in the path:

default:\
:path=~/bin /usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin /usr/local/sbin:\

Before:

$ ssh localhost env | grep PATH
amb@localhost's password:
PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin

After:

$ ssh localhost env | grep PATH
amb@localhost's password:
PATH=/home/amb/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin

Arguably, this could be done for a class that is assigned to different
users for which this should apply so not everyone has this. Also, this
does not impact interactive shells because, well, interactive shells
read ~/.profile and consequently ENV applies.

Andy

No comments:

Post a Comment