1

I have an infrastructure that mostly consists of Ubuntu machines and many users. We like to use X2GO for remote access, which works well. We now have an AlmaLinux 8.8 machine. When login onto that one with X2GO and opening a terminal, the prompt is messed up and only writes something like bash-4.4$ . We figured out that this is because opening a terminal in X2GO is not a login shell (sorry, not so sure anymore, see edit) and thus the /etc/bashrc is not sourced by the /etc/profile. The Ubuntu system is somehow configured to work without a local .bashrc in the user's home directory. Thus, all home dirs are created without a .bashrc.

I want to fix that on the AlmaLinux machine by always sourcing the /etc/bashrc. This is because I do not have access to the mechanism that creates new homes for new users, and I do not want to create/tell all users to have a local .bashrc. Is there a way to realize that? I do have sudo rights on the Alma machine.

[Edit] After checking again, I noticed this block in the /etc/profile:

if [ -n "${BASH_VERSION-}" ] ; then
        if [ -f /etc/bashrc ] ; then
                # Bash login shells run only /etc/profile
                # Bash non-login shells run only /etc/bashrc
                # Check for double sourcing is done in /etc/bashrc.
                . /etc/bashrc
       fi
fi
5
  • Can you edit the /etc/profile on the relevant machines? If you can just add . /etc/bashrc as an additional line in /etc/profile. But why not just add what you need from /etc/bashrc to /etc/profile? Commented Nov 14, 2023 at 9:08
  • @Uberhumus: OP says their issue is that a non-login shell is being started – and non-login shells do not load /etc/profile, which seemingly is the very problem here. Commented Nov 14, 2023 at 9:15
  • @u1686_grawity, I suspect one of us is reading it wrong. "We figured out the that is because opening a terminal in X2GO is not a login shell and thus the /etc/bashrc is not sourced by the /etc/profile" hints that /etc/profile is loaded. He specifically asks: "I would like to fix that on the AlmaLinux machine by always sourcing the /etc/bashrc.". Am I missing something? Commented Nov 14, 2023 at 9:19
  • Can you edit /etc/profile? That requires root access. If you have root access, you also have write access to /etc/skel/ so you can set up new users with .bashrc if you want to. Commented Nov 14, 2023 at 9:40
  • I have root access to the machines. Home directories are created by the IT central service and therefore I have no control over the home creation process. Commented Nov 14, 2023 at 10:07

1 Answer 1

1

Your explanation is a bit off. Login shells do read the profile family of files, but they don't read the bashrc ones; it's non-login shells that don't read profile but do read bashrc. As for Ubuntu, yes, it may be set up to not have local .bashrc, presumably by not having one at /etc/skel. You could add a default file there which should then be copied for all new users.

As for having your login shells read bashrc, I would personally suggest having the settings you need in /etc/profile instead, but if you don't want that, you can make /etc/profile source /etc/bash.bashrc. Just add this to your /etc/profile:

if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
  if [ -f /etc/bash.bashrc ]; then
    . /etc/bash.bashrc
  fi
fi

This will source /etc/bash.bashrc if the shell reading /etc/profile is bash and is not bash as /bin/sh (bash in POSIX mode). A few Linux distributions do this by default, as far as I know only those in the Debian family, but maybe others as well. Note that this assumes your /etc/bash.bashrc has code to exit if the shell is not interactive. On my Arch, this looks like:

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

If you don't have a similar line in your /etc/bash.bashrc, add one so that you do not read it for non-interactive shells where you realy don't want the settings in bashrc to be active.

8
  • I have added the proposed code to /etc/profile but it does not fix the problem. Most likey due to the edit I put in the question. Sorry for putting the situation wrongly. Commented Nov 14, 2023 at 10:23
  • @SimonT. but that means you are reading /etc/bash.bashrc from login shells. But if you are opening a GUI terminal, that isn't a login shell, no. However, that should read /etc/bash.bashrc by default as well. But what is this /etc/bashrc file you mention? That isn't standard, the standard file is /etc/bash.bashrc. Is that a typo? Also, if you have root access, why don't you just create a default /etc/skel/.bashrc file so that all new users have the setup you want? Commented Nov 14, 2023 at 10:46
  • On AlmaLinux I don't see a /etc/bash.bashrc I only have the /etc/bashrc. No bash. before. The homes are created on a NFS, and I guess for new user they will be initialized by the first machine they log into. This can now be either a Ubuntu or this single AlmaLinux machine. I would have to force the users to log in to the Alma machine first, right? That may sound picky, but that is also not a preferred solution for me. Commented Nov 14, 2023 at 11:00
  • No, I get that. But you can just create an /etc/skel/.bashrc file on each machine, and then any new accounts will have that file copied to their $HOME no matter where they log in. As for the rest, is the /etc/bashrc the file you want then? Does it have the settings you expect? Commented Nov 14, 2023 at 11:05
  • Ok, let me understand. Is the skeleton checked every time? So when I place a .bashrc there, it will be copied to every user's home that logs in and misses that file? I will try that. Yes the /etc/bashrcdoes the correct thing. I tested by having a local .bashrc in my home that sources the /etc one. Commented Nov 14, 2023 at 11:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.