[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] The execution of /etc/bash.bashrc and ~/.bashrc for non
Re: [Help-bash] The execution of /etc/bash.bashrc and ~/.bashrc for non interactive shells
Fri, 7 Apr 2017 21:57:51 -0400
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.0
On 4/6/17 3:30 AM, Cristian Zoicas wrote:
> Now let's analize what happens under ssh.
> I) When running "ssh address@hidden" bash executes the system/user profiles
> (/etc/profile and ~/.profile)
> II) When running "ssh address@hidden ls -l" the system/user profiles are not
> executed but .bashrc is executed.
> In case I) when the user logs on the system/user profiles are executed. This
> is consistent with all the behavior presented so far.
That's because case I is really "slogin address@hidden".
> But in the second case the things are very surprising:
> a) although the user is authenticated the system/user profiles are not
> executed, and
> b) to make the things even more confusing, although the shell is not
> interactive .bashrc is executed.
In case II, what ends up actually being executed is `bash -c "ls -l"'. This
is how sshd invokes the shell to run the requested command. It's not a
login shell, so no login shell startup files. The fact that .bashrc is
read and executed is exactly what we're discussing here: it was added as
an optional feature due to user requests.
> All this behavior is documented in the man pages of ssh and bash, but I simply
> cannot understand why was not possibile to start a login shell and
> consequently to have bash loading the system/user profiles instead of starting
> a non-interactive shell that loads .bashrc. This is also in contrast with the
> purpose of the .bashrc files that must prepare the shell for an interactive
> session (which does not occur in the case II).
> Why the request of loading .bashrc and the impossibility of starting a
> login shell (when a login is performed)?
I explained, in my previous message, exactly why bash reads .bashrc when
it's invoked by ssh, and the reasons users requested it.
If you want sshd to start a login shell for every command that it receives,
you'll have to request that feature with the ssh developers.
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU address@hidden http://cnswww.cns.cwru.edu/~chet/