Linux Basic Administration Concepts

Introduction

Linux is a multi-user system, allowing many users on the same machine at once. Due to security considerations, normal users are limited to manipulating only their personal files. Sometimes, however, it is needed to administer the system, to install software or perform maintenance tasks. To perform these tasks, a linux system has a special user account called root.

Using the root account could be very dangerous. One short command might wipe out your entire hard drive without warning. Therefore, you must observe extreme caution while working as root, avoiding root as much as possible.

Finally, remember what sets off the hitch-hickers guide to the galaxy from the encyclopedia Galactica: It has, written on its top, the phrase: Don't Panic!

So, where do you start?

To switch to the root account, open a console and type su(short for "Switch User" or "Super User"). You are now required to type the root password which you have set during system installation.

[alon@localhost alon]$ su
Password:
[root@localhost alon]#

Notice the hash sign (#) which usually signifies root mode.

Installing Software

In the linux world software comes in three main formats:

RPM - RedHat Packaging Manager

Most modern distributions are based on RPM packages. In an RPM-based system, it is preferred to install software via RPM, if available. Note, however, that the package you are installing should match your distribution. To find packages for your distribution, use rpmfind.net which lets you search for packages based on package name, or a file included in the package. If you are a RedHat user, you might also want to look at http://atrpms.physik.fu-berlin.de/ or http://dag.wieers.com/home-made/apt/ - two RPM repositories managed to make your life, as a user, easier.

The RPM system is designed to make software work correctly by the use of dependencies. RPM automatically detects and reports conflicts, asking you to download and install additional packages to satisfy package dependencies.

To install a package, issue the command rpm -Uvh packagename.rpm, for example:

[root@localhost alon]# rpm -Uvh foobar-1.0-3mdk.i586.rpm
Preparing... ########################################### [100%]
1:foobar ########################################### [100%]
[root@localhost alon]#

On a Mandrake system, you can check and satisfy dependencies by using urpmi - the Mandrake package tool. To install, simply type urpmi packagename, for example:

[root@localhost alon]# urpmi locales-ru
Please insert the medium named "disc 1 Download Edition Installation CD (x86)
(cdrom1)" on device [/dev/scsi/host0/bus0/target0/lun0/cd]
Press Enter when it's done...
installing /mnt/cdrom/Mandrake/RPMS/locales-ru-2.3.1.2-8mdk.i586.rpm
Preparing... ##################################################
locales-ru ##################################################
[root@localhost alon]#

To uninstall, use rpm -e packagename. For example:

[root@localhost alon]# rpm -e locales-ru
[root@localhost alon]#

Installing from Source Code

Some software is available only as source code, and sometimes use of source code is preferred. The source is usually in C or C++, compressed in an archive. In Linux, two compressors are commonly used: gzip and bzip2, and the files are combined together using tar. To open a tar.gz or tgz archive, use the command: "tar -xzvf file.tar.gz". To open a tar.bz2 archive, use "tar -xjvf file.tar.bz2".

The archive will usually include a directory by the same name. In this directory you will usually find a README file, read it! There might also be an INSTALL file, read it too. Take a look at other files with capitalized names as well.

Note: not all tar files are properly built - they might create files without creating a directory first. To be on the safe side, make a habbit of opening tar files in a new, empty directory. You can always move the files later on to a different directory.

Most of these programs are based on a system called autoconf, which simplifies the compilation of Linux software. To install an autoconf-based program, do the following (as a normal user):

[alon@localhost foobar-1.0]$ ./configure
(... lots of output ...)
[alon@localhost foobar-1.0]$ make
(... lots of output ...)
[alon@localhost foobar-1.0]$ su
Password:
[root@localhost foobar-1.0]# make install
(... lots of output ...)
[root@localhost foobar-1.0]# exit
[alon@localhost foobar-1.0]$

Using "Apt"

As you see, the major drawback of the rpm utility, is that it only points out dependency problems, rather then solving them.

The apt utility, originally built for a different packaging system, handles dependencies automatically (or semi-automatically), similar to the way the urpmi utility works on Mandrake. For a RedHat system, you may download apt from Dag Wieers' web site. Install this package using the rpm command (as seen earlier).

Once you have apt installed, you need to ask it to update the local list (= cache) of packages it can install, using the following command:

[root@localhost alon]# apt-get update

To install a new program named "xsane" on your system (assuming you found the package's name, via one of the earlier web sites):

[root@localhost alon]# apt-get install xsane

To search for a program, in the cache of apt, using a keyword such as "image":

[root@localhost alon]# apt-cache search image

If you want to have a GUI to make using apt easier, take a look at synaptic. You may download a version for RedHat from the atrpms site.

System Directory Structure

The UNIX directory tree is structured based on the type of use of the files. A typical UNIX setup includes the following directories under the root directory (/):

Directory Contents
/bin
Essential executables, used by all users
/boot
Files needed to start the system, including the kernel
/dev
Interfaces to system hardware (devices)
/etc
Configuration files of all software and the system itself
/home
Users' home directories, which include personal files
/lib
Essential libraries and kernel modules (drivers)
/mnt
Mount-points of foreign (non-Linux) file-systems (see below)
/opt
Optional files and programs (usually empty)
/proc
Interface to the kernel and running processes
/root
Home directory of the root user
/sbin
Essential system executables for use mostly by root
/tmp
Temporary files, writable by all users
/usr
All non-essential programs and program data
/var
Variable system files, such as logs, mail, and print jobs

/usr

The /usr directory is again structured based on use, as follows:

Directory Contents
/usr/bin
Executables of installed software
/usr/doc
Documentation, see also /usr/share/doc
/usr/games
Executables of games
/usr/include
C/C++ header files for installed libraries
/usr/lib
Installed libraries and other application files
/usr/local
Locally installed software (from source, not rpm)
/usr/man
Manual pages for the man command
/usr/sbin
Executables of installed system software for use mostly by root
/usr/share
Shared program data, such as graphics and documentation
/usr/src
Sources. Usually includes the source of the kernel.
/usr/X11R6
Files related to the X Windowing system (GUI)

Handling file-systems and mounts

In UNIX, as opposed to windows, there is only one directory tree, starting from the root directory (/). The root directory is mapped (or mounted) to some disk partition. Other partitions may be mounted instead of any existing directory in the file-system. Mounts may be used to separate system directories to different disks, or to access foreign (Windows, floppy, CDROM, ...) file-systems. Foreign file-systems are usually mounted under /mnt.

The default mount locations of partitions are defined in a file called /etc/fstab (file-system table). The file looks like this:

/dev/hda8  /           reiserfs notail                        1 1
none /dev/pts devpts mode=0620 0 0
none /dev/shm tmpfs defaults 0 0
/dev/cdrom /mnt/cdrom auto user,umask=0,exec,ro,noauto 0 0
/dev/fd0 /mnt/floppy auto user,umask=0,sync,exec,noauto 0 0
/dev/hda1 /mnt/win_c vfat defaults 0 0
/dev/hda5 /mnt/win_d vfat defaults 0 0
none /proc proc defaults 0 0
none /tmp tmpfs defaults 0 0
/dev/hda6 /usr ext3 defaults 1 2
/dev/hda7 swap swap defaults 0 0

The first column is the device (or partition) to mount, or none for special file-systems. /dev/hda is the first physical hard-disk, and the number is the partition number. To find out your partition list and manipulate partitions use cfdisk or fdisk as root. WARNING: fdisk is a dangerous command and should be used with extreme caution.

The second column is the mount point, the location in the directory tree where the mounted file-system starts. swap is a partition used for virtual memory.

The third column is the file-system type, or auto which results in auto-detection.

The fourth column is for mount options. For more information on these options and the meaning of the next columns see the man pages for mount andfstab.

Manually mounting file-systems

In Linux, you can manipulate file-system mounts in runtime. This is useful for mounting removable storage such as CDROM and floppy. Note that you must unmount a file-system before ejecting the removable media, or data loss will occur.

The current status of mounts is kept in /etc/mtab and /proc/mounts, and can be seen by running mount with no parameters. The format of these files is similar to /etc/fstab.

To mount a file-system in /etc/fstab type (as root): mount mountpoint. To unmount, type umount mountpoint. For example to access the CD-ROM:

[root@localhost alon]# mount  /mnt/cdrom  # Mount the CD-ROM and lock the drive
[root@localhost alon]# ls /mnt/cdrom # List files on CD-ROM
Mandrake/
[root@localhost alon]# umount /mnt/cdrom # Unmount CD-ROM (drive unlocked)
[root@localhost alon]# eject /mnt/cdrom # Open CD-ROM tray

Note: Various graphical desktop systems will automatically mount CDROM disks you insert into the CD-ROM drive, for your convenience.

Permissions and ownership

In UNIX, every file must be owned by some user and by some group. This is usually the user id and group id of the user who created the file. The user who owns the file can change the file's permissions, specifying what other users can do with the file.

File permissions and ownership information can be viewed using ls -l(long). The output looks as follows:

-rwxr-xr-x    1 root     root       579384 Feb 25  2002 /bin/bash
-r-------- 1 root root 1594 Aug 25 23:09 /etc/shadow
drwxr-xr-x 18 root root 4096 Sep 1 14:41 /usr
drwx--x--x 212 alon alon 28816 Sep 19 00:47 /home/alon/

The first column is the file permissions(details below). The third and fourth columns list the user and group the file belongs to.

The first letter in the permissions specifies the type of the file: "-" is a regular file, "d" is a directory. The next three letters specify read(r) write(w) and execute(x) permissions of the file's owner. The next three letters are for users in the file's group, and the last three of for the rest of the users on the system. Note that the execute permission for directories actually means the permission to enter the directory and its subdirectories.

Permissions can be changed using the chmod command. Ownership can be changed by root only using the chown command. The default permissions for new files are set using the umask command. See the man pages of these commands for details.

Configuration tools

Many distributions include graphical tools to assist in common administration tasks. Here is a list of a few:

Common commands

Below is a list of useful UNIX commands and what they do, so you can read their manual pages:

Command Usage
cd
Change directory
pwd
Print working directory
ls
Show directory contents
cp
Copy file or directory
mv
Move file or directory
rm
Delete file or directory
mkdir
Make directory
rmdir
Remove directory
grep
Find files containing some text or textual pattern
ps
Show running processes (programs)
top
Show CPU usage interactively
kill
Terminate running process
df
Show free/used disk space
du
Show disk usage of specified directory
which
Locate programs via path
locate
Find stuff on the hard-disk

How to Get Help

Sometimes you want to do something and don't know how. What should you do now?

How to ask questions

Linux pros are usually happy to help beginners. However, the pros will not be able to answer your question and might be mad at you, unless you follow the following guidelines:

Originally written by Valid HTML 4.01!Alon Altman