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:
- Set the JDK / JVM / PATH variables
- Set the user’s terminal type
- Customize the user’s prompt
- Set a default text editor
- Setup historyfile size and location
- Run reports as soon as you log into account etc
- Set a command line shortcuts and aliases
$ 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:
/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/.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.
- man pages bash, csh, ksh, sh