bash NOT reading .bashrc on RHEL 6
Solution 1
The ~/.bashrc file does not always get read: see Bash Startup Files in the manual.
Does your ~/.bash_profile (or ~/.profile) invoke your .bashrc file? Often this appears in .profile files:
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
Solution 2
Perhaps the documentation is confusing but Bash's standard behavior is to source your "profile" (.bash_profile, .bash_login, .profile whichever it finds first in that order) on interactive login shells and .bashrc on interactive non-login shells.
Sshd typically spawns a login shell where opening an X11 terminal window is typically a non-login shell.
So you should not expect your .bashrc to be read when you ssh into a machine.
That said I generally recommend users add a line like the following to their "profile"
[[ -r ~/.bashrc ]] && source ~/.bashrc
Finally, /etc/bashrc is never directly read by Bush and you'll find no mention of it in the bash man page. It's a file RedHat added and the expectation is that your ~/.bashrc file will source it. The default ~/.bashrc that should have been in your home directory when your account was created should be doing that. If not, you should find an example in the /etc/skel directory.
Related videos on Youtube
Mikel
Computer guy from Australia now living in the US. Part sysadmin, part developer, part web developer. My name is pronounced like "Michael".
Updated on September 18, 2022Comments
-
Mikel almost 2 years
machine A --RHEL 7 and updated.
machine B -- RHEL 6 and updated.If I do this on A (RHEL 7)
ssh B
I get in, like I should, but my .bashrc has NOT been run. This is new behavior to me. I want my
.bashrc
to be run on the machine B (RHEL 6). I did diffs on the/etc/ssh/sshd_config
and/etc/ssh/ssh_config
, and they are different but I don't see why these should matter.ssh_config
differs only by whitespace and comments.Yes, I saw the stuff but even with that it mangled the diff output because of the less than/greater than in it. Is there something in there that I should care about? I hacked and slashed, other than whitespace, comments, and environment variable (
AcceptEnv
) here is what the diff boiled down to.the 6 side
Protocol 2
the 7 side
HostKey /etc/ssh/ssh_host_ecdsa_key AuthorizedKeysFile .ssh/authorized_keys UsePrivilegeSeparation sandbox
So, where do I look to find out why my
.bashrc
won't run? My.profile
, again:alias lo='exit' alias l='ls -CF' alias ..='cd ..'
and my
.bashrc
:PRINTER=its1 export PRINTER DISPLAY=jgs:0.0 export DISPLAY PATH=/usr/bin:/usr/sbin:/bin:/sbin:/opt/bin:/home/gl/bin:. export PATH PROXY=whiteproxy.arlut.utexas.edu:3128 export PROXY cd /home/gl if [ -f /etc/bashrc ]; then . /etc/bashrc fi
/etc/bashrc
is stock.-
yoonix over 9 yearsBash reads the files, not ssh. Read the Bash Guide for Beginners Chapter 3 or this question on Super User to learn how and when to use .bashrc and / or .bash_profile. Also, your question says .bashrc isn't read on RHEL 7, then your example shows you logging in to RHEL 6.
-
LexMulier over 9 yearsI had a similar problem and the explanation that helped me get to the bottom of the issue was this: serverfault.com/a/593487/96078
-