Introduction To UNIX and Linux - Lecture Seven
Introduction To UNIX and Linux - Lecture Seven
html
Introduction to UNIX:
Lecture Seven
7.1 Objectives
This lecture covers basic system administration concepts and tasks, namely:
Note that you will not be given administrator access on the lab machines. However,
you might like to try some basic administration tasks on your home PC.
One way to become root is to log in as usual using the username root and the root
password (usually security measures are in place so that this is only possible if you
are using a "secure" console and not connecting over a network). Using root as your
default login in this way is not recommended, however, because normal safeguards
that apply to other user accounts do not apply to root. Consequently using root for
mundane tasks often results in a memory lapse or misplaced keystrokes having
catastrophic effects (e.g. forgetting for a moment which directory you are in and
accidentally deleting another user's files, or accidentally typing "rm -rf * .txt"
instead of "rm -rf *.txt" ).
A better way to become root is to use the su utility. su (switch user) lets you become
another user (at least as far as the computer is concerned). If you don't specify the
1 of 7 10/17/2009 2:20 PM
Introduction to UNIX and Linux: Lecture 7 http://www.doc.ic.ac.uk/~wjk/UnixIntro/Lecture7.html
name of the user you wish to become, the system will assume you want to become
root. Using su does not usually change your current directory, unless you specify a
"-" option which will run the target user's startup scripts and change into their home
directory (provided you can supply the right password of course). So:
$ su -
Password: xxxxxxxx
#
Note that the root account often displays a different prompt (usually a #). To return
to your old self, simply type "exit" at the shell prompt.
You should avoid leaving a root window open while you are not at your machine.
Consider this paragraph from a humorous 1986 Computer Language article by Alan
Filipski:
If you have to shut a system down extremely urgently or for some reason cannot
use shutdown, it is at least a good idea to first run the command:
2 of 7 10/17/2009 2:20 PM
Introduction to UNIX and Linux: Lecture 7 http://www.doc.ic.ac.uk/~wjk/UnixIntro/Lecture7.html
# sync
System startup:
At system startup, the operating system performs various low-level tasks, such as
initialising the memory system, loading up device drivers to communicate with
hardware devices, mounting filesystems and creating the init process (the
parent of all processes). init's primary responsibility is to start up the system
services as specified in /etc/inittab. Typically these services include gettys
(i.e. virtual terminals where users can login), and the scripts in the directory
/etc/rc.d/init.d which usually spawn high-level daemons such as httpd
(the web server). On most UNIX systems you can type dmesg to see system
startup messages, or look in /var/log/messages.
If a mounted filesystem is not "clean" (e.g. the machine was turned off without
shutting down properly), a system utility fsck is automatically run to repair it.
Automatic running can only fix certain errors, however, and you may have to
run it manually:
# fsck filesys
where filesys is the name of a device (e.g. /dev/hda1) or a mount point (like
/). "Lost" files recovered during this process end up in the lost+found
directory. Some more modern filesystems called "journaling" file systems don't
require fsck, since they keep extensive logs of filesystem events and are able to
recover in a similar way to a transactional database.
useradd is a utility for adding new users to a UNIX system. It adds new user
information to the /etc/passwd file and creates a new home directory for the
user. When you add a new user, you should also set their password (using the
-p option on useradd, or using the passwd utility):
# useradd bob
# passwd bob
groupadd creates a new user group and adds the new information to
3 of 7 10/17/2009 2:20 PM
Introduction to UNIX and Linux: Lecture 7 http://www.doc.ic.ac.uk/~wjk/UnixIntro/Lecture7.html
/etc/group:
# groupadd groupname
groups
# groups username
Look in /usr/src/linux for the kernel source code. If it isn't there (or if there
is just a message saying that only kernel binaries have been installed), get hold
of a copy of the latest kernel source code from http://www.kernel.org and untar
it into /usr/src/linux.
4 of 7 10/17/2009 2:20 PM
Introduction to UNIX and Linux: Lecture 7 http://www.doc.ic.ac.uk/~wjk/UnixIntro/Lecture7.html
optional modules have actually been loaded you can run lsmod when the
system reboots.
Now type:
Finally, you may need to update the /etc/lilo.conf file so that lilo (the
Linux boot loader) includes an entry for your new kernel. Then run
# lilo
to update the changes. When you reboot your machine, you should be able to
select your new kernel image from the lilo boot loader.
Each entry in the /etc/crontab file entry contains six fields separated by spaces or
tabs in the following form:
minute 0 through 59
hour 0 through 23
day_of_month 1 through 31
5 of 7 10/17/2009 2:20 PM
Introduction to UNIX and Linux: Lecture 7 http://www.doc.ic.ac.uk/~wjk/UnixIntro/Lecture7.html
month 1 through 12
weekday 0 (Sun) through 6 (Sat)
command a shell command
You must specify a value for each field. Except for the command field, these fields
can contain the following:
A number in the specified range, e.g. to run a command in May, specify 5 in the
month field.
Two numbers separated by a dash to indicate an inclusive range, e.g. to run a
cron job on Tuesday through Friday, place 2-5 in the weekday field.
A list of numbers separated by commas, e.g. to run a command on the first and
last day of January, you would specify 1,31 in the day_of_month field.
* (asterisk), meaning all allowed values, e.g. to run a job every hour, specify an
asterisk in the hour field.
You can also specify some execution environment options at the top of the
/etc/crontab file:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
To run the calendar command at 6:30am. every Mon, Wed, and Fri, a suitable
/etc/crontab entry would be:
30 6 * * 1,3,5 /usr/bin/calendar
The output of the command will be mailed to the user specified in the MAILTO
environment option.
You don't need to restart the cron daemon crond after changing /etc/crontab - it
automatically detects changes.
rs:2345:respawn:/home/sms/server/RingToneServer
Here rs is a 2 character code identifying the service, and 2345 are the runlevels (to
find about runlevels, type man runlevel) for which the process should be created.
The init process will create the RingToneServer process at system startup, and
respawn it should it die for any reason.
6 of 7 10/17/2009 2:20 PM
Introduction to UNIX and Linux: Lecture 7 http://www.doc.ic.ac.uk/~wjk/UnixIntro/Lecture7.html
7 of 7 10/17/2009 2:20 PM