Setup a Global User Profile with ‘/etc/profile.d/custom.sh’

It’s fairly common to edit the /home/user/.bash_profile file to setup a custom environment, such as alias and startup applications, for user, but what if you wanted that profile to be the same for all users (including root). The best way is to use a custom script that resides in the /etc/profile.d/ directory. This process is described briefly in /etc/bashrc:

# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# It's NOT good idea to change this file unless you know what you
# are doing. Much better way is to create custom.sh shell script in
# /etc/profile.d/ to make custom changes to environment. This will
# prevent need for merging in future updates.

Here is a quick example for taking advantage of this hook which assigns a simple alias. First, you must setup /etc/profile.d/custom.sh:

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

Second, you must created the contents of /etc/profile.d/custom.sh:


alias ls='ls -lah'

Third, simply log out and then back in again. You’ll notice the changes. You can verify this particular example by using the alias command:

$ alias | tail -n1
alias ls='ls -lah'

Of course, you’ll want to take what you’ve learned above and run with your own script suited to your needs. I hope this has helped you achieve your goal of creating a universal profile for all users on the system.

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:

There's 2 Comments So Far

Share your thoughts, leave a comment!