Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 17 down vote accepted

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)

share|improve this answer
thank you!, I used your method and it worked perfectly... – user309584 Jul 27 '14 at 7:17
Plenty of good suggestions there. I think there is one other option, which would be worth mentioning as well. One can edit /etc/skel/.bashrc to change what the contents of ~/.bashrc will look like for newly created users. – kasperd Jul 27 '14 at 15:08
@kasperd - nice idea (you could do a answer on it if you want) – Wilf Jul 27 '14 at 15:12
In my experience, ~/.bash_logout and /etc/bash.bash_logout do not work. :( – Paddy Landau Jul 29 '14 at 13:56

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.