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?

Asked By: user309584


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:

              The bash executable
              The systemwide initialization file, executed for login shells
              The systemwide login shell cleanup file, executed when a login shell exits
              The personal initialization file, executed for login shells
              The individual per-interactive-shell startup file
              The individual login shell cleanup file, executed when a login shell exits
              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 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/
chmod +x /etc/profile.d/

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

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)

Answered By: Wilf

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.

Answered By: Dishank Jindal

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).

Answered By: Bill Barth

I’m really new to Linux operativ system, but i did a sketch of a bash script that works to modify all the users .bashrc file and not the system file /etc/.bashrc file.


X=$( cat etc/passwd | cut -f1 -d: ) #All-users

For X in /home/*/.bashrc ; do 

echo "alias ls='ls -al'" >> $X



source $X

exit 0

Okay so i know that that script works, but i don’t if it’s fault free 🙂
Also u can modify it so it doesn’t involves all the users, maybe u make a file for all the users that need their .bashrc file customized.

Answered By: Farhad Rahimi

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.

Answered By: Fik of the borg
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.