Ubuntu Set User Profile Under Bash Shell

How do I set user profile under bash shell running Ubuntu Linux operating systems?

You need to edit the following files to set profile for users.


Systemwide Profile For All Users

/etc/profile: You need to update /etc/profile which is systemwide initialization profile file. All changes made to this file applies to all users on the system.

/etc/bash.bashrc : The systemwide per-interactive-shell startup file. This file is called from /etc/profile. Edit this file and set settings such as JAVA PATH, CLASSPATH and so on.

How Do I Edit Systemwide Profile Files?

Use the text editor such as vi:
sudo vi /etc/profile

Profile For Individual Users

Use the following shell startup files to customize each user profile. The following files are located in users $HOME directory such as /home/vivek.

  1. $HOME/.bash_profile – The personal initialization file, executed for login shells. Add PATH settings and other user specific variables to this file.
  2. $HOME/.bashrc – The individual per-interactive-shell startup file. Add user specific aliases and functions to this file.
  3. $HOME/.bash_logout – The individual login shell cleanup file, executed when a login shell exits.

You can edit above files with the following command:
vi ~/.bashrc
vi $HOME/.bash_profile

Sample $HOME/.bash_profile

# shell path
export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
export PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin
export EDITOR=vim
export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre

# load ssg keys
/usr/bin/keychain $HOME/.ssh/id_dsa
source $HOME/.keychain/$HOSTNAME-sh

# turn on directory spelling typos
shopt -s cdspell

Sample $HOME/.bashrc

# shell functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias vi='vim'
alias grep='grep --color'
alias update='sudo apt-get update && sudo apt-get upgrade'
alias dnstop='dnstop -l 5  eth1'
alias vnstat='vnstat -i eth1'
alias bc='bc -l'

genpasswd() {
	local l=$1
       	[ "$l" == "" ] && l=16
      	tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs

	local o=$IFS
	IFS=$(echo -en "\n\b")
	/usr/bin/beep-media-player "$(cat  $@)" &

Recommended readings:

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

4 comments… add one
  • David Bowskill Jul 15, 2012 @ 7:17

    Very helpful info – would like to receive more – Thanks

  • Carlos Jul 12, 2014 @ 13:11


    I have a doubt:

    Why does the article recommends to set the user specific path and variables in .bash_profile file, and not in .bash_rc?. Why does the article recommend to set the functions and aliases in .bash_rc and not in .bash_profile file?


  • Gustavo Piva Nov 9, 2014 @ 14:01

    Thank you for this notes. I’m finding for this information a few days.

  • satish Jan 5, 2017 @ 5:39

    what is the use of /etc/. and /profile/ configuration file?

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.