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

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

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

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts