Home|Cudeso|Linux|*NIX / BSD|Misc|
 

Tweaky User- & Sysadmin

This page is a summary of hints and tricks that I have used to configure my GNU/Linux-machines. Some of these may be useful, some may not, some could screw up your machine!

System administration

1. View last 30 lines of the messages

2. Split a file into seperate files

3. Opposite of pattern matching

4. Create a random-password

5. Tune the performance of a process

6. Make a file immutable

7. Remove files on a daily basis

8. Speed up your harddisk

9. Check your system for rootkits

10. Upload files with ncftpput

11. Add Windows to lilo.conf

12. Check systemperformance

13. Install a new harddrive

14. Redhat 8/9 showing garbage characters

15. Convert filenames uppercase to lowercase

16. Add extra swapfile

17. Turn on DMA with Gentoo

User administration

1. GPG

2. Automatic log-out

3. Change CTRL-ALT-DEL functionality

4. Change bash-prompt

1. View last 30 lines of the messages

I love to keep track of all the entry's that fill up my messages [grin]. In the early days I always issued cat -n 30 /var/log/messages to get the last 30 lines of messages. Because I was tired of entering it over and over I created an alias. For this you need to add the following line to /etc/bashrc
alias tail30="tail -n 30 /var/log/messages"
Now logout and login and you can use tail30 to review your logs.

2. Split a file into seperate files

When you want to backup large files to a floppy you can split a file so that it has the right size.
split -C 1430k backup.tar disk
will divide the file backup.tar into slices of 1.430k . The splitted files get names as disk.aa   disk.ab.

You can concatente all files with
cat disk.* > total.tar

3. Opposite of pattern matching

As you should know, with grep you can filter out text that matches a certain pattern. You can also do the opposite :
grep -v "^#" /etc/inetd.conf
gives you everything that isn't commented out

4. Create a random-password

I find it hard to figure out new password for my users. You can automate this task with<
/usr/bin/mkpasswd -l 9 -d 3 -c 3 -C 3
This will give you a password with length = 9, minimum 3 decimals, 3 lower-case characters and 3 upper-case characters.

5. Tune the performance of a process

To enhance (or decrease) the performance of a process, you can use the renice command :
renice -20 cat /usr/local/squid/logs/squid.pid

6. Make a file immutable

