Tips and Tricks For Hardworking Admins

From custom remote login prompts to smarter network time management: Our tip collection has something for everyone.

 By Carla Schroder
Page 1 of 2
Print Article

Today you get a hearty serving of some of my favorite tips and tricks, painstakingly accumulated and carefully squirreled away for a special occasion. Autumn is here, which is always special, so here they are.

Colorizing Remote BASH Prompt
When you get a bunch of remote SSH sessions going it's easy to lose track of where you really are, because all you see are boring old generic prompts. Sure, they show the hostnames, but it's still easy to get confused. Which can be a bit amusing when you issue a reboot command to the wrong computer, or send a cranky broadcast message to all users on the wrong system. An easy way to keep track is to colorize and customize the Bash prompt on your remote systems, so you can easily differentiate them from your local login. You can assign different colors and text for different machines and accounts. For example, you can make the prompt turn green and display the text "THIS IS AN SSH SESSION" by adding these lines to ~/.bashrc of your remote account:

if [ -n "$SSH_CLIENT" ]; then text=" THIS IS AN SSH SESSION"
export PS1='[e[0;32m]u@h:w${text}$e[m] '

So when you log into to your remote machine, you see something like this displayed in green:

carla@windbag:~ THIS IS AN SSH SESSION$

This works by testing for the presence of the SSH_CLIENT environment variable; if it exists, the customized prompt is displayed. Only the prompt is colored, all other text remains its normal color. You can easily test the color and text instantly by running the export PS1='[e[0;32m]u@h:w${text}$e[m] ' command, then open a new terminal. The new terminal will show the new prompt.

You can easily modify this by changing the color code and the text. The color code in this example is 0;32. The backslashes are all escapes; to find out what everything means in this example visit the BASH Prompt Howto.

Running a Local Timeserver the Easy Way
Keeping your LAN hosts synchronized is very important, and easy. It's more important for them to be synchronized to each other than to have the correct time, but there's no reason you can't have both. The old-fashioned way is to select several individual public timeservers and enter them in /etc/ntp.conf. However, this approach has several problems. Timeservers tend to suffer considerable abuse from inconsiderate users, so they get taken offline. And your only redundancy is whatever active servers you have hunted down and entered in your configuration file. The old-fashioned way has long been deprecated in favor of using pool.ntp.org. This is a DNS round-robin that selects random servers from a large pool of participating servers. Simply make your /etc/ntp.conf look like this:

driftfile /etc/ntp.drift
logfile /var/log/ntp.log

server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org

Then use this machine as your local timeserver, and point your other LAN hosts to it:

driftfile /etc/ntp.drift
logfile /var/log/ntp.log

#use hostname or IP for your local timeserver
server localtimeserver.carla.com
fudge stratum 10

The "fudge" factor means the ntp daemon will continue to calculate the time on the PC even when it is disconnected from the timeserver, based on past performance.

You might consider letting your server join pool.ntp.org. It won't get clobbered with a lot of traffic, and you'll make a useful contribution. See www.pool.ntp.org/join for details.

Rotating Message of the Day
When users log in they first see the contents of /etc/issue displayed with the login prompt:

 _     _ _                          _
| |   (_) |__  _ __ __ _ _ __   ___| |_
| |   | | '_ | '__/ _` | '_  / _  __|
| |___| | |_) | | | (_| | | | |  __/ |_
|_____|_|_.__/|_|  __,_|_| |_|___|__|

Libranet GNU/Linux 3.0 i686 windbag ttys1
windbag login:
Then after logging in they see the Message of the Day as specified in /etc/motd:

Linux windbag 2.6.11-ln.std #1 Sun Apr 10 18:27:05 PDT 2005 i686 GNU/Linux

Libranet GNU/Linux

That's pretty dull. You can jazz it up by editing /etc/motd. Some admins like to do elaborate ASCII art (see the Figlet program to create these), some display helpful messages with information about new servers, policies, downtimes, and such. To push out new /etc/motd messages to multiple hosts use cfengine.

This article was originally published on Sep 28, 2005
Get the Latest Scoop with Networking Update Newsletter