How can I set a single .bashrc file for several users?

during my work I need to constantly add alias commands to bashrc, most of those commands needs to be runed by other users. is there any way I could add alias commands to a bashrc from external source?


Many config files in users home directory just override/add to ones in the /etc - for example the settings for GIMP in the users home are in ~/.gimp-2.*, which adds to the system-wide config /etc/gimp/2.0.

So for ~/.bashrc, you could edit the system wide config files /etc/bash.bashrc (for functions/aliases) or /etc/profile (for environment stuff) - you can the full list from man bash:

FILES
       /bin/bash
              The bash executable
       /etc/profile
              The systemwide initialization file, executed for login shells
       /etc/bash.bash_logout
              The systemwide login shell cleanup file, executed when a login shell exits
       ~/.bash_profile
              The personal initialization file, executed for login shells
       ~/.bashrc
              The individual per-interactive-shell startup file
       ~/.bash_logout
              The individual login shell cleanup file, executed when a login shell exits
       ~/.inputrc
              Individual readline initialization file

This warning is given for a few Linux systems in the files:

# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.

So you could edit those files, you may want to back them up first (cp /etc/bash.bashrc /etc/bash.bashrc-backup for example), or create a shell script in /etc/profile.d - for example you can create one with these commands (with sudo/as root):

touch /etc/profile.d/custom.sh
chmod +x /etc/profile.d/custom.sh

Then open it with nano /etc/profile.d/custom.sh

#!/bin/sh
alias ls='ls -lah'

And check whether it works by seeing if it appears in the output of alias - Note that you may need to logout/login or reboot to see any changes (if you don't want to, running source /etc/profile after any changes might work)


Go to /etc/bash.bashrc

vim /etc/bash.bashrc

and make your alias there.

add your alias in last line.

alias abc="whatever"

That alias will become global for all users.

but for security reasons we dont recommend you that.

there is profile.d directory which contains user-environment files

go to

cd /etc/profile.d/

vim aliases

and add your aliases here.

without effecting your system files. It is safe and right way to work with your environment files.


There's already an accepted answer here, but you might consider using some form of environment modules to handle system-wide configuration of user environments rather than messing with the files in /etc/profile.d, etc. This is especially true if you want to manage this control in one place across lots of shells. Lmod (under very active development), C/TCL modules (the classic solution), or Cmod (lightweight).


Don't know if I'm doing it right, but it works for me to keep a /home/ComunAtodos directory (capitalized and in spanish to make evident that it is not a linux native directory) and put .bashrc, .nanorc and .bash_aliases there. Then I reference those in /etc/skel/.profile so new users point to them, and only add extras to specific users that need them.