I created a new home directory for myself on my SSH server and when I log in my bashrc is never loaded, I always have to type . ~/.bashrc after I log in. How can I save keystrokes so this is done automatically?

  • thats only for interactive shells - you might want to put those commands into ~/.profile or ~/.bash_profile instead – Steven Penny Jun 5 '18 at 20:54
  • Is your default shell bash? .bashrc won't run for zsh, sh, ash, csh, etc. – DopeGhoti Jun 5 '18 at 21:16
  • @DopeGhoti Yes it is. If I were to use a different shell would there be a better way to go about this? – papermachine Jun 5 '18 at 21:32

You could link your .bash_login - used when you login - to your .bashrc - used for other bash shell sessions:

mv -f .bash_login .bash_login.old    # Don't worry if this says no such file
ln -s .bashrc .bash_login

Ensure that the commands in your .bashrc can handle the possibility that they are being run without a terminal being connected. So don't print anything unless there's a terminal attached to stdout, for example.


Bash is not POSIX compliant here.

Any interactive shell should read the file $ENV in the users home directory, but bash reads $HOME/.bash_login instead in case it is a login shell and even reads this file before reading $HOME/.profile instead of reading it after that file.

Fortunately, this deviating behavior is documented in the bash man page under the section INVOCATION that starts aprox. at page #3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.