You can make a file immutable (so that it's impossible - even for root - to change it) with :
chattr +i /etc/inetd.conf
To reset the immutable bit use :
chattr -i /etc/inetd.conf

7. Remove files on a daily basis

You can remove files on a daily basis. I use this feature for the files that I backup to an archive-directory. Without control, this directory would grow out of size after a while. I remove all files that are older than 4 days. You can easily do this with :
for i in `find /home/archive/ -mtime +3`; do (rm $i); done

8. Speed up your harddisk

There's a way in which you can speed up the performance of your harddisk. But please...be cautious because this could really screw up your machine and could result in a loss of data (as I experienced!). Before you start, reboot your machine in single-user-mode!!

The tool to use is : hdparm. First of all, you can review the default performance with
hdparm -tT /dev/hda/
Now, set 32-bit I/0 support on together with multi-read :
hdparm -c3 -m16 /dev/hda
Check the results again with hdparm -tT /dev/dha

Next, set unmaskriq and use dma on
hdparm -u1 -d1 /dev/hda
Again, check the results. The last speed-up thing could be to use another DMA-mode. For further details, please refer to the man-page.
hdparm -X34 -d1 -u1 /dev/hda
In stead of X34, you could also use : X66.

When you want to save these settings, edit the file /etc/sysconfig/harddisk and change the appropriate value.

9. Check your system for rootkits

Allthough running GNU/Linux prevents you from being infected with the latest vbs-virus, there are some nasty bugs out there. By using chkrootkit you can check your system for rootkits. Download the script from http://www.chkrootkit.org/, untar the file and compile it (with make sense). For the upmost security, run this script from a secured host through a cron-job.

10. Upload files with ncftpput

You can easily upload files to a ftp-server with a cronjob with ncftpput. Allthough you can make use of ncftpbatch, I love the ncftpput. For example :
ncftpput -u myuploaduser -p verysecret -V -DD ftp.cudeso.be . /var/backup/home.tar.gz
-u is your username on the ftpserver and -p is the corresponding password.
-V means no output (because we're running from cron. -DD deletes the local file when the upload was succesful. Next we find the remote-hostname, the remote-path and the local file.

11. Add Windows to lilo.conf

other = /dev/hda1 label=win

12. Check systemperformance

You can check wether your system is under heavy-load or not; or wether it's just running out of swap with :
vmstat 5 60
This will print out 60 times with a delay of 5 seconds the current load.

13. Install a new harddrive

Off course, first attach the drive to the IDE-device. Then partition it with fdisk.
Now you need to build a file-system on it. Do this with
mke2fs -j /dev/hdXX
Before you can use the new drive, you need to mount it. Do this with
mount -t ext3
If you want to use it permanetly, put the right configuration in /etc/fstab

14. Redhat 8/9 showing garbage characters

Redhat 8 and 9 install UTF-8 as the default character encoding. This gives you a problem when you try to remotely use an application that uses ncurses (for example 'setup'). You can solve this problem by disable the file i18n.
mv /etc/sysconfig/i18n /etc/sysconfig/i18n.orig
Just reboot and try to login again.

15. Convert filenames uppercase to lowercase

This script gives you the possibility to convert a whole directory with files to files with names in lowercase.
for file in `ls -1`; do
   lfile=$(echo $file | tr [A-Z] [a-z])
   mv -r ${file} ${lfile}
done

16. Add extra swapfile

When you're running out of swap space, you can add some more while the system is running. This does not have to be a seperate partition; it can also be a file.
cd /var/tmp
dd if=/dev/zero of=extra-swap bs=1024 count=1048576
/sbin/mkswap -c -v1 /var/tmp/extra-swap
/sbin/swapon /var/tmp/extra-swap
more /proc/swaps
If you want to make this change permanent (after a reboot) : Open /etc/rc.d/rc.sysinit and look for swapon -a. Then append this line
swapon /var/tmp/extra-swap
It should look something like this: action "Activating swap partitions" swapon -a swapon /var/tmp/extra-swap

17. Turn on DMA with Gentoo

When I installed Gentoo Linux from the CD I had the impression that my hard-disk performance was very low. In fact, when I checked the HD-settings with hdparm, it turned out that dma-mode was turned off. When I tried to turn it on I received this error
 root # hdparm -d1 /dev/hda

/dev/hda:
 setting using_dma to 1 (on)
 HDIO_SET_DMA failed: Operation not permitted
 using_dma    =  0 (off)
A bit of fiddling arouned learned me that the IDE-driver that was loaded was the 'generic' driver. When you look in the kernel-configuration under 'IDE...' you will find several possible extra drivers. To find out which one you need, take a look at the output of cat /proc/pci. Chances are big that you are using
IDE interface: VIA Technologies, Inc. VT82C586A
Just mark the vt82cxxxx IDE driver, recompile your kernel and give it a try!



1. GPG

A quick way to generate a key is : gpg --gen-key.

If you want to export the key use : gpg --armor --export johndoe@mydomain.com > mykey.key

Import a key with : gpg --import redhat2.key (the key for redhat is on http://www.redhat.com/about/contact/

List all the keys in the database : gpg --list-keys

Verify packages with rpm -K filename

2. Automatic log-out

When you have the bad habit of not logging out after you've finished, you can GNU/Linux do it for you. Edit the file /etc/profile and add a line :
TMOUT=3600
This will logout the user after 1 hour of inactivity.

3. Change CTRL-ALT-DEL functionality

Do you hate it when you're working with both Windows NT and GNU/Linux and you're always mistaken with the CTRL-ALT-DEL-combination?

It's possible to change the default behavior. Edit the file /etc/inittab

Look for the line containing :
ca::ctrlaltdel:/sbin/shutdown -h -t 4 now
At least this line is in my config...in the original config there can be a line with -r (reboot). Just change it to whatever functionality you want, for example :
ca::ctrlaltdel:/bin/echo "You pressed CTRL-ALT-DEL"
Don't forget to reboot because 'inittab' is only read from the boot-cycle.

4. Change bash-prompt

Edit the file ~/.bash_profile and put something like this in it :
#!/bin/sh
 PS1='\u@\h (\w))$ '
 export PS1
This will give you something as : Charly@verybighost (~/html/mycss/)$

You will find more on information on the settings that can be used at Bash Reference Manual
Copyleft 2002-2007 - cudeso.bewebmaster@cudeso.betop