Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I ssh into a server (4.3.3-2-ARCH), my .bashrc is not loaded (however, I can load it manually by sourcing it).

I don't have any other files in my home folder, like .profile. The shell is also correct

$ echo $SHELL
/bin/bash

When I login using ssh -t myserver /bin/bash , my .bashrc IS loaded correctly.

In SSH verbose mode, I do see that /etc/bash.bashrc and ~/.bashrc are loaded using the last command. When using the default ssh command, none of them is being loaded...

What should I configure to have .bashrc (and /etc/bash.bashrc) loaded when using the default ssh command?

share|improve this question
up vote 7 down vote accepted

the ~/.bashrc file is loaded for interactive non-login shells, that's why running /bin/bash from ssh works as you expect.

For login shells (amongst others) ~/.bash_profile is read. Typically your ~/.bash_profile contains something like

if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

Which ensures that ~/.bashrc is loaded if your shell is a login shell.

If your ~/.bash_profile contains the above and ~/.bashrc is not being loaded you can debug the scripts by using set -x as usual.

share|improve this answer
    
I do not have a ~/.bash_profile ... So, I do need to create it with the above lines in it? – intrixius Jan 7 at 9:22
2  
    
I created the ~/.bash_profile file and it works... I have installed multiple servers in the past, and I cannot remember that I had to create that to get bashrc working... – intrixius Jan 7 at 9:30

Normally when a user is created it will copy a bunch of files to your new homedirectory (if you chose to create one).

You can check the /etc/skel directory for those files. There should be the .bash_profile that you expected.

share|improve this answer
    
/etc/skel does indeed include .bash_profile . So i don't know why I did not have it. I just created my user with useradd username ... strange – intrixius Jan 7 at 10:43
    
were the contents of the file as exspected tho ? – Koen van der Rijt Jan 8 at 14:10

Bash reads group of files depending on the invocation of the shell:

  • Login shell: Basically a shell that it is attached to a tty and comes from an authentication process. This kind of shell reads /etc/profile, ~/.bash_profile, ~/.bash_login and ~/.profile
  • Non login - interactive shell: Interactive shells that opens without an authentication process. This kind of shell reads /etc/bash.bashrc and ~/.bashrc

You can find more information on: man bash , section INVOCATION

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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