Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 22174 - bash reads rcfile when it shouldn't
bash reads rcfile when it shouldn't
Product: Red Hat Linux
Classification: Retired
Component: bash (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Bernhard Rosenkraenzer
David Lawrence
Depends On:
  Show dependency treegraph
Reported: 2000-12-12 13:25 EST by Tim Waugh
Modified: 2007-04-18 12:30 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2000-12-13 05:37:07 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Tim Waugh 2000-12-12 13:25:50 EST
[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 18:39:23 EST
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 17:15:37 EST
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 17:20:49 EST
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.