Bug 22174 - bash reads rcfile when it shouldn't
Summary: bash reads rcfile when it shouldn't
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: bash
Version: 7.0
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Bernhard Rosenkraenzer
QA Contact: David Lawrence
Depends On:
TreeView+ depends on / blocked
Reported: 2000-12-12 18:25 UTC by Tim Waugh
Modified: 2007-04-18 16:30 UTC (History)
2 users (show)

Clone Of:
Last Closed: 2000-12-13 10:37:07 UTC

Attachments (Terms of Use)

Description Tim Waugh 2000-12-12 18:25:50 UTC
[root@turmoil /root]# id; id user
uid=0(root) gid=0(root)
uid=500(user) gid=500(user) groups=500(user)
[root@turmoil /root]# grep ^user /etc/passwd
[root@turmoil /root]# su user -c ':'
bash: /root/.bashrc: Permission denied
[root@turmoil /root]# strace -feexecve su user -c ':' 2>&1 | grep bash
[pid  1399] execve("/bin/bash", ["bash", "-c", ":"], [/* 25 vars */]) = 0
bash: /root/.bashrc: Permission denied

The man page says that 'bash -c :' should not be considered interactive,
and only interactive shells should read .bashrc.

Comment 1 Tim Waugh 2001-02-01 23:39:23 UTC
Thi only happens with BASH_ENV set, just like the documentation says.  Thanks to
Chet Ramey for diagnosing.

Comment 2 Need Real Name 2002-02-03 22:15:37 UTC
This bug should be reopened for RedHat 7.2 and openssh-2.9p2-12.
OpenSSH is causing the "~/.bashrc" file to be read for 
non-interactive shells.

To see this do the following.

  + For each F in "/etc/ssh/sshrc", "~/.ssh/rc", "/etc/profile",
                  "~/.bash_profile", "/etc/bashrc", and "~/.bashrc"
    on the host and target account do the following.

      - Prepend the lines (replacing %F with the filename)

echo "In %F for USER=\"${USER}\"," >> /tmp/ssh-errors.txt
echo "with PS1=\"${PS1}\"," >> /tmp/ssh-errors.txt
echo "with ENV=\"${ENV}\", and" >> /tmp/ssh-errors.txt
echo "with BASH_ENV=\"${BASH_ENV}\"." >> /tmp/ssh-errors.txt

      - Comment out the usual references to other rc files.

Now for a warm up see what happens when you execute

    /bin/bash -c "/usr/bin/env"

from within the target account.  According to 


this is the intended effect of running ssh, scp, etc.  So have
a look at "/tmp/ssh-errors.txt".  On my RedHat 7.2 box it remains
empty because this is neither a login nor an interactive shell.

However, when we do the same from another RedHat 7.2 host via
the OpenSSH command

    ssh andrew@hostname "/usr/bin/env"

"/tmp/ssh-errors.txt" now contains the lines

In .ssh/rc for USER="andrew",
with PS1="",
with ENV="", and
with BASH_ENV="".
In .bashrc for USER="andrew",
with PS1="",
with ENV="", and
with BASH_ENV="".

The first reference is expected.  The sshd(8) manpage explains
that "~/.ssh/rc" wil be sourced, but there is no explanation
for "~/.bashrc" being sourced.  Not even the one caused by
the earlier RedHat practice of setting ENV to this file.
Furthermore, the shell is clearly non-interactive because PS1
is _not_ set.

This is _very_ annoying because it means there is nowhere
to put stty commands or send messages at login, because
OpenSSH wil stupidly invoke these interactive shell resources.



Comment 3 Need Real Name 2002-02-03 22:20:49 UTC
My mistake --- wrong bug report number, I'll go and affix this
to an OpenSSH bug where I thought I was typing it.

Note You need to log in before you can comment on or make changes to this bug.