8

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?

intrixius
  • 195
  • 1
  • 1
  • 5

4 Answers4

20

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.

user9517
  • 115,471
  • 20
  • 215
  • 297
1

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.

1

As none of the previous, it seemd that the user didn't have a shell assigned, so it just show the character $ as prompt.
I had to assign a shell to the user by running the command:

sudo usermod --shell /bin/bash username

After that, the user automatically logged in with a bash shell.

Evhz
  • 115
  • 6
0

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