NTP Configuration on RedHat

Make sure its installed and enabled:
yum install ntp
chkconfig ntpd on
/etc/init.d/ntpd start

Config can be done in /etc/ntp.conf such adding local time servers:
server mytimeserver.com

You can instantly update the time from the timeserver by running:
ntpdate pool.ntp.org
ntpd -qg

If you get an error like:
5 Mar 14:09:24 ntpdate[19228]: the NTP socket is in use, exiting
It’s because you can’t manually sync the time with the ntpd service is running. Stop the service and try again.

Postfix queue administration

Although I’ve used many MTA’s before, I’m new to postfix so here’s a few handy commands to note:

List the mail queue:
postqueue -p

Delete a single message:
postsuper -d 4C63F2300BA

Find broken symlinks

Quick tip to find broken symlinks in the filesystem:

find -L . -type l

Convert SSH2 keys to OpenSSH

Convert SSH2 key to OpenSSH format:
ssh-keygen -i -f id_dsa_1024_a.pub > id_dsa_1024_a_openssh.pub

Or to convert an OpenSSH key to SSH2:
ssh-keygen -e -f id_dsa.pub > id_dsa_ssh2.pub

Useful Linux find examples

The Linux/Unix find command can be used to do a lot more than find strings. Here’s a few very handy commands I’ve put together over the years:

Recursively chmod files and folders to something sensible:
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;

Find files over a certain size:
find . -type f -size +100000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'

Debian / Ubuntu package Management

You can search for a package by packagename or a word within the package description:
apt-cache search apache2
apt-cache search "Apache "

You can also search by a file that is within the package:
apt-file search apache2.conf

Show package information:
apt-cache show apache2
apt-cache showpkg apache2

List files in a package:
apt-file list apache2 | less

Linux hardware clock

You can use hwclock to synchronise the system clock with the hardware clock:

–show read hardware clock and print result
–set set the rtc to the time given with –date
–hctosys set the system time from the hardware clock
–systohc set the hardware clock to the current system time

Check RAM type without opening server

You can use dmidecode in Linux to check various hardware specs such as CPU / memory without having to physically open or power down the server. For example to see the RAM needed:

dmidecode --type memory

SMBIOS 2.5 present.

Ping an entire network / netblock

You can use fping to ping a netblock to see which hosts are alive:

fping -g

You could also put ping into a loop, but the output is less than useful:

for i in {1..254}; do ping -c1 192.168.1.$i; done

nmap is also a handy solution and can provide much more host information if needed:

nmap -sP

nmap and fping should both be available as packages for your distro.

Basic AWK usage in BASH

To print a field from a file (-F is the field separator and $ is the number of the field to print):

awk -F':' '{ print $1 }' /etc/passwd or
awk -F':' '{ print $1 $3 }' /etc/passwd or
awk -F':' '{ print "username: " $1 "\t\tuid:" $3" }' /etc/passwd