[StuCo 98008]
GNU/Linux for Beginners

Session 5

System Administration

By the end of this lecture you will know

How to administer user/group information

How to interpret and use filesystem permissions

How to add/remove applications

How to handle processes

Scheduling and automating tasks

Managing hardware

Users and groups

/etc/passwd stores information about user accounts

Except their passwords, these are at /etc/shadow

A typical /etc/passwd entry:

freenet:x:1004:1004:Freenet Test Account,,,:/home/freenet:/bin/bash

/etc/group stores information about groups

The group passwords are stored in /etc/gshadow

A typical /etc/group entry:

cdrecording:x:1007:alex,ddrew

Administering User Information

One way: Hand-editing /etc/passwd

Simple but tricky

Other way: GUI utility

Simper but trickier

Best way: CLI utilities

useradd/groupadd : Add new user/group

userdel/groupdel : Delete existing user/group

usermod/groupmod : Modify user/group information

Filesystem permissions

Basic file attributes, like file type, permission to read/write/execute, which user/group owns the file:

-rwxr-xr-x 1 alex staff	385K	Aug 29 06:57 .bashrc

drwxr-xr-x 4 ddrew staff 4,0K Sep 17 22:47 Library

File type:

- Regular file

d Directory

l Link

Access Permissions

User, Group, Others

read, write, execute

Reference count

Owner

Group

Size on disk

Modification time

Name

Changing permissions

chown/chmod : Change the owner or group of a file

Relative Permissions

chmod [a,u,g,o][+,-][r,w,x] <filename>

[all, user, group, others] [add, remove] [read, write, execute]

Absolute Permissions

4 – read

2 – write

1 – execute

So, if we want to change a file's permissions to rwxr-xr-x , the command chmod 755 does the trick

Managing Applications

Applications are provided as packages of the following types:

.rpm (RedHat Package Manager)

.deb (Debian Advanced Package Tool)

.tar [.gz - .bz2] (tarballs, often compressed with gzip or bzip2)

RPM

RPM is the preferred package management tool for Red Hat, SuSE, Mandrake, Gentoo

# rpm -U sendmail-8.3.0.rpm : install/upgrade

# rpm -q sendmail : query installed package

# rpm -e sendmail-8.3.0 : erase installed package

# rpm -qa : show all installed packages
Combine with grep to search for a pattern, e.g.
# rpm -qa | grep sendmail

Add the flags v,h for more verbose output

DEB

DEB is the preferred package format for Debian.

Debian uses multiple levels of tools to manage its packages:

dpkg, apt-get, aptitude, dselect...

Recommended method:

# apt-get install sendmail

# apt-get remove sendmail

# apt-get update : updates your local package index

# apt-cache search icons : look for a package that has something to do with icons

TARballs

Some distributions intentionally do this (e.g. Slackware)

Sometimes, the application you want has not been pre-packaged by your distribution (no RPM, no DEB), but source tarballs are always available

Problem/blessing: No centralized database (like rpm -qa or dpkg --list)

Usual procedure for installation:

Untar/uncompress: $ tar -xvzf qmail-3.0.1.tar.gz

Tailor the parameters to your system: $ ./configure

Compile the application: $ make

Install it (usually needs root privileges): # make install

Processes

Any program that executes in userland spawns one or more processes, each of which has a process ID (PID).

Listing:

$ ps auxf : List all ProcesseS in tree format

$ top -c : Show list of most resource-intensive processes

Killing:

$ kill <PID> : Sends a TERMinate signal to the process. Works only if you own the process, or are root

$ killall <process name> : Kill processes by name (dangerous but convenient)

$ kill -9 <PID> : Send a KILL signal to the process (last resort for something that's not responding)

Scheduling

Scheduling stuff to be executed just once:

$ sleep 12m; echo “Spaghetti on fire”

sleep simply counts time since invocation (relative scheduling)

$ at 15:00 echo “Wake up – time to go to class”

relative or absolute scheduling, e.g $ at +10m echo “Time to go”

$ atrm 1 : removes the first scheduled job

$ atq : prints the queue of scheduled jobs

Persistent scheduling: cron

$ crontab -e : edit my crontab, with the following syntax:

00 4 * * wed,sat alex /home/alex/scripts/backup_home.sh

minute, hour, day of month, month, day of week, user, command

$ crontab -l : list my crontab

Hardware Information

Disk Free space: $ df (-h for human-readable format)

Free RAM: $ free (-m for displaying RAM in megabytes)

CPU info: $ cat /proc/cpuinfo

Boot-time device detection : $ dmesg (| less)

PCI bus information: $ lspci (-v for more verbose output)

The Andrew servers have interesting /etc/passwd files. Since anyone can use these servers to login, they must hold account information for all CMU students. Try figuring out how many students have active accounts this term (hint: wc is your friend)

More info at:

http://www.mandrakeuser.org/docs/admin/index.html#s

http://www.justlinux.com/nhf/Miscellaneous/Scheduling_in_Linux.html

Session 5 - System Administration

[StuCo 98008] Introduction to GNU/Linux

gnu linux system administration chmod permissions passwd shadow rpm dpkg tar configure cron atd lspci free cpuinfo df

This lecture introduces us to the basics of administering a GNU/Linux system.
We go over user/group information handling, explain permissions and ownership and how they can be changed.
Then we talk about adding/removing/upgrading software packages. We cover the rpm (RedHat, SuSE, Mandrake), apt (Debian), and tarballs (Slackware) methods.
We also talk about processes and jobs. We show how they can be audited (ps, top), handled (KILL signals), and sent to the foreground or background of the shell.
Then we show the basic scheduling facilities (cron and the at daemon), and how they can be used to automate administrative tasks.
Drawing to an end, we show future administrators how to find out what kind of hardware they have on their systems, the memory utilization, processor information, free disk space, etc.

2003-09-11T14:09:36