Page 1 of 1

Customizing You Linux Login Rate Topic: -----

#1 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5365
  • View blog
  • Posts: 27,328
  • Joined: 10-May 07

Post icon  Posted 05 July 2007 - 10:32 AM

Customizing You Linux Login

Why?
There are many reasons why someone would want to customize their Linux session. The reasons for this include:
1. Prompt
You may want to make your prompt different in appearance based on which ID you are logged in. You will also want to change from the default look, & there are unlimited options available for you to use.
2. Environment (variables, libraries, & other situations)
Some hardware may need libraries loaded in order to use the software. You may also take this time to load environment aliases & other customized variables to assist you with your day to day functionality.
3. Background Jobs
At login, you can take advantage of launching processes into the background, so once you get the command prompt, you can expect that your background processes (or daemon) is running.
4. Hardware customization
As in reason #2, you may have some configuration differences for hardware between different users. This would be the ideal time to launch any libraries or configuration variables as needed by the hardware.
5. Xwindows (preparing & starting)
You can even create some session variables specific to Xwindows. You may also want Xwindows to launch as soon as you’ve logged in. Both of these can be handled by your startup scripts.

Bash Shell: The Bourne Again Shell.
References :
Small guide to shell scripting:
http://tldp.org/LDP/abs/html/
Bash Guide for Beginners:
http://tldp.org/LDP/...sect_03_01.html

The bash shell checks for a set of files in a specific order. Knowing this order is important so that you can understand when they load & why some of your information may not be available. The following is a list of the startup files in the order they are searched for. If a file is not found, there is no error message, the shell simply skips to the next file.
Start-up order:
/etc/profile - This holds the ‘default’ values. So if you want a specific behavior for every user on the system, rather than put it in each users’ .profile file, you can place those actions here.

~/.bash_profile - Login shells. An important fact about this file is that this script is always read, even on new terminal launches or window opens. So in this file you don’t want to launch any background processes that you just want to run once. If you are running Xwindows & open a new terminal window, the background processes will launch again.

~/.bash_login – Login initialization. This file executes once a user is logged onto the system.

~/.profile - login if no .bash_profile is present. In the absence of ~/.bash_profile & ~/.bash_login, this file is read. It can hold the same configurations, which are then also accessible by other shells (for example SH or KSH). This file holds user specific functions similar to the global /etc/profile script.

~/.bashrc - Interactive non-login shells. These shells exist for automatic (sometimes remote) events.

$ENV - Linux by default sets many environment variables for you. You can modify the values of these variables. A few of the variables that are set are:
HOME : The users home directory
PATH : This sets the path that the shell would be looking at when it has to execute any program or reference a file.
PS1 : This is the users’ Shell Prompt.
SHELL : This variable defines the user’s default shell.
LOGNAME : The LOGNAME is automatically set for you, & is the same value as your login name. A situation where you would use this variable is in case you want to reference your login name in a script.

Upon termination:
~/.bash_logout - login shells.
Others:
~/.inputrc - Readline initialization.

The rc directories
These run prior to being prompted to login. The last one to run will be rc.local, this general runs just after setting up the general purpose mouse device. One main difference between the rc files & what we are talking about here, the rc files run with permissions, so you can setup hardware level configurations.

Examples:
(setting up common keystroke charactors)
stty erase ^H
stty intr ^C
stty kill ^X 


(Prompt)
$PS1 $PS2 prompts:
PS1='\u@\h:\w> ' 


no2pencil@linux:/tmp>

Adding the \A to display the time, we end up with something that looks like this:

10:09 no2pencil@linux:/tmp>

PS1 values: Meaning
\u Username
\h Hostname
\H The fully-qualified hostname
\w Current working directory
\d date
\t The current time in 24 hour HH:MM:SS format
\T The current time in 12 hour HH:MM:SS format
\@ The current time in 12 hour am/pm format
\A The current time in 24 hour HH:MM format
\| The basename of the shell’s terminal drive
\e Escape character
\n newline
\r carriage return

PS1='\e[31m\A\e[0m \u@\h:\w> ' 


Which then looks like this:
10:09 no2pencil@linux:/tmp>

Environment (variables, libraries, & other situations)
umask 027	# Create files with group, other permissions  turned off.

ulimit -c 0	# Prevent a crashed program from creating a "core" file.

PATH=$HOME/bin:$PATH:/usr/sbin:/sbin:/usr/local/sbin
CDPATH=":$HOME:$HOME/man:$HOME/bin"
MANPATH="$HOME/man:$MANPATH"

alias ls=’ls –color’
alias ll=’ls –l’
alias la=’ls –a’
EDITOR=vi
export EDITOR



(Execute once logged in)
w; cal`date +”%m”` `date +”%Y”`


(Background Jobs)
background_proc &


(Xwindows)
startx




Other
Q: What if I can’t see my .profile or other files?
A: Try using ls –a. The dot is a generic way of hiding the files from users without super user privileges.

Is This A Good Question/Topic? 1
  • +

Replies To: Customizing You Linux Login

#2 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 180
  • View blog
  • Posts: 2,641
  • Joined: 30-December 07

Posted 08 January 2009 - 06:52 PM

My ZSH prompt (~/.zshrc).

HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=10000
setopt appendhistory autocd extendedglob nomatch notify
zstyle :compinstall filename '/home/tom/.zshrc'
autoload -Uz compinit
compinit

# Custom colors, borrowed from
# <http://aperiodic.net/phil/prompt/>
autoload colors zsh/terminfo
if [[ "$terminfo[colors]" -ge 8 ]]; then
	colors
fi
for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; 
do
	eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
	eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
	(( count = $count + 1 ))
done
PR_NO_COLOUR="%{$terminfo[sgr0]%}"

# Custom prompt
function precmd () 
{
	if [ $TERM = "xterm" ];
	then
	print -Pn "\e]0;%n@%m (%~)\a"
	print
	fi
}

function preexec ()
{
	print ""
}

# Custom shell
export PROMPT="$PR_BLUE$PR_MAGENTA%n@%m$PR_BLUE%% $PR_NO_COLOUR"
export RPROMPT="$PR_BLUE($PR_MAGENTA%~% $PR_BLUE)\
$PR_NO_COLOUR $PR_BLUE\
$PR_GREEN%D{%I:%M %P}$PR_BLUE\
$PR_NO_COLOUR"

# Print out a fortune :-)
echo "\n$PR_YELLOW\b\b\b\b$(fortune)"



Prompt looks like this:
Attached Image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1