Why and How To Customize a UNIX / Linux User Account?

Q. Can you tell more about UNIX user account customization along with some sample configuration?

A. Usually useradd / adduser and passwd commands are used for creating an entry for a user in /etc/passwd, /etc/shadow and /etc/group files. However, adding user in files may not provide all the functionality needed. You need to set user customization by modifying various scripts located at /etc or ~/ (user home directory). These scripts executed at the start of every console (text based) login or ssh session to setup the user’s environment.

Typical UNIX / Linux login scenario

User login / SSH Login
         |
         |
System login script /etc/profile
         |
         |
Personal login script $HOME/.profile
         |
         |
Shell startup script $HOME/.bash_profile $HOME/.shrc 
         |
         |
User logged in (login complete)

You can add system wide customization using /etc/profile file. End users can manage their own profile / custom environment using personal login script or shell startup script.

Why customize a UNIX / Linux / BSD user account?

Following are few common examples:

  1. Set the JDK / JVM / PATH variables
  2. Set the user’s terminal type
  3. Customize the user’s prompt
  4. Set a default text editor
  5. Setup historyfile size and location
  6. Run reports as soon as you log into account etc
  7. Set a command line shortcuts and aliases

Sample Customization

$ cat ~/.bash_profile
Output:
export TERM=xterm # my terminal type
export PS1="$ " # my sweet prompt
export JAVA_HOME=/opt/jvm/java-6-sun #for java
export PATH=$PATH:$JAVA_HOME/bin:/home/vivek/bin # my binary file search path
export EDITOR=vim # my editor
export HISTSIZE=100 # history file size
export HISTFILE=~/.cmd_history # history file location
umask 077 # my umask
ulimit -c 0 # unlimited core file
# some shell variables
set -o noclobber
set -o physical
shopt -s cdspell
shopt -s extglob
shopt -s dotglob
shopt -s cmdhist
shopt -s lithist
shopt -s progcomp
shopt -s checkhash
shopt -s histreedit
shopt -s promptvars
shopt -s cdable_vars
shopt -s checkwinsize
shopt -s hostcomplete
shopt -s expand_aliases
shopt -s interactive_comments
bind '"\C-t": possible-completions' # replaces 'transpose-chars'
bind '"\M-t": menu-complete' # replaces 'transpose-words'

View environment variables list

Simply user env command, enter:
$ env

/etc/skel directory to push configuration to user

By default all files from /etc/skel are copied to the new user’s home directory; when a new user account created. There are few files included in /etc/skel/ by default.

  • /etc/skel/.bash_logout
  • /etc/skel/.bashrc
  • /etc/skel/.profile
  • /etc/skel/.cshrc
  • /etc/skel/.exrc (/etc/skel/.vimrc)

You can also create or copy existing scripts in /etc/skel. For example copy /usr/share/vim/vimrc to /etc/skel/.vimrc
# cp /usr/share/vim/vimrc /etc/skel/.vimrc
Now file /etc/skel/.vimrc will be copied when a new user account created.

Suggested readings:

  • man pages bash, csh, ksh, sh

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Craig Wayman Feb 4, 2008 @ 13:43

    Hi,

    The last few sentences talk of /etc/.vimrc and they should be /etc/skel/.vimrc

    Cheers,
    Craig.

  • 🐧 nixCraft Feb 4, 2008 @ 14:00

    Craig,

    Thanks for the heads up.

  • clusteradmin.blogspot.com Feb 8, 2008 @ 11:52

    To customize adding/deleting users even more but still use the built-in tools, adduser/deluser can be used.
    It has config files and custom scripts that can be run automatically when a user is added/deleted:

    /etc/adduser.conf
    /etc/deluser.conf
    /usr/local/sbin/adduser.local
    /usr/local/sbin/deluser.local

    HTH.

  • Earle Joseph Feb 26, 2008 @ 12:00

    Your answers are crips but explicit. They are very educational and helpful

  • minakshi Aug 24, 2011 @ 7:01

    proper definition of customize enviornment

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum