Score:0

Use original linux user bashrc also as root user

ae flag

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

in flag
Just add the source command to the .bashrc of root?
HBruijn avatar
in flag
*"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.
Score:1
in flag

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)
Score:0
cn flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.