Introduction to Linux and SUSE Linux
Introduction to Linux and SUSE Linux
UNIX/Linux OS Introduction
Linux is the core, or kernel, of a free operating system first developed and released to the world by
Linus Benedict Torvalds in 1991. Torvalds, then a graduate student at the University of Helsinki,
Finland, and now a engineer with the CPU design company Transmeta, Inc., fortuitously chose to
distribute Linux under a free software license named the GNU General Public License (GPL).
Using Linux is a good idea for a number of reasons. These reasons include
⚫ There is little or no cost on a “per seat” basis. Unlike commercial operating systems Linux has
no royalty or licensing fees, and a single Linux distribution on CD-ROM (DVD) can form the
basis of an enterprise wide software distribution, replete with applications and productivity
software.
⚫ Linux, in conjunction with its graphical interface, the X Window System, has worked well.
The fact that UNIX is ready for the consumer desktop is now confirmed with the introduction
of Apple Computer’s BSD UNIX-based MacOS X.
⚫ Linux is fast, stable, scalable, and robust. Latest version of the Linux kernel easily supports
multiple-processor computers (optimized for eight CPUs).
⚫ Linux provides a royalty free development platform for cross-platform development. Because
of the Open Source development model and availability of free high-quality development
tools, Linux provides a low-cost entry point to budding developers and tech industry startups.
⚫ Big-player support in the computer hardware industry from such titans as IBM now lends
credibility to Linux as a viable platform. IBM has pledged to enable Linux on the company’s
entire line of computers, from low-end laptops through “Big Iron” mainframes. New corporate
customers are lining up and using Linux as part of enterprise-level computing solutions.
1.1.1. Disadvantages of Linux
⚫ There are far too many different distributions (but similarities in the different
distributions)
⚫ Linux is not very user friendly and confusing for beginners Is an Open Source
product trustworthy?
SUSE (poperly pronounced /zuzə/, but typically pronounced /suzi/) is a major retail Linux
distribution and is produced in Germany, but is now currently owned by Novell, Inc.
Page 1 / 121
History
SUSE Linux was originally based on Slackware Linux; In mid-1992, Softlanding Linux System
(SLS) was founded by Peter McDonald, which was the first comprehensive distribution to contain
elements such as X and TCP/IP. The Slackware distribution (maintained by Patrick Volkerding)
was initially based in large parts on SLS.
S.u.S.E was founded in late 1992 as a UNIX consulting group, which among other things regularly
released software packages that included SLS and Slackware, and printed UNIX/Linux manuals.
They released the first CD version of SLS/Slackware in 1994, under the name S.u.S.E Linux 1.0.
It later integrated with the Jurix distribution of Florian La Roche (also based on Slackware), to
release the first really unique S.u.S.E Linux 4.2 in 1996.
The name "S.u.S.E.", later shortened to just "SUSE", was originally an acronym for the German
phrase "Software- und System-Entwicklung" ("Software and system development"). The company
is now simply called SUSE LINUX, and "SUSE" does not officially stand for anything any more.
On November 4, 2003, Novell announced it would acquire SUSE Linux (Shankland, 2003). The
acquisition was expected to be finalized in January 2004 (Kennedy, 2003). According to Ramesh
(2004), J. Philips (Novell's corporate technology strategist for the Asia Pacific region) stated that
Novell would not "in the medium term" alter the way in which SUSE continues to be developed.
At Novell's annual BrainShare gathering
(http://www.novell.com/brainshare/) in 2004, all computers ran SUSE Linux for the first time. At
this gathering it was also announced that the proprietary SUSE administration program YaST2 (Yet
another Setup Tool) would be released into the public under the GPL license.
Proper preparation and planning before considering a SUSE Linux installation can pay big
dividends later on. After choosing to deploy Linux, it is time to take a hard look at how to deploy
the new operation system.
Page 2 / 121
⚫ Hardware Requirement
SUSE Linux can be installed on a wide variety of hardware. This includes legacy platforms up to
the latest workstations, rack-mounted systems, and multi-processor servers available from the
entire tier of computer hardware vendors. Small, medium-sized, and even largescale deployments
of SUSE Linux are available through a number of companies such as IBM, which offers hardware,
software and service solutions (with more than 200 software solutions for clustering application
alone). It is always a good idea to check for compatibility and extensively explore options before
on boards with a specific vendor.
⚫ Partitioning
Partitioning your hard drive for Linux can be done during installation. Partitioning your hard drive
to accept Linux requires some forethought. At the very least, Linux requires a native Linux partition
and a swap partition. The SUSE Linux installer can automatically create and use a partition scheme
if Linux will be the only resident operation system.
The simplest partitioning scheme would be a single Linux native root partition and swap partition.
A single-drive system with 10GB storage and 128MB RAM, the scheme might look like this:
However, on a system that is being designed for expansion, greater capacity, or the capability to
host additional software or users, additional partitions can be used to host various parts of the Linux
file system. Some candidates that should be separate partitions or even file systems include
P
age 3 / 121Lecturer EZE Herbert O.
/var Placing this directory (or perhaps some of its subdirectories) on a separate
partition can be a good idea, especially because security logs, mail, and print
spooling takes place under this tree.
/media Mount point for removable media. Previously this directory was /mnt, but
the Filesystem Hierarchy Standard (FHS) version 2.3 has announced the new
file system hierarchy on 29 Jan 2004, and SUSE has adopted it.
/srv Data directory for www and ftp servers. This is also according to the FHS
2.3
/etc Configuration files will be stored in this directory. This directory should be
back upped.
Swap Swap space is not a directory but it is a necessary partition. Traditionally the
swap partition is assigned a double amount of its memory size.
Though many factors exist to determine how well a computer system will perform, the hardware
occupies large part. Old and less hardware generally slow down the system. The hardware for a
Linux system deeply determines how it will perform.
Hardware elements
Page 4 / 121
Hardware can be divided into some elements in terms of panning:- 1. CPU
type
2. RAM size
3. Type, IRQ, I/O address, DMA, motherboard, PCI/AGP, external peripherals.
4. Suitability
5. Compatibility – Is your part of hardware supported by the version of Linux that you are
installing?
Provided that the system load remains not high, the minimal acceptable hardware by intended usage
is as listed on Table 3, otherwise they may be insufficient if the system load becomes unusually
high.
1
PXE allows your client computers to boot and install a Linux distribution over the network, without the
need of burning Linux iso images onto a CD/DVD, boot floppy images, etc.
P
age 5 / 121Lecturer EZE Herbert O.
1.4.2. Specialised Hardware
There are other items that system administrator should consider in planning a highperformance
system.
Multi-threading is the process of cloning processes to split load within a programmes into separate
processes that can be routed to routed to separate processors in an SMP system. If the system is
always busy CPU load, it is likely to reduce the load by introducing SMP system. On the other
hand, if the system is slow on account of slow disk drive, and CPU load is not very high, SMP
model may not be benefited.
(2) RAID
RAID (Redundant Array of Independent Disks, originally redundant array of inexpensive disks is
a storage technology that combines multiple disk drive components into a logical unit. Data are
distributed across the drives in one of several ways called "RAID levels", depending on the level
of redundancy and performance required.
Disk I/O could be a bottleneck for Linux computer system that requires high performance in that
Disk access is measured in millisecond, on the other hand, RAM in nanosecond. You may consider
installing RAID in terms of fault tolerance, and fast disk access. RAID is Redundant Array of
Independent Drives (or Disks), also known as Redundant Array of Inexpensive Drives (or Disks).
There are several different levels of RAID. Linux supports RAID 0, RAID 1, and RAID 5.
⚫ RAID0: Disk stripping. It is intended to improve disk access performance, not fault tolerance.
Data is stripped across multiple disks (from 2 to 32 disks), and is simultaneously read from
multiple drives.
① Disk stripping
② Good for creating large logical disk
③ Faster performance than single hard disk
④ If one disk fails all data is lost
⑤ All disk have to be identical
⚫ RAID1: Disk mirroring & duplexing. This is intended to improve fault tolerance, and not
performance. The same data is stored in two disks. Writing data tends to be slow as two copies
must be written. Raid 1 requires at least 2 disk drives. If one dist fail entire data is safe.
Page 6 / 121
Server A A
B = B
C C
D D
Mirroring
Figure 3 – RAID2
RAID5: In addition to the data stripping, the parity bits are also splits over all disks in the array.
RAID 5 array can withstands a single disk failure. Writing speed is slow as single write
operation requires old data, and parity to be read from each disk, the new parity to be
calculated, and new data and parity to be written to each disk in the array. However, reading is
quite fast in that data is read from striping across multiple disks. Raid 5 requires at least 3 disk
drives.
Parity
generation
Server
A0 B0 C0 0 Parity
A1 B1 1 Parity D0
A2 2 Parity C2 D1
3 Parity B3 C3 D2
Figure 4 – RAID5
2
.5.1. Installation method
Though there are some differences among distributions the installation method in slightly different
among Linux distributions offer some kind of installation methods to meet majority
P
age 7 / 121Lecturer EZE Herbert O.
1.5.2. Disk layout
For the disk layout, at least two mount points are necessary.
⚫ The root ( / ) mount point
⚫ The swap mount point
The size of swap point is usually twice as large as that of RAM.
You can create more mount points. To do so, create disk partitions, locate a directory in them. The
next example shows that a HDD divided into several partitions.
srv1:~ # df
Filesystem 1K-blocks Used Available Use% Mounted on
devtmpfs 1016456 0 1016456 0% /dev tmpfs
1024088 0 1024088 0% /dev/shm tmpfs
1024088 2428 1021660 1% /run
tmpfs 1024088 0 1024088 0% /sys/fs/cgroup
/dev/sda3 24635392 6608648 17749368 28% /
/dev/sda3 24635392 6608648 17749368 28% /var/lib/mailman
/dev/sda3 24635392 6608648 17749368 28% /.snapshots
/dev/sda3 24635392 6608648 17749368 28% /var/log
/dev/sda3 24635392 6608648 17749368 28% /var/tmp
/dev/sda3 24635392 6608648 17749368 28% /var/cache
/dev/sda3 24635392 6608648 17749368 28% /var/spool
/dev/sda3 24635392 6608648 17749368 28% /var/opt
/dev/sda3 24635392 6608648 17749368 28% /var/lib/named
/dev/sda3 24635392 6608648 17749368 28% /boot/grub2/x86_64-efi
/dev/sda3 24635392 6608648 17749368 28% /usr/local
/dev/sda3 24635392 6608648 17749368 28% /tmp
/dev/sda3 24635392 6608648 17749368 28% /var/lib/pgsql
/dev/sda3 24635392 6608648 17749368 28% /var/lib/mariadb
/dev/sda3 24635392 6608648 17749368 28% /var/lib/machines
/dev/sda3 24635392 6608648 17749368 28% /opt
/dev/sda3 24635392 6608648 17749368 28% /var/lib/libvirt/images
/dev/sda3 24635392 6608648 17749368 28% /srv
/dev/sda3 24635392 6608648 17749368 28% /var/crash
/dev/sda3 24635392 6608648 17749368 28% /var/lib/mysql
/dev/sda3 24635392 6608648 17749368 28% /boot/grub2/i386-pc
/dev/sda4 36147976 122408 36025568 1% /home
tmpfs 204820 0 204820 0% /run/user/481
tmpfs 204820 12 204808 1% /run/user/0
Page 8 / 121
Regardless of the installation type (DVD, CDROM, network, etc) a minimal version of a Linux
kernel is used. Once small set of kernel is loaded, it initializes, and performs some hardware checks.
Then the installation starts. The computer must have a valid IP address of itself as well as IP address
of FTP/NFS server address from where the installation files will be loaded.
During the installation process, multiple virtual terminals (VTY) are available:
⚫ Ctl+Alt+F1: Console Terminal
⚫ Ctl+Alt+F2: Shell prompt
⚫ Ctl+Alt+F3: System messages
⚫ Ctl+Alt+F4: Install log
⚫ Ctl+Alt+F7: Install dialogue
P
age 9 / 121Lecturer EZE Herbert O.
Exercise 1 – Installing and using SUSE Linux
⚫ Partition Design1
Design a partition of your newly installing server. The server will be a mail server (smtp,
pop, and imap). There will be 100 users and each user will have a 100MB mail quota.
Software will be at least 4GB under /usr. The server has a 80GB RAID 5 volume and 1GB
memory.
Disk Partition Size
RAID 5 device1 Swap
/var
/usr
/
/home
⚫ Partition Design2
Design a partition of your newly installing server. The server will be a proxy server. The
requirement of proxy cache space is 10GB. The server has two 40 GB SCSI hard disks and
512MB memory.
Disk Partition Size
SCSI 1
⚫ Partition Design3
Design a partition of your newly installing server. The server will be a web and ftp server.
The web and ftp contents will be 1GB. There will be 100 users and Individual user also
will have a 100MB disk quota for mail and web. The server has a 80GB RAID 5 volume
and 1GB memory.
Disk Partition Size
RAID 5 device1
⚫ Partition Design4
Page 10 / 121
Design the partition of your exercise computer. The server will serve as a mail, smtp, imap,
www, and ftp server. Answer how many users the existing computer can handle.
P
age 11 / 121Lecturer EZE Herbert O.
Page 12 / 121
2. Architecture of OS UNIX
Users
Utilities
Shell
Kernel
Hardware
2.1.1. Kernel
The kernel is the core of operating system, presenting a virtual machine interface to user process.
Processes are written without needing any knowledge of what physical hardware is installed on a
computer. Instead the kernel abstracts all hardware into a consistent virtual interface. The kernel
provides low-level services:
⚫ Access to hardware (I/O)
⚫ Memory management Process management
⚫ Inter process management
⚫ Virtual file system switch
P
age 13 / 121Lecturer EZE Herbert O.
User level programmes
Programmes
Inter process
Virtual File system communication Advanced Network
Management Service (socket)
Process
Memory Manager
Schedular
Virtual File system
drivers TCP/IP protocol drivers
Kernel
Hardware
Hardware
2.1.2. Shell
A UNIX shell provides the user interface for the UNIX operating system. Shell runs by the login
process. Shell interprets user commands, executes them and returns to the shell. Shell can be
customized through shell environment variable.
There exist a number of shell registers in /etc/shells, The main difference is the amount of built-in
functionality. You can select one of shells using chsh, or passwd –s command. Environment
variable, “echo $SHELL” shows current shell you are using. Below are well known shell:-
Page 14 / 121
⚫ Bourne-again shell (bash)
This is the default shell on most Linux systems. Written in 1987 by Brian Fox in 1990, it is a pun
on the Bourne shell (sh), which was an early, important UNIX shell. The Bourne shell was the shell
distributed with Version 7 Unix. TENEX C shell (tcsh)
It is based on and compatible with the C shell (csh). It is essentially the C shell with (programmable)
filename completion, command-line editing, and a few other features.
UNIX is multi user operating system. It is necessary to differentiate between the users so as to keep
the file system private, or assign the right permission, and what ever.
Each user is given an account: set of files which is usually stored in the user home directory,
resources, and information belonging to a user.
2.2.1. /etc/passwd
The /etc/passwd file contains user account’s attributes.
⚫ Login name
⚫ Encrypted password
⚫ UID / GID (User ID / Group ID)
⚫ Home directory location
⚫ Default shell
Example:
….
root:x:0:0:root:/root:/bin/sh
…
user1:x:1000:100:User1:/home/user1:/bin/bash
user2:x:1001:100:User2:/home/user2:/bin/bash
The UID of a super user (root account) is 0.
2.2.2. /etc/group
Group information is stored in /etc/group.
⚫ Group name
⚫ Password (rarely used)
⚫ GID (Group ID)
⚫ List of members GECOS (Generic Electric Comprehensive Operating SysteM0
⚫ Home directory location
⚫ Default shell
P
age 15 / 121Lecturer EZE Herbert O.
2.2.3. Dot files
Start-up files begin with a dot is ‘run command’ for short. They are used by various programmes
(command line based and graphical) such as the shell, editors. Global dot files exist under /etc/skel.
Also to establish user specific environment, dot files are located in each user’s home directory. The
below are some typical dot files.
useradd is mostly used command. To create a new user “user1”, simply type,
# useradd user1 –m –g users
The option –m create home directory, and –g option specify the group.
Then, following entry will be added in /etc/passwd. This default value was derived from
/etc/default/useradd.
user1:x:1005:100::/home/user1:/bin/bash
The default values can be overridden by specifying additional values. In the next example, primary
and secondary group, home directory location and default shell are specified.
Most of the hard disks are mounted automatically. When you boot Linux, all Linux partitions
residing on hard disk that are listed in the /etc/fstab file are typically mounted.
To see file system types that are currently available to be used on the system, type,
# cat /proc/filesystems
Table 5 shows the file system types that are supported in Linux.
ext3 Ext file systems are the most common in Linux systems. The ext3 file system
includes journaling features that compared to ext3, improve a file system’s
capability to recover from crashes.
ext2 The default filesystem type for earlier Linux system. Ext2 does not include
journaling features.
msdos An MS-DOS filesystem. You can use this type to mount floppy disks that come
from Microsoft OS
vat Microsoft extended FAT (VFAT) filesystem
reiserfs ReiserFS journaled filesystem. ReiserFS and ext3 are the most common
filesystem types used with Linux today.
swap Used for swap partitions. Swap areas are used to hold data temporarily when
RAM is currently used up.
nfs Network File System (NFS) type of filesystem. NFS is used to mount file
systems on other Linux or UNIX computers.
P
age 17 / 121Lecturer EZE Herbert O.
ntfs Windows NT filesystem. It is supported as a read-only file system. Readwrite
support is available but considered unreliable.
Page 18 / 121
/rc5.d start-up-files for multi X11mode
2.3.2. Pathnames
The file system is presented as a single unified hierarchy that starts at the directory ‘/’ (root), and
continues downward through an arbitrary number of subdirectory. (The single unified hierarchy
differs from that used by Windows. Windows uses disk-specific name space)
Pathname is represented with list of directories, and a file name. Pathname can be absolute (
/var/log/apache2/access_log ), or relative ( apache2/access_log ). Relative pathnames are
interpreted starting at the current directory.
A command entered without path indication will be searched among directories specified in PATH
environment variable.
The list of directories, and file name form ‘pathname’ that must be locate a particular file, together
with its filename, forming a “pathname”
▪ u(user), g(group), o(others), a(all) Octal Binary Perms Octal Binary Perms
▪ +(add), -(remove), =(exact) ▪ 0 000 --- 4 100 r--
r(read), w(write), x(execute) or octal 1 001 --X 5 101 r-X
digit listed right 2 010 -W- 6 110 rW-
3 011 -WX 7 111 rWX
Example:
# chmod 754 Script
This is equal to
# chmod u=rwx,g=rx,o=r Script
This will add group write permission to myDir and all its contents
# chmod –R g+W myDir
P
age 19 / 121Lecturer EZE Herbert O.
chmod 700 myCabinet/
As well as chmod, chown with –R flag changes the settings of a directory, and all the files
underneath.
# chmod 755 ~user1
# chown –R user1:users ~user1
These commands might be used to set up a new user’s home directory.
2.3.5. umask: Default permission umask is a build-in shell internal command that influences the
default permissions of the files when they are created. Specify the permission that you do not allow
in the argument of umask.
# umask 023
This will give a new file with permission ‘rwxr-xr--‘ (754 permission).
Usually it is provided for a suitable default in the shell initial dot file ( .cshrc, or .profile ) with
umask. (777 – 022 = 755)
2.3.6. inode
There are three aspects to a file. It contains data, it has attributes (access permissions, ownership,
etc), and it has one or more names. These three things are stored in different places in the filesystem.
A file’s data is stored within a disk partition. A file’s attributes are stored in a data structure called
an inode (originally short for “intermediate node”). Each file has one inode, which contains,
⚫ The file’s type (regular file? directory? device file? and so on)
⚫ The file’s access permissions, owner, and group
⚫ The file’s timestamps – time of last access, time of last modification, and time of last status
change
⚫ Pointers to where this file’s data blocks are
⚫ A count of the number of links to this inode
Page 20 / 121
You can see inode by ls command with -i option
# ls –i
To mount a CD Drive
# mount –t iso9660 /dev/cdrom /media/cdrom
Or just
# mount /dev/cdrom /media/cdrom
To mount Microsoft Windows Network, as known as, Server Message Block (SMB), Common
Internet File System (CIFS), or Samba server.
# mount -t cifs //192.168.0.2/share /mnt/share -o username=guest,password=guest
P
age 21 / 121Lecturer EZE Herbert O.
/dev/hda1 swap swap defaults 00
/dev/hda2 / ext3 acl,user_xattr 1 1 proc
/proc proc defaults 0 0 sysfs /sys
sysfs noauto 0 0 debugfs /sys/kernel/debug
debugfs noauto 0 0 usbfs /proc/bus/usb
usbfs noauto 0 0 devpts /dev/pts devpts
mode=0620,gid=5 0 0 /tmp/openSUSE.iso /mnt/suse -o
loop defaults 00
192.168.100.2:/srv/ftp/ /mnt/ftp nfs ro 00
//192.168.0.2/share /mnt/smb cifs username=guest,password=guest 0 0
3 The filesystem type of this partition. The keyword auto in this field tells
mount to figure out the filesystem format for itself examining the partition.
4 The mount options for this partition. This is a comma-separated list of
options
5 The fifth field is used by the dump command (a utility for performing
incremental backups of a partition). A 1 in this field indicates that the
filesystem should be included by dump. This tool has largely fallen out of
use and the field has little meaning these days.
6 The sixth field is used by the file consistency check program fsck to
determine the order in which filesystem checks are done at boot time. The
root filesystem should have a value of 1
If you modified the fstab, or some mount point failed due to some network problems for NFS,
CIFS, etc, the following command mounts according to the configuration of fstab.
# mount -a
Using –s option summarize the display only a total for each directory.
# du -sh /usr/*
12M /usr/X11R6
221M /usr/bin
12K /usr/etc
3.1M /usr/games
16K /usr/i586-suse-linux
130M /usr/include
1.5G /usr/lib
47M /usr/local
44M /usr/sbin
1.6G /usr/share
P
age 23 / 121Lecturer EZE Herbert O.
300M /usr/src
0 /usr/tmp
Find file named with a wildcard, it should be enclose the pattern in quotes.
# find /usr/local/src -name '*.c' -print
Find files which is more than 100M file size in or below directory /home
# find /home -size +100M –print
Find files owned by username (or numeric user ID) in or below directory /
# find / -user username –print
A terminal refers to the input/output device attached to a computer. That is a primary devices used
by users to interact with Linux. As for virtual terminal, it refers to multiple independent logical
terminals multiplexed over one physical terminal. Each virtual terminal has its own device file.
Users can access it by pressing CTL+ALT+ F1 to F7. Usually virtual terminal 1 to 6 is textbased
terminals, and virtual terminal 7 is the graphical terminal. Mingetty’s responsibility is to create
and manage a text-based terminal.
In addition to virtual console keystrokes, the Linux console also recognizes the three-fingered
salute Ctrl+Alt+Del. And while using the console, you can also get the screen to scroll. This is
down by using Shift+PageUp or Shift+PageDown..
Page 24 / 121
The Linux console also supports an available pointing device for copy and paste operations. This
support is through the gpm (general purpose mouse server), which must be enabled or started while
booting Linux. To copy a section of text, click and drag text with the left mouse button (button 1)
held down. To paste text, click an insertion point and then press the middle mouse button (button
2).
2.5. X Server
The Linux windowing system uses client/server architecture. The server component is called the X
server. The client components may run on the local machine, or may be remote.
SaX2 edits the main X server configuration file, /etc/X11/xorg.conf. This is a plain text file, but
you really cannot edit it by hand.
You might need to temporary set the default run level to 3, but for the time being, edit the file
/etc/inittab and edit,
id:5:initdefault:
P
age 25 / 121Lecturer EZE Herbert O.
To
id:3:initdefault:
You may prefer to switch to run level 3 temporarily with the command
# init 3
Now you can try starting SaX2 from the text-based login
# sax2
If the X server fails to start, try looking in the log files /var/log/SaX2.log and /var/log/Xorg.0.log
for a clue as to what went wrong. In the Xorg.0.log file, look for lines tagged with the string “EE”.
If SaX2 will not start, use following command. This will attempt to create a configuration file
automatically without bringing up a graphical user interface.
# sax2 -a
This will bring up the user interface in low resolution (800x600) mode.
# sax2 -l
2.6. Process
Page 26 / 121
Table 9 – Process types
Process type Meaning
Terminal A forked process invoked from a shell prompt during login
/shell process session
Batch process A process usually invoked cron. It is not associated with login
session.
Daemon process It is invoked at startup-time by its startup-scripts, and continues
running, httpd, dhcpd, squid, etc
Kernel process
The fork system call creates a copy of the original process. Given a unique PID (Process ID), the
new process (child process) inherits the environment of the original process (parent process), and
keeps parent process’s ID (PPID).
The exec system call creates a new process by overwriting an original process, therefore, PID
remain the same. After a fork, the child process often uses one of the exec system calls to begin
execution of a new programme.
init is one of the processes that the kernel automatically starts at system boot. Having PID 1, init
is responsible for executing the system’s start-up scripts. All processes except processes that the
kernel creates are descendants of init.
Example
# ls
P
age 27 / 121Lecturer EZE Herbert O.
⚫ Shell call fork system call, then creates a child process
⚫ The child process exec ls
⚫ the parent process, the shell wait the end of ls
# exec ls
⚫ shell exec ls command
⚫ shell’s process information is overwritten by ls command’ information. The PIDs of shell and
ls remain the same.
⚫ Therefore, after the end of ls command, shell also finished.
The ps command is used to see which programs are running. In this example, the –a option to show
processes of all users who are associated with the current terminal, and the –u option asks that
usernames be shown, as well as other information such as the time the process started and memory
and CPU usage.
# ps au
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 5102 0.0 0.1 4276 1912 pts/0 Ss+ 20:14 0:00 -bash root
5968 0.0 0.1 4276 1912 pts/1 Ss 20:21 0:00 -bash root 6149
0.0 0.0 2484 856 pts/1 R+ 20:27 0:00 ps au
2.7.1. Overview
Understanding the boot process is vital for system administration. In general, the boot process
undergoes the following procedures:-
a. BIOS loads a boot programme from MBR on the first hard disk
b. The boot programmes loads kernel
c. The kernel initialize hardware and runs diagnostics
d. Then, the kernel forks init
e. init reads /etc/inittab, then launches start-up scripts
a-b)
When a computer is switched on, BIOS stored in ROM starts. BIOS loads a programme contained
in the first 512 bytes of the disk (MBR). This programme loads a secondary boot programme (grub,
or lilo) from a disk. The boot programmes starts from the first partition of the disk by default, but
Linux provides nicer MBR (grub, lilo) so that the computer enables multiple operating system.
After the MBR sets the partition to boot from, MBR loads the boot loader specific to the partition,
then the kernel is loaded.
c)
The boot programme allows the user to pass arguments, such as hardware specific information, root
partition location. Also some other boot programme’s configuration file can be found in
/boot/grub/menu.lst.
Kernel executes the initialization scripts, which check file system, mount local disks, assign
page/swap areas, or clean up pages.
d-e) init switches the default run level, then executes startup-scripts under /etc/init.d. Start-up
scripts are responsible for starting or stopping processes, or service. Startup scripts use
configuration information from files located under /etc/sysconfig directory
P
age 29 / 121Lecturer EZE Herbert O.
2.7.2. GRUB menu / configuration sample
If you want to start as a single user mode (runlevel 1) for emergency or some maintenance, enter
“1” at the [Boot Options] textbox.
2.7.3. Login and Shutdown
After rebooting your PC, you will be able to log in to a Linux session. If X11 was not configured
during the installation, you will log in at a text-based login prompt, If you configured X and enabled
a graphical login, the screen will clear after SUSE Linux boots, and you will be presented with a
graphical login screen.
To login, type root or appropriate username and press Enter, type in the password and press Enter
to start using Linux. If you use a graphical login, you can use the shutdown or reboot menus in the
dialog box to shut down or reboot our system. To shutdown your system from the command line
of a text-based session, use the shutdown command with its –h or halt option and the keyword now
or the numeral 0. You can also use other aliases.
init defines 7 run levels. Each run level represents a distinct system service.
⚫ Level 0: system is shut down
⚫ Level 1: single-user mode
⚫ Level 2: multi-user mode - user can define
⚫ Level 3: multi-user text based login
⚫ Level 4: not-used – user can define
⚫ Level 5: multi-user with xdm
⚫ Level 6: reboot
Single-user mode is usually used for maintenance, like Windows safe mode. It does not supply
network service, does not start any daemon. The main usage for the single-user mode is to root
password recovery in that it does not require root password entry by default for many Linux
distributions except openSUSE.
/etc/inittab defines commands when the system enters each level as well as default run level. In
this case, the system runlevel is 3. You can hand-edit this entry if you wish.
# The default runlevel is defined here id:3:initdefault:
2.8.1. Control Boot-time Service Startup init executes the system startup scripts. They are shell
scripts interpreted by shell (/bin/sh,
/bin/bash, /bin/tcsh, or what ever). Master copies of the startup scripts are under the /etc/init.d
directory. Each script starts, or stops a daemon, or definite feature of the system, recognising start
P
age 31 / 121Lecturer EZE Herbert O.
and stop argument. A run level specific startup script is located under /etc/init.d/rcX.d, where X is
the run level, but it is not a script file, but a symbolic link of which name is preceded a capital S(for
“start”), or K(for “kill”), followed by a number. The number designates the order of start, or stop.
When the system starts, it runs startup scripts that start with S in ascending order with the argument
start. When the system halts, it runs startup scripts that start with K (for “kill”) in descending
numerical order with the argument stop.
You can start the server by three different ways, but the result is the same
# /etc/init.d/squid start
For convenience, openSUSE places symbolic links to these scripts in /usr/sbin
# rcsquid start
Or you can also start as,
# service squid start
Each of scripts at /etc/init.d takes an argument to specify its action; the arguments shown in Table
13 are supported by most scripts
For example, you can use these scripts as shown in this sequence
# /etc/init.d/sshd start
Starting SSH daemon done
# /etc/init.d/sshd status
Checking for service sshd running
# /etc/init.d/sshd stop
Shutting down SSH daemon done
# /etc/init.d/sshd status
Checking for service sshd running
The utility chkconfig can be used to manipulate and interrogate the Slinks and Klinks from the
command line.
Page 32 / 121
Table 14 – Using chkconfig command
Command Description
chkconfig --list Display the settings for all services at all runlevel
chkconfig --list sshd Display the settings for the sshd service
chkconfig sshd on Enable sshd at its default runlevels
chkconfig sshd 5 Enable sshd to start at level 5 only
chkcondig sshd off Disable sshd
chkconfig --del sshd Delete S link and K link of sshd
chkconfig --add sshd Add S link and K link of sshd
You can see the S link and K link arrangement for sshd with a wildcard,
# ls -l /etc/init.d/rc?.d/*sshd lrwxrwxrwx 1 root root 7 Feb 25 22:17
/etc/init.d/rc3.d/K17sshd -> ../sshd lrwxrwxrwx 1 root root 7 Feb 25 22:08
/etc/init.d/rc3.d/S09sshd -> ../sshd lrwxrwxrwx 1 root root 7 Feb 25 22:17
/etc/init.d/rc5.d/K17sshd -> ../sshd lrwxrwxrwx 1 root root 7 Feb 25 22:08
/etc/init.d/rc5.d/S09sshd -> ../sshd
The two digit numbers in the link names are used to control the order in which the scripts are
executed. This is important, because if service A depends on service B.
The each master script at /etc/init.d places within the script a set of comment lines that specify
which run levels this service is supported to run at, and what services it depends on. For example
of /etc/init.d/sshd
### BEGIN INIT INFO
# Provides: sshd
# Required-Start: $network $remote_fs
# Required-Stop: $network $remote_fs
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: Start the sshd daemon
### END INIT INFO
The Default-Start line describes which run levels to enable the service in. It will also look at the
Required-Start and Required-Stop lines to figure out where in the startup and shutdown order the
S links and K links should be placed.
2.9. vi Editor
P
age 33 / 121Lecturer EZE Herbert O.
The vi editor is available on every Unix and Linux system. It works on character terminals, without
a graphical user interface, and it is fast and powerful once you get to know it. Figure 8 shows the
three major modes of vi and shows a few of the command availavle in each mode.
Start
: Newline
Table 15 – vi Commands
Command Description
Movement
h,j,k,l Left, down, up, right
^, $ Start, end of current line
Ctrl+b Scroll backwards one page
Ctrl+f Scroll forwards one page
Ctrl+u Scroll backwards half a window
Ctrl+d Scroll forwards half a window
:n Go to line n
nG Go to line n. If no count is given, the end of the file
Insert Mode
I Insert before cursor
A Insert after cursor
A Append to end of line
I Insert at start of line
O Open a line below current line
O Open a line above current line
Replacing Text
C Change to he end of the line from the current cursor
position
Cw Change the current word
Cc Change the current line
Page 34 / 121
S Change the entire line
R Replace one character
Search
/pattern Search for pattern, forward from current position. Use
backslash “\” for special characters.
N Repeat the search in the forward
N Repeat the search in the backward
:%s/pattern/to_pattern/g Substitute. All occurrences are substituted.
Copy, Delete, Paste
U Undo the last change
Yy “Yank” (copy) the current line into the paste buffer
P Paste the buffer before the current cursor position
X Delete the character under the cursor
Dd Delete the current line (and put it in the paste buffer)
D Delete to end of line
. Repeat the previous change at the new cursor position
Miscellany
ZZ Save the file and exit
:wq Save the file and exit (same as ZZ)
Ctrl+g Show the current filename and the status
:q! Quit the editor, abandoning any changes
:w file Save to the specified file
Linux documentation is spread over a number of sources, some of which are installed on your
system.
⚫ Books
⚫ Distribution specific documents (/usr/local/doc)
⚫ Electronic guides
⚫ HOWTOs: (http://www.tldp.org) – Good starting point
⚫ Manual pages (man pages)
● man pages
Man pages documents are traditional ‘on-line’ documentation. This document is installed in the
directories /usr/share/man/manX, were X is a digit 1 through 9. That is a section. The Linux man
pages are divided into nine sections.
Table 16 – Section of Linux man pages
Section Contents
P
age 35 / 121Lecturer EZE Herbert O.
1 User-level commands and applications
2 System Calls and Kernel error codes
3 Library calls
4 Device drivers and network protocols
5 Standard file format
6 Games and demonstrations
7 Miscellaneous files and documents
8 System administration commands
9 Obscure kernel spec and interfaces
The man pages are normally compressed with gzip to save space. (The man command knows how
to uncompress).
The man command searches a number of different directories to find the manual pages. manpath
command shows the search path. If necessary, you can set MANPATH environment variable to
overwrite default path. You can also set the system-wide default in /etc/manpath.config. man
command with section number shows man page specific to the section, For example,
‘man 5 crontab’ shows how to setup crontab table. On the other hand, ‘man crontab’ ( same as
‘man 1 crontab’) tells you about crontab command. Thus, unless you specify section number, man
searched the topic from section 1, and then shows the result.
‘man –k keyword’’ prints a list of man page that have keyword in their one-line summary.
# man –k memory ( same as ‘apropos memory’ )
PerlIO::scalar (3pm) - in-memory IO, scalar IO pmap
(1) - report memory map of a process vmstat
(8) - Report virtual memory statistics
ipcrm (8) - remove a message queue, semaphore set or shared memory id
Page 36 / 121
Exercise 2 – Linux Administration
1.Create users
Create users on your Linux box
User Name Password Group
trainee1 trainee1 trainees
trainee2 trainee2 trainees
trainee3 trainee3 trainees
P
age 37 / 121Lecturer EZE Herbert O.
3. Basic of using Linux
SUSE Linux supports the use of virtual consoles or terminals. This means that you can log in, run
a program, and then jump to another login prompt, login, and start another session.
To jump to another console while using Linux in text-based mode, login and then press Alt+F2
(you will be using the first virtual console, or vt1 by default). You should then see another login
prompt. Log in, and you are then using vt2, the second Linux console. Jump back and for the
between sessions by using the Alt key plus the F key number of the desired session. The only caveat
when using virtual consoles in that there is a default limit on the available number (usually six) and
there might be one or more active X Window sessions (occupying vt7 by default or vt8).
In addition to virtual console keystrokes, the Linux console also recognize the three-fingered salute
Ctrl+Alt+Del. And while using the console, you can also get the screen to scroll. This is down by
using Shift+PageUp or Shift+PageDown..
The Linux console also supports an available pointing device for copy and paste operations. This
support is through the gpm or general purpose mouse server, which must be enabled or started
while booting Linux. To copy a section of text, click and drag text with the left mouse button (button
1) held down. To paste text, click an insertion point and then press the middle mouse button (button
2).
You can quickly examine the layout of a Linux file system by using the list directory contents
command, ls, like this;
$ ls /
bin dev home media opt root srv tmp var boot etc lib mnt proc
sbin sys usr
In addition to the name of each file, print the file type, permissions, number of hard links, owner
name, group name, size in bytes, and timestamp.
$ ls -l total
3
-rw-r--r-- 1 guest users 8 Aug 4 15:56 file1
-rw-r--r-- 1 guest users 8 Aug 5 15:57 file2
-rw-r--r-- 1 guest users 8 Aug 4 15:57 file3
Page 38 / 121
Sort directory contents by timestamp instead of alphabetically, with the newest files listed first.
$ ls -lt total
3
-rw-r--r-- 1 guest users 8 Aug 5 15:57 file2
-rw-r--r-- 1 guest users 8 Aug 4 15:57 file3
-rw-r--r-- 1 guest users 8 Aug 4 15:56 file1
Use the cd command to navigate through the Linux file system. This command is generally used
with a specific directory location, or pathname like this:
$ cd /usr/X11
The cd command can also be used with several shortcuts. For example to quickly move up a
directory, use the cd command like this:
$ cd ..
To return one’s home directory from anywhere in the Linux file system, use the cd command like
this:
$ cd
$ ls file1 file2
file3
$ cp file1 file4
$ ls
file1 file2 file3 file4
$ ls
file1 file2 file3 file4
$ mv file4 file5
$ ls
file1 file2 file3 file5
$ ls file1
file2
$ rm file2 $ ls
file1
$ rm –fr /tmp/testdir
$ ls file1
$ mkdir directory
$ ls -lt total
2
drwxr-xr-x 2 guest users 1024 Aug 5 11:40 directory/
-rw-r--r-- 1 guest users 8 Aug 4 16:04 file1
cat filename
Outputs contents of filename to display
Page 40 / 121
$ cat file1
101 3people 2-DK
102 none 1-room
201 2people 2-DK
202 4people 3-LDK
less filename
$ less /etc/services
$ cat file2
301 4people 4-DK
302 3people 3-LDK
401 none 2-DK
402 2people 2-DK
$ grep LDK *
file1:202 4people 3-LDK file2:302
3people 3-LDK
This is an introduction to vi, a text editor that is available on almost all Unix machines. This is what
you use to create a file or to change the contents of a file.
To start up vi, use the command 'vi filename', where filename is the name of the file that you want
to change. If you want to create a new file, you can just say 'vi newfilename', where newfilename
is the name that you want to give the file.
The tricky part about vi is that it has two modes, insert mode and command mode. When you are
in insert mode, all you can do is type text, which will go directly into the file wherever your cursor
P
age 41 / 121Lecturer EZE Herbert O.
is. When you are in command mode, you can do everything else, including moving the cursor,
searching, and setting options.
To move from insert mode to command mode, use the [ESC] key. If you forget to do this and end
up with a ':wq' or something else that you don't want at the end of your line, just backspace over
the characters that you don't want, then hit [ESC]. If you hit [ESC] when you are already in
command mode, the terminal will beep at you, but it won't do anything to your file. When in doubt,
hit [ESC].
To move from command mode to insert mode, use the i, a, o, or O command as described below.
There are a few others, but those are the most common.
Cursor Movement:
A handy thing about these commands is that you can type a number first, and the editor will do
the command that many times. For instance, h moves the cursor one character to the left, and
12h moves the cursor twelve characters to the left. You shouldn't see the number or command
that you type, by the way. If you do, you are in insert mode; you should backspace over the
number and press the [ESC] key, then try again.
w - moves cursor one word forward, with punctuation and braces as new words W
- moves cursor forward to the next word
b - moves cursor one word backward, with punctuation and braces as new words
B - moves cursor backward to the next word
Page 42 / 121
/pattern - searches for pattern and moves the cursor there
?pattern - searches backwards for pattern and moves the cursor there
Deleting Text:
d followed by a cursor movement command deletes that much text. For instance, w moves the
cursor forward a word, and dw deletes to the end of the word. The 5h command moves the cursor
five characters to the left, and the d5h command deletes five characters to the left.
Inserting Text:
These commands may seem a little confusing at first. The i command means that everything you
type until you hit [ESC] will be inserted to the left of the cursor. In other words, this command
leaves you in insert mode with the insertion point to the left of where the cursor was when you hit
'i.'
i - inserts text to the left of the cursor (leaves you in insert mode) a - appends
text to the right of the cursor (leaves you in insert mode) A - appends text at the
end of the line (leaves you in insert mode) o - opens new line under the line the
cursor is on (leaves you in insert mode) O - opens new line above the line the
cursor is on (leaves you in insert mode)
The root, or superuser account is a special account and user on UNIX and Linux systems. When
logged in as root, you have total control over your system. This includes the ability to destroy a
P
age 43 / 121Lecturer EZE Herbert O.
running system. Linux comes with a command named su that allows you to rune as root and then
return you to normal user status. You can recognize whether normal or root user by prompt, as $
normal or # root.
$ su – root Password:
#
The only time you should run Linux as the superuser is when booting to run level 1, or system
maintenance mode. This is most often done for filesystem or system configuration repair and
maintenance. Logging in and using Linux as the root operator is not good idea, and defeats the
entire concept of file permissions, discussed next.
3.13. Permissions
Under Linux operating system, everything in the file system, including directories and devices, is
a file. And every file has a set of permissions. These permissions from the basis for security under
Linux and consist of a series of fields designating read, write, and execute permission assigned to
every file. You can examine the permissions for a particular file (if you have read access) by using
the ls command’s long-format listing like this:
$ touch file
$ ls –l file
-rw-r--r-- 1 user1 users 0 2004-11-03 17:29 file
In this example, the touch command is used to quickly create a file. The ls command then reports
on the file showing permissions, owner, group, size, and create (or modification) date. Under Linux,
permissions are grouped by owner, group and others, with read, write, and execute permission
assigned to each, like so:
These permissions can also be represented by base 8, or octal values, with read permission=4, write
permission=2, and execute permission=1. In the previous example for the file named file, the
owner, user1, has read and write permission, as does any member of the group named users. All
other users may only read the file. In octal notation, the file has a permission setting of 664
(read+write, read+write, read-only).
Directories are also files under Linux. For example, again use the ls command to show permissions
like this:
Page 44 / 121
$ mkdir foo
$ ls –ld foo
drwxr-xr-x 2 user1 users 48 2004-11-03 17:36 foo
In this example, the mkdir command is used to create a directory. The ls command and its –ld option
is used to show the permissions and other information about the directory. Here you can see that
the directory has permission values of 775 (read+write+execute, read+write+execute,
read+execute).
The chmod command is used alter a file’s permissions, and uses various forms of command syntax,
such as octal or a mnemonic form (such as u,g,o, or a and rwx, and so on) to specify a desired
change. Although either form can be used, octal is easy to use quickly after you visualize and
understand how permissions are numbered.
For example, to modify a file’s permissions so that only you, the owner, can read and write, the use
chmod command a file permission of 600, like this:
$ chmod 600
P
age 45 / 121Lecturer EZE Herbert O.
3.14. Managing Services
The default entry, or initdefault line /etc/inittab determines what system state to boot SUSE Linux
to. For example,
Id:3:initdefault:
In this example, SUSE Linux will be booted to a full multiuser with network mode.
As the master control file for system startup, /etc/inittab and its corresponding system of symbolic
link used to control system services can be managed by various graphical and nongraphic
administrative tools. SUSE Linux graphical tool YaST can be used to control the action of a service
at a particular runlevel.
SUSE Linux also offers a manual configuration of boot services. Use the chkconfig command to
display, diagnose, or change the starting or stopping of system services (as available under
/etc/rc.d/init.d) in each runlevel. For example, to list all services that will be turned on in runlevel
3, you can pipe the output of chkconfig through the frep command like this:
# chkconfig -list | grep '5:on'
alsasound 0:off 1:off 2:on 3:on 4:off 5:on 6:off coldplug 0:off
1:on 2:on 3:on 4:off 5:on 6:off cron 0:off 1:off 2:on 3:on
4:off 5:on 6:off cups 0:off 1:off 2:on 3:on 4:off 5:on 6:off
fbset 0:off 1:on 2:on 3:on 4:off 5:on 6:off hotplug 0:off
1:on 2:on 3:on 4:off 5:on 6:off hwscan 0:off 1:off 2:on 3:on
4:off 5:on 6:off isdn 0:off 1:off 2:on 3:on 4:off 5:on 6:off kbd
0:off 1:on 2:on 3:on 4:off 5:on 6:off network 0:off 1:off 2:on
3:on 4:off 5:on 6:off nfsboot 0:off 1:off 2:off 3:on 4:off 5:on
6:off nscd 0:off 1:off 2:off 3:on 4:off 5:on 6:off portmap
0:off 1:off 2:off 3:on 4:off 5:on 6:off postfix 0:off 1:off 2:off
Page 46 / 121
3:on 4:off 5:on 6:off powersaved 0:off 1:off 2:on 3:on 4:off 5:on
6:off random 0:off 1:off 2:on 3:on 4:off 5:on 6:off resmgr
0:off 1:off 2:on 3:on 4:off 5:on 6:off smbfs 0:off 1:off 2:off
3:on 4:off 5:on 6:off splash 0:off 1:on 2:on 3:on 4:off 5:on
6:off splash_early 0:off 1:off 2:on 3:on 4:off 5:on 6:off splash_late
0:off 1:off 2:on 3:on 4:off 5:on 6:off sshd 0:off 1:off 2:off
3:on 4:off 5:on 6:off syslog 0:off 1:off 2:on 3:on 4:off 5:on
6:off xdm 0:off 1:off 2:off 3:off 4:off 5:on 6:off xinetd
0:off 1:off 2:off 3:on 4:off 5:on 6:off
The chkconfig command can be used to reassign start or stop values for each runlevel and each
service. However, this feature should only be used cautiously because it is possible to render a
system temporarily unusable. (You can boot Linux to single-user mode to attempt a fix). For
example, to start network time protocol (ntp) (controlled by the xntpd script under /etc/rc.d/init.d/),
use chkconfig like this:
# chkconfig xntpd on
You can then verify this action by again grepping chkconfig’s output like so:
# /etc/rc.d/init.d/xntpd start
Starting
The Red Hat Package Manager (RPM) is used for installing, erasing, upgrading software on SUSE
Linux. You also can use YaST graphical tool for managing packages however the background is
still using RPM.
1. Installing
# rpm -ivh foo-1.0-1.i386.rpm
foo ####################################
P
age 47 / 121Lecturer EZE Herbert O.
2. Do not do a dependency check before installing
# rpm -ivh --nodeps foo-1.0-1.i386.rpm
3. Install the packages even if they replace files from other, already installed, packages.
# rpm -ivh --replacefiles foo-1.0-1.i386.rpm
4. Install the packages even if some of them are already installed on this system
# rpm -ivh --replacepkgs foo-1.0-1.i386.rpm
7. Uninstalling
# rpm -e foo
8. Upgrading
# rpm -Uvh foo-2.0-1.i386.rpm
foo ####################################
9. Freshening
# rpm -Fvh foo-1.2-1.i386.rpm
foo ####################################
RPM's freshen option works for single packages or a group of packages. If you have just
downloaded a large number of different packages, and you only want to upgrade those packages
that are already installed on your system, freshening will do the job. If you use freshening, you will
not have to deleting any unwanted packages from the group that you downloaded before using
RPM.
15. List the package specific scriptlet(s) that are used as part of the installation and uninstallation
processes.
# rpm -q --scripts packagename
# rpm -qp --scripts packagename-1.2.rpm
17. Display the states of files in the package. The state of each file is one of normal, not installed,
or replaced.
# rpm -qs packagename
As a practical matter for reasons of identification and accountability, regular users exist. Each user
has own username, password and permissions that can only be assigned by the superuser. The
ability to run programs and access files can be restricted for regular users, and the access is again
being determined solely by the superuser. All users have a user ID (uid), and a group ID (gid).
1. The su command
You become root and inherit root’s environment
$ su – #
By executing the following, you become that user and inherit the enfironment – a pretty handy tool:
$ su - <some other user>
P
age 49 / 121Lecturer EZE Herbert O.
To return the previous user’s identity, just type
# exit
This takes you to the previous user’s prompt
$
2. Managing groups
The groups are identified in /etc/groups. You can add a new group by groupadd command
# groupadd trainee
Delete group by groupdel command
# groupdel trainee
3. Managing users
Adding new users with the commands adduser and passwd (to change passwords) is simple to do
from the command line, and you can make it even more elaborate to make it do more for you.
Add the user newuser with the password panewuser in users group.
# adduser newuser –g users
Note: SUSE 9.1 does not create the home directory of the new user, so you can make as,
# mkdir /home/newuser
Change the owner of the directory as,
# chown newuser:users –R /home/newuser
To delete a user,
# deluser newuser
Delete the user’s directory and subdirectories if needed
# rm –fr /home/newuser
Page 50 / 121
Configure the network of the Linux
Trainee1 Trainee2 …
IP Address (Internal) 192.168.0.11/24 192.168.0.12/24 …
Host Name t1 t2 …
Domain Name test1.kg test2.kg …
Root user’s password training training …
After the completion of the configuration, test the connectivity by ping command.
Install Software
Install findutils-locate package
Create users
Create users on your Linux box
User Name Password Group
trainee1 trainee1 trainees
trainee2 trainee2 trainees
trainee3 trainee3 trainees
P
age 51 / 121Lecturer EZE Herbert O.
4. Bash
4.1.1. Introduction The shell’s job is to translate the user’s command lines into operating system
instructions. Several layers of events take place whenever you enter a command, but we are going
to consider only the top layer, known as the shell. Figure 9 shows the relationship between user,
shell, and operating system.
Shell
Output UNIX
Operating
Input System
User
Bash is the shell, or command language interpreter, for the GNU operating system. The name is an
acronym for the 'Bourne-Again Shell', the author of the direct ancestor of the current Unix shell
/bin/sh.
Bash is largely compatible with sh and incorporates useful features from the Korn shell ksh and the
C shell csh. It offers functional improvements over sh for both interactive and programming use.
While the GNU operating system provides other shells, Bash is the default shell. It currently runs
on nearly every version of Unix and a few other operating systems - independentlysupported ports
exist for MS-DOS, OS/2, and Windows.
The ? wildcard matches any single characters, so that if your directory contains the files program.c,
program.log, and program.o, then the expression program.? matches program.c and program.o
but not program.log.
The asterisk (*) matches any string of characters. The program.* will match all three files in the
previous paragraph.
Table 18 should help demonstrate how the asterisk works. Assume that you have the files bob,
darlene, dave, ed, frank, and fred in your working directory.
A set is a list of characters (e.g., abc), an inclusive range (e.g., a-z), or some combination of the
two. If you want the dash character to be part of a list, just list it first or last. Table 19 should explain
things more clearly.
P
age 53 / 121Lecturer EZE Herbert O.
In the original wildcard example, program.[co] and program.[a-z] both match program.c and
program.o, but not program.log.
Suppose you are a C programmer, and you want to list all source, object, and header files in your
working directory. The command ls.[cho] matches names end in a period followed by a c, h, or o.
The wildcard examples that we have seen so far are actually part of a more general concept called
pathname expansion. For example, if you wanted to list all of the files in the directories /usr and
/usr2, you could type ls /usr*. If you were only interested in the files beginning with the letter b
and e in these directories, you could type ls /usr*/[be]* to list them.
You can also use a different type of brace expansion nfor creating a sequence of letters or numbers.
$ echo {2..5}
2345
$ echo {d..h} d e f g h
Brace expansion can also be used with wildcard expansions. In the example from the previous
section where we listed the source, object, and header files in the working directory, we could have
used ls *.{c,h,o}.
For example, sort < /etc/passwd will sort the lines in the file, and out onto your terminal (we are
pretending that these utilities do not take filename arguments).
Page 54 / 121
Similarly, command > filename causes the command’s standard output to be redirected to the
named file. The example of this is date > now: the date command prints the current date and time
on the standard output; the previous command saves it in a file called now.
4.1.6. Pipelines
It is possible to redirect the output of a command into the standard input of another command
instead of a file. The construct that does this is called the pipe, notated as |. A command line that
includes two or more commands connected with pipes is called a pipeline.
Pipes are very often used with toe more, or less command. If you are in a directory with a large
number of files and you want to see details about them, ls -l | more, or ls -l | less will give you a
detailed listing a screen at a time.
Here is a more complicated example. The file /etc/passwd stores information about users’ accounts
on a UNIX. The first field of each line is the login name; fields are separated by colons (:). A sample
line might look like this:
linus:x:1000:100:Linus Torvalds:/home/linus:/bin/bash
P
age 55 / 121Lecturer EZE Herbert O.
(Actually, you can omit the <, since cut accept input filename arguments.) The cut command
extracts the first field (-f1), where fields are separated by colons (-d:), from the input. The entire
pipeline will print a list that looks like this:
For example, the file is abc.tar.Z, which is a large compressed archive file. Type uncompress
abc.tar & (you can omit .Z), and the system will start a job in the background.
# updatedb &
[1] 294
and then resulting in very large amounts of output, which will be difficult to stop. However, if you
type
# make &> make.log &
Then the difference will be saved in the file txtdiff for you to examine later.
It is the lowest propriety (19: lowest priority, -20: highest priority, default 10)
$ nice -n 19 make &> make.log &
4.1.11. Quoting
If you want to print the string 2 * 3 > 5 is a valid inequality? If you type:
$ echo 2 * 3 > 5 is a valid inequality.
P
age 57 / 121Lecturer EZE Herbert O.
You would get a new file 5, containing “2 Desktop bin 3 is a valid inequality.”.
4.1.12. Backslash-Escaping
Another way to change the meaning of a character is to precede it with a backslash (\). This is called
backslash-escaping the character. For example,
$ echo 2 \* 3 \> 5 is a valid inequality.
2 * 3 > 5 is a valid inequality.
4.1.14. Aliases
Aliases allow a string to be substituted for a word when it is used. Aliases can be defined on the
command line, in your .bash_profile, or in your .bashrc. If you want to apply the same aliases to
all users in a system, edit (create) /etc/bash.bashrc.local at a SuSE environment. For example,
5. DHCP Server
Page 58 / 121
Dynamic Host Configuration Protocol (DHCP) servers provide network configuration parameters
to machines when they boot. DHCP provides the IP addresses, subnet mask, the broadcast address,
the IP address of the default gateway, the IP address of one or more DNS servers, a domain name
for the client and so on.
DHCP offers a number of conveniences. First, it allows large-scale deployment of desktop systems
by allowing each system to be imaged with an identical configuration. Second, it allows those who
regularly move laptops between networks to automatically pick up appropriate settings for that
network, without tedious manual reconfiguration. Third, it allows reuse of IP addresses through the
reclamation and reissue of expired leases.
DHCP Configuration
There are several configuration examples. You can copy it and modify,
# cp /usr/share/doc/packages/dhcp-doc/examples/simple_dhcpd.conf/
/etc/dhcpd.conf
P
age 59 / 121Lecturer EZE Herbert O.
Start the DHCP server
# /etc/init.d/dhcpd start
Arrange for it to be started at run time with
# chkconfig dhcpd on
Server 1 Server 2
Server IP address 192.168.0.1 192.168.0.2
IP Range 192.168.0.100-150 192.168.0.151-200
DNS 192.168.0.1 192.168.0.2
192.168.0.2 192.168.0.1
If one of the servers is down, the other server can provide DHCP functionality. If you are also
using DNS in each server, the order of DNS configuration also should be changed accordingly.
Page 60 / 121
DHCP Client
DHCP Client will receive automatically but you can also specify
For Windows NT, 2000, XP and Vista,
Command Description
Command Description
ipconfig Show IP information
ipconfig /all Show all IP information
ipconfig /release Release IP addresses
ipconfig /renew Renew IP addresses
You might experience the renew option does not work, and then reboot the PC.
P
age 61 / 121Lecturer EZE Herbert O.
For Linux,
Command Description
Command Description
ifconfig Show IP information
route -n Show routing table
/etc/init.d/network Get IP address
restart or dhcpcd
Page 62 / 121
6. Basic of DNS (BIND)
The Domain Name System or DNS is a system that stores information about host names and domain
names on networks, such as the Internet. Most importantly, it provides an IP address for each host
name, and lists the mail exchange servers accepting e-mail for each domain.
The DNS forms a vital part of the Internet, because hardware requires IP addresses to perform
routing, but humans use host names and domain names, for example in URLs and email addresses.
A domain name usually consists of two or more parts (technically labels) separated by dots. The
rightmost label conveys the top-level domain (for example, the address www.yahoo.com has the
top-level domain com). Each label to the left specifies a subdivision or subdomain (for example,
yahoo.com is a subdomain of com and www.yahoo.com is a subdomain of yahoo.com).
⚫ An A record or address record maps a host name to its 32-bit IPv4 address.
⚫ An AAAA record or IPv6 address record maps a host name to its 128-bit IPv6 address.
⚫ A CNAME record or canonical name record makes one domain name an alias of another. The
aliased domain gets all the subdomains and DNS records of the original.
P
age 63 / 121Lecturer EZE Herbert O.
⚫ An MX record or mail exchange record maps a domain name to a list of mail exchange servers
for that domain.
⚫ A PTR record or pointer record maps a host name to the canonical name for that host. Setting
up a PTR record for a host name in the in-addr.arpa domain that corresponds to an IP address
implements reverse DNS lookup for that address. For example (at the time of writing),
www.icann.net has the IP address 192.0.34.164, but a PTR record maps 164.34.0.192.in-
addr.arpa to its canonical name, referrals.icann.org.
⚫ An NS record or name server record maps a domain name to a list of DNS servers for that
domain and are used to create delegations.
⚫ An SOA record or start of authority record specifies the DNS server providing authoritative
information about an Internet domain.
6.3. BIND
BIND (Berkeley Internet Name Domain, previously: Berkeley Internet Name Daemon) is the most
commonly used DNS server on the Internet, especially on Unix-like systems, where it is a de facto
standard.
Scenario:
Assume that we have a single openSuSE Leap 42.3 Linux machine to be configured as a DNS
Server, and another client machine (Linux, or Windows 7). A switch will be needed to create a
single segment LAN. The topology is a shown below:
Scenario diagram for typical rwanda.local network
Page 64 / 121
DNS server installation requires the following packages
1. bind 2. bind-chrootenv 3. bind-doc 4. bind-libs 5. bind-utils
These packages can be installed by using the yast2 tool or using the yast2 command line interface
zypper command “zypper in bind “
P
age 65 / 121Lecturer EZE Herbert O.
The output of the second command is a tabular output. In the first column “i” indicates an already
installed package. “i” against bind, bind-chrootenv, bind-doc, bind-libs, bind-utils, all indicates that
the packages have been installed.
2. Forward Zone
First, we must introduce the zone to named.conf
…
Page 66 / 121
include "/etc/named.conf.include"; zone "rwanda.local" in { file "master/rwanda.local";
type master;
};
3. Reverse Zone
First, we must introduce the zone to named.conf
zone "10.168.192.in-addr.arpa" in {
file "master/192.168.10.zone";
type master; };
$TTL 1W
@ IN SOA ns1.rwanda.local. root.ns1.rwanda.local. (
42 ; serial (d. adams)
2D ; refresh
4H ; retry
6W ; expiry
1W ) ;
minimum
IN NS ns1.rwanda.local.
1 IN PTR ns1.rwanda.local.
4. Resolver Configuration
P
age 67 / 121Lecturer EZE Herbert O.
The last thing we need to do before running BIND is to set up the local resolver software.
/etc/resolv.conf
nameserver 192.168.10.1 search
rwanda.local
5. How to restart
Whenever you changed the configuration, you must restart the service to enable to configuration.
# /etc/init.d/named restart
1. nslookup command
# nslookup
Default Server: ns1.rwanda.local
Address: 192.168.10.1
> ns1
Server: ns1.rwanda.local
Address: 192.168.10.1
Name: ns1.rwanda.local
Address: 192.168.10.1
> www
Server: ns1.rwanda.local
Address: 192.168.10.1
2. dig command
Page 68 / 121
ns1:~ # dig rwanda.local
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;rwanda.local. IN A
;; AUTHORITY SECTION:
rwanda.local. 604800 IN SOA ns1.rwanda.local. root.ns1.rwanda.local. 42
172800 14400 3628800 604800
Exercise 4 - DNS
Configure your DNS server. Following will be the example configuration for BIND.
Trainee1 Trainee2
Domain Name test1.kg test2.kg
Network Address 212.0.0.0/255.255.255.240 212.0.0.0/255.255.255.240
Note: If your computer is not delegated properly from the higher DNS authority, you can
not test using nslookup and dig command. However, you can still test by ping command.
P
age 69 / 121Lecturer EZE Herbert O.
7. Advanced DNS (BIND)
To use the name server of the provider or one already running on your network as the forwarder,
enter the corresponding IP address or addresses in the options section under forwarders. The
addresses in the followings are just examples. Change these entries according to your own setup.
The options entry is followed by entries for the zone, for localhost, 0.0.127.in-addr.arpa, and the
type hint entry under “.”, which should always be present. The corresponding files do not need to
be modified and should work as is. Also make sure that each entry is closed with a “;” and that the
curly braces are in the correct places. After changing the configuration file /etc/named.conf or the
zone files, tell BIND to reread them.
directory "/var/lib/named"; specifies the directory where BIND can find the files containing the
zone data.
forwarders 192.168.10.1;; specifies the name servers (mostly of the provider) to which DNS
requests should forwarded if they cannot be resolved directly.
forward first; causes DNS requests to be forwarded before an attempt is made to resolve them via
the root name servers. Instead of forward first, forward only can be written to have all requests
forwarded and none sent to the root name servers. This makes sense for firewall configurations.
Page 70 / 121
listen-on port 53 127.0.0.1; 192.168.10.1;; tells BIND to which network interface and port to listen.
The port 53 specification can be left out, as 53 is the default port. If this entry is completely omitted,
BIND accepts requests on all interfaces.
query-source address * port 53; This entry is necessary if a firewall is blocking outgoing DNS
requests. This tells BIND to post requests externally from port 53 and not from any of the high
ports above 1024.
allow-query 127.0.0.1; 192.168.10.1/24;; defines the networks from which clients can post DNS
requests. The /24 at the end is an abbreviated expression for the netmask, in this case,
255.255.255.0.
allow-transfer ! *;; controls which hosts can request zone transfers. In the example, such requests
are completely denied with ! *. Without this entry, zone transfers can be requested from anywhere
without restrictions.
notify no; If notify is set to yes (default), notify messages are sent to other name servers when the
zone data is changed. Instead of setting a global 'notify' statement in the 'options' section, a separate
'notify' can be added to each zone definition.
P
age 71 / 121Lecturer EZE Herbert O.
8. APACHE WEB SERVER
Page 72 / 121
Introduction
• Apache web server evolved as a result of the effort of Brain Behiendorl in 1995
• He collected and packaged apache as a collection of software patches that had been used on the latest version of NCSA HTTPd
web server. The first package known as apache (from “a patchy” web server) was released publicly in 1995.
• Apache is the most widely used web server providing 70% of web service content on public internet.
• The group known as Apache Software Foundation is now an incorporated group providing legal structure for the continued open
source operation of apache
TCT 2/22/2010
Page 73 / 121
Lecturer EZE Herbert O.
Installation
TCT 2/22/2010
Confirm installation
• Installation can be confirmed in yast2-software
management tool by clicking on the installed tab, the
installed packages will be listed in alphabetical order
in the details-container pane of the utility.
Page 74 / 121
•The command
line tool can also
be used by typing
at the shell
prompt: zypper se
<package name –
e.g. apache2>
•Rpm command
can also be used
by typing rpm –qa
<packagename
e.g. apache2>
Configuration
• The apache server is a multi-layered consolidated system that uses mostly pre-forked system call and sometimes worker-thread
system for executing the server processes.
• So the server forks up many executing processes and spare process in ready state to process many of the categories of the web
service processing.
• As a result the configuration includes many modules, which are not contained in a single file.
Page 75 / 121
Lecturer EZE Herbert O.
• The main configuration file is the /etc/apache2/httpd.conf file.
• Many include statements (called include directives – in apache2 terms) are used to include these modules in the sections of the
main configuration file (httpd.conf) where they should be.
• The /etc/apache2/httpd.conf file has three main configuration sections
• The Global Environment Section, the Main server or default server section, and the Virtual Host Section
Page 76 / 121
Global Environment section
• This section is used to provide the configuration option dedicated to the operation of the primary web site.
• The include directive here points to the defaultserver configuration file where the main directives for default server configuration
is.
• Here is the place to configure for virtual hosts. Such configurations allow an administrator to configure multiple websites in the
same server.
• The include directive in this section points to vhosts.d directory where there are vhost.template files used in configuring the virtual
hosts. And also listen.conf file where there are directives for ip address and ports on which virtual hosts can listen for service
requests (Listen 80,
NameVirtualHost *: 80) are typical directives here.
• The vhost.template file contains some similar directives as the default-server.conf file, but in addition it also contain directives like
<VirtualHost *:80>, ServerAdmin,
ServerName, DocumentRoot, ErrorLog, CustomLog,
HostNameLookups, UseCannonicalName,
ServerSignature
Page 79 / 121
Lecturer EZE Herbert O.
Explaining some major Directives
<Directory /srv/www/htdocs>
<Filessecret.html>
Options All
AllowOveride None
Order deny, allow
Allow from 192.168.10.0 /24
Deny from All
</Files>
</Directory>
the first two lines points to the resources (directory or pages/files) that the options in the container shall operate on.
The Options directive is used to choose one or combinations of operational website features { Indexes, Includes,
FollowSymLinks, SymLinksIfOwnerMatch, ExecCGI, Multiviews, All, and None}
The AllowOverride directive used one or combination of the choices {All, None, Options, FileInfo, AutoConfig, and Limit} to
specify the degree of restriction on inheritance of settings/features by the subdirectories or child-directories or files to the directory
associated to this container.
Page 80 / 121
Lecturer EZE Herbert O.
Explaining some major Directives
The line Order deny,allow and Deny from All work together to select or filter clients request for the pages in the container which
can be serviced (passed) or rejected. The Order directive is used to specify which set (Deny or Allow ) directives to evaluate
first for matching.
For the Order deny,allow - Deny directives will be evaluated first before Allow directives are evaluated. If at the reception of a
request, at least one Deny directive matches that request, the request will be rejected except if there is any allow directive that
matches the request.
For Order allow,deny - First, all Allow directives are evaluated; at least one must match, or the request is rejected. Next, all Deny
directives are evaluated. If any matches, the request is rejected. Last, any requests which do not match an Allow or a Deny
directive are denied by default.
• <IfModule mod_Userdir>
</IfModule> - This directive is used in the same way as the Directory container directive, but in the case of “If a module is to be
included”. So it specifies configuration settings or additional specific directives for the module which it points to, like Userdir
module as in the case of above directive.
• Alias – This directive is used to give shortname or fakename to a directory or pages files or other resources such that rather than
giving the full pathname for that resource in the URL, the short fakename can be used in the url to reduce the complexity e.g
Alias /john/
/home/john/public_html/
Set apache2 On at run levels 3 and 5, so that it can start automatically at boot time.
Ensure that DirectoryIndex directive has been set with correct values in /etc/apache2/httpd.conf.
For all the above steps, do as in the case of setting up primary website.
Name-based virtual website
(create the DocumentRoots)
Page 86 / 121
Lecturer EZE Herbert O.
Decide the points in the files system tree where you wish to create
the DocumentRoots for the websites
Navigate to those points and Create the directories you will use as
the document roots (to keep the web pages/files) for the
two sites wwwl.itclass.local and for
mail.itclass.local
CGI – Common Gateway Interface defines a way in which a web server can interact with external programs, often referred to as CGI
programs or scripts, for generating dynamic web contents based on client request.
If a web server has the capability to run CGI scripts, normally contained in a specific directory, it means that when a client requests
content from such directories, the server itself will run the scripts or programs in the directory, those programs in turn will generate web
pages as a result of their process and the generated pages are served to the client. CGI is said to be server side technology because the
client machine does not need to have a particular client program in order to request and use the CGI directory contents. The web server
itself runs the content and server the result to the client via the web browser.
PERL is a scripting language that can be used for CGI scripts. PERL compares with PHP sometimes. However it is different from php
scripts because where as php runs its process interpreter as part of the apache web server, perl script interpreter runs as separate process
from the web server modules and only pipes its outputs into the web servers standard output.
TCT 2/22/2010
Enabling CGI at website Directory
Page 97 / 121
There are two ways by which CGI scripts can be enabled for a Lecturer EZE Herbert O.
website.
After a ScriptAlias directive has been used to point to a
One is by the use of the ScriptAlias directive directory according to file system location, the next thing
Example; ScriptAlias /cgi-bin/ would then be to use the <Directory> directive to provide the
“/srv/www/cgi-bin/” specific settings of how the apache2 will treat the contents of
By the above directive, it is meant that the apache2 web server the dircetory which the ScriptAlias pointed to. In the directory
recognizes that the contents in the /srv/www/cgi-bin/ directory directive, use the value +ExecCGI among the values for the
are scripts or programs, so that when a client’s request is (sub)directive Options (e.g.
targeted on that directory, the apache2 server knows that it <Directory “/srv/www/cgi-bin”>
should run the scripts by itself and send the output across the --------
network to the browser. The ScriptAlias works like Alias in Option Indexes +ExecCGI Multiviews
terms of the web space relationship with the URL. If
---------
wwwl.itclass.local is the domain name for the website, then
typing the url; wwwl.itclass.local/cgi-bin/ will make the client </Directory> )
request to be pointed to the content of the the directory
/srv/www/cgi-bin/;
which is the file-system value of the ScriptAlias /cgi-bin/
TCT 2/22/2010
Page 98 / 121
Enabling CGI at website Directory
Page 101 /
121Lecturer EZE Herbert O.
Enabling PHP Pages for Apache web server
In httpd.conf file add a directive as follows
<IfModule mod_php5.c> AddType application/x-
httpdphp .php <IfModule>
In mail.kigali.local use
directives to make ACL to prevent a host (e.g. 192.168.20.5) from accessing the web pages.
Make a PHP content and load it in an arbitrary directory in the www.kigali.local site and
enable that site for PHP content so that a browser can access output from that directory. Add
Authentication based security using Basic Authentication type.
FTP Processes
Page 112 / 121
FTP – like the apache web server uses multiple processes
simultaneously, although it uses much less processes.
There are two main ftp processes namely
ftp connection and control – this processes uses default
well known port number 21
ftp data transfer process – this process uses well known
port number 20
There is also a secure connection (SFTP) process which
uses a well known port number 22
ftp control is used to initiate and negotiate connection, it
is also used between the client and server to exchange
control commands like rename and copy, or mkdir
commands using port 21
ftp data transfer – is only functional on interim bases and
serves only to transfer data (files), for instance if a
clients passed a copy command to the server via ftp (21)
, the server responds by initiating a data transfer process
which will enable client-server to establish a data
transfer connection for files exchange
There two types of Data Transfer Connections in FTP
client-server communications
ACTIVE data transfer connection (Active FTP)
Passive Data Transfer connection (Passive FTP)
Also there is two forms of transfers
Ascii transfer process
Binary transfer process
FTP - Installation
Page 113 / 121
Enabling PHP Pages for Apache web server
FTP daemon is known as vsftpd
(Very Secured File Transfer Protocol
Daemon)
To Implement ftp this vsftpd package
need to be installed using any of the
software installation methods
E.g.: type at the shell prompt zypper in
–y vsftpd
This command will install the package
provided that the repository is
correctly configured and populated.
Use the command zypper se vsftpd to
check and ensure that vsftpd package
has been installed
See at the screen shots at the right.
FTP - Configuration
local_umask=022
most commonly used umask for local users . Default is 077
chroot_local_user=YES
local users are chrooted to their home directory
chroot_list_enable=YES
explicit list of users to chroot their home directories enabled
chroot_list_file
=/etc/vsftpd.chroot_list
local_max_rate=7200
maximum data rate permitted for the local user in bytes/sec
local_umask=022
this is a umask file permission setting for local users
anon_upload_enable=YES
this enables anonymous user to upload file, but subject to write_enable
general option
anon_mkdir_write_enable=YES anonymous user is allowed to create
directories
anon_other_write_enable=YES allow anonymous user to rename or
move files
chown_uploads=YES
chown_username=whoever allow file owner change when
anonymous user uploads file