0

I extended the bashrc file of my linux user. This file contains extra aliases, functions, whatever is useful. It's synchronized with a playbook across our 100+ servers.

When i'm working on linux I often escale to the sudo user. this is frustrating bc when I escalate to this user I lose my bashrc settings. Is there any way to keep these when I change to sudo.

Addendum:

  1. Also we work with multiple linux users. With each there own bashrc.
  2. I there is any way to source it. It needs to be done automatically. Or are there better alternatives?

OS: redhat

  • Just add the source command to the .bashrc of root? – Gerald Schneider May 04 '23 at 09:48
  • 1
    *"I often escale to the sudo user"* - note that there is no such thing as a `THE sudo user` ; the `sudo`command allows to execute a command is any other user and the default user is root. – HBruijn May 04 '23 at 09:48

2 Answers2

1

Your problem is one of the many reasons I have stopped customising my personal environments on any and all of the (customer) servers that I manage. When you become frustrated and crippled when they're not consistently available such customisations lose their benefits IMHO.

Two different approaches to combat that:

  • combine all your teams shell profile customisations, aliases and functions and make them available to all users by publishing them in for example /etc/profile.d/

That has the benefit that you can create uniform work instructions and standardise approaches and avoids the situation where several versions of your_useful_shell_function exist in different peoples ~/.bashrc that don't get updated when you discover and fix a bug / edge case / incompatibility.

To continue relying on customisations from your personal environment consider to:

  • Set up an appropriate alias/function in your personal profile and train yourself to use that instead of sudo -i -u root. That alias or function can then run sudo -u root /bin/bash --rcfile ~ansible_usah/.bashrc a and ensure that your personal bash RC file gets used instead of the default one for root. (or load a different personal bash rc-file that includes a subset/superset from the your customisations in your default ~/.bashrc)
HBruijn
  • 77,029
  • 24
  • 135
  • 201
0

Does your .bashrc source another, system-wide, shared file? Say /etc/bash.bashrc?
If so, consider putting your definitions there and everybody will get them.

If you only want a smaller number of users to have these settings, then create your own "shared" file and source that from the .bashrc of each user.

Phill W.
  • 1,479
  • 7
  • 7