Table of Contents
Here, I will describe basic tips to configure and manage systems, mostly from the console.
The screen
program is a very useful tool for people to access remote sites via unreliable or intermittent connections since it support interrupted network connections.
Table 10.1. List of programs to support interrupted network connections.
package |
popcon |
size |
description |
---|---|---|---|
|
V:10, I:29 |
1036 |
terminal multiplexer with VT100/ANSI terminal emulation |
|
V:0.05, I:0.5 |
372 |
allows you to move programs between X Window System displays |
The screen
(1) program not only allows one terminal window to work with multiple processes, but also allows remote shell process to survive interrupted connections. Here is a typical use scenario of the screen
(1) program.
You login to a remote machine.
You start the screen
command on a single console.
You execute multiple programs in screen
windows created with ^A c
("Control-A" followed by "c").
You switch among the multiple screen
windows by ^A n
("Control-A" followed by "n").
Suddenly you need to leave your terminal, but you don't want to lose your active work by keeping the connection.
You detach the screen
session by any methods such as:
brutally unplugging your network connection,
typing ^A d
("Control-A" followed by "d") and manually logging out from the remote connection, or
typing ^A DD
("Control-A" followed by "DD") to have screen
detach and log you out.
You log in again to the same remote machine (even from a different terminal).
You enter the "screen -r
" command.
The screen
program will magically reattach all previous screen
windows with all actively running programs.
![]() |
Tip |
---|---|
You can save connection fees for metered network connections such as dial-up and packet ones, because you can leave a process active while disconnected, and then re-attach it later when you connect again. |
In screen
session, all keyboard inputs are sent to your current window except for the command keystroke, by default ^A
("Control-A"). All screen
commands are entered by typing ^A
plus a single key [plus any parameters]. Here are important ones to remember:
Table 10.2. List of key bindings for screen.
key binding |
meaning |
---|---|
|
show a help screen (display key bindings) |
|
create a new window and switch to it |
|
go to next window |
|
go to previous window |
|
go to window number 0 |
|
go to window number 1 |
|
show a list of windows |
|
send a Ctrl-A to current window as keyboard input |
|
write a hardcopy of current window to file |
|
begin/end logging current window to file |
|
lock the terminal (password protected) |
|
detach screen session from the terminal |
|
detach screen session and log out |
See screen
(1) for details.
Many programs record their activities under the /var/log/
directory.
The kernel log daemon: klogd
(8)
The system log daemon: syslogd
(8)
See Section 4.5.8, “The system message” and Section 4.5.9, “The kernel message”.
Here are notable log analyzers ("~Gsecurity::log-analyzer
" in aptitude
).
Table 10.3. List of system log analyzers.
package |
popcon |
size |
description |
---|---|---|---|
|
V:2, I:2 |
2312 |
log analyser with nice output written in Perl |
|
V:2, I:2 |
616 |
bans IPs that cause multiple authentication errors |
|
V:1.2, I:17 |
4608 |
web server log analyzer |
|
V:1.5, I:3 |
4896 |
powerful and featureful web server log analyzer |
|
V:1.5, I:1.5 |
1448 |
squid analysis report generator |
|
V:0.3, I:0.7 |
164 |
Postfix log entry summarizer |
|
V:0.2, I:1.0 |
80 |
summarize the contents of a syslog log file |
|
V:0.18, I:0.2 |
5056 |
full-featured log analyzer and report generator |
|
V:0.14, I:0.2 |
432 |
Firewall log analyzer |
|
V:0.09, I:0.6 |
260 |
monitors and analyses squid access.log files |
|
V:0.08, I:0.3 |
224 |
fast web server log analyzer |
|
V:0.06, I:0.2 |
112 |
Log file viewer with regexp matching, highlighting, & hooks |
|
V:0.08, I:0.2 |
1120 |
The Controllable Regex Mutilator and Spam Filter (CRM114) |
|
V:0.07, I:0.4 |
84 |
Interpret ICMP messages |
![]() |
Note |
---|---|
CRM114 provides language infrastructure to write fuzzy filters with the TRE regex library. Its popular use is spam mail filter but it can be used as log analyzer. |
The simple use of the script
(1) command (see: Section 2.4.9, “Recording the shell activities”) to record shell activity produces a file with control characters. This can be avoided by using the col
(1) command:
$ script Script started, file is typescript
do whatever ...
Press Ctrl-D
to exit script
$ col -bx <typescript >cleanedfile $ vim cleanedfile
If you don't have the script
command (for example, during the boot process in the initramfs), you can use following instead:
$ sh -i 2>&1 | tee typescript
![]() |
Tip |
---|---|
Some |
![]() |
Tip |
---|---|
You may use |
![]() |
Tip |
---|---|
You may use |
Although pager tools such as more
(1) and less
(1) (see Section 2.4.5, “The pager”) and custom tools for highlighting and formatting Section 12.1.7, “Highlighting and formatting plain text data” can display text data nicely, general purpose editors (see Section 2.4.6, “The text editor”) are most versatile and customizable.
![]() |
Tip |
---|---|
For |
Shell echo to most modern terminals can be colorized using ANSI escape code (see /usr/share/doc/xterm/ctlseqs.txt.gz
). E.g.:
$ RED=$(printf "\x1b[31m") $ NORMAL=$(printf "\x1b[0m") $ REVERSE=$(printf "\x1b[7m") $ echo "${RED}RED-TEXT${NORMAL} ${REVERSE}REVERSE-TEXT${NORMAL}"
Colorized commands are handy for inspecting their output in the interactive environment. I include following in my ~/.bashrc
.
if [ "$TERM" != "dumb" ]; then eval "`dircolors -b`" alias ls='ls --color=always' alias ll='ls --color=always -l' alias la='ls --color=always -A' alias less='less -R' alias ls='ls --color=always' alias grep='grep --color=always' alias egrep='egrep --color=always' alias fgrep='fgrep --color=always' alias zgrep='zgrep --color=always' else alias ll='ls -l' alias la='ls -A' fi
The use of alias limits color effects to the interactive command usage. It has advantage over exporting environment variable "export GREP_OPTIONS='--color=auto'
" since color can be seen under pager programs such as "less
".
![]() |
Tip |
---|---|
You can turn off these colorizing aliases in the interactive environment by invoking shell with " |
There are few ways to record the graphic image of an X application, including an xterm
display.
Table 10.4. List of graphic image manipulation tools.
package |
popcon |
size |
command |
---|---|---|---|
|
V:25, I:64 |
84 |
|
|
V:13, I:55 |
11928 |
GUI menu |
|
V:13, I:31 |
4464 |
|
|
V:0.2, I:1.1 |
76 |
|
There are specialized tools to record changes in configuration files with help of DVCS system.
I recommend to use the etckeeper
package with git
(1) which put entire "/etc
" under VCS control. Its installation guide and tutorial are found in "/usr/share/doc/etckeeper/README.gz
".
Essentially, running "sudo etckeeper init
" initializes the git repository for "/etc
" just like the process explained in Section 11.5.4.4, “Git for recording configuration history”) but with special hook scripts for more thorough setups.
As you change your configuration, you can use git
(1) normally to record them. It will automatically record changes nicely every time you run package management commands, too.
You can browse history of "/etc
" and package upgrade by executing "cd /etc; sudo gitk
".
Booting your system with Linux live CDs or debian-installer CDs in rescue mode make it easy for you to reconfigure data storage on your boot device. See also Section 11.2, “The binary data”.
For partition configuration, although fdisk
(8) has been considered standard, parted
(8) deserves some attention. "Disk partitioning data", "partition table", "partition map", and "disk label" are all synonyms.
Most PCs use the classic Master Boot Record (MBR) scheme to hold disk partitioning data in the first sector, i.e., LBA sector 0 (512 bytes).
![]() |
Note |
---|---|
Some new PCs with Extensible Firmware Interface (EFI), including Intel-based Macs, use GUID Partition Table (GPT) scheme to hold disk partitioning data not in the first sector. |
Although fdisk
(8) has been standard for the disk partitioning tool, parted
(8) is replacing it.
Table 10.6. List of disk partition management packages
package |
pocon |
size |
description |
|
---|---|---|---|---|
|
V:85, I:99 |
1744 |
Miscellaneous system utilities including |
Not supported |
|
V:1.1, I:8 |
180 |
The GNU Parted disk partition resizing program |
Supported |
|
V:4, I:46 |
1940 |
GNOME partition editor based on |
Supported |
|
V:0.14, I:1.1 |
764 |
KDE partition editor based on |
Supported |
|
V:0.00, I:0.11 |
72 |
Synchronize classic MBR partition table with the GPT one |
Supported |
![]() |
Caution |
---|---|
Although |
![]() |
Note |
---|---|
In order to switch between GPT and MBR, you need to erase first few blocks of disk contents directly (see Section 11.2.10, “Clear file contents”) and use " |
Although reconfiguration of your partition may yield different names for partitions, you can access them consistently. This is also helpful if you have multiple disks and your BIOS doesn't give them consistent device names.
The mount
(8) command with "-U
" options can mount a block device using UUID, instead of using its file name such as "/dev/sda3
".
The "/etc/fstab
" file (see fstab
(5)) can use UUID.
Boot loaders (Section 4.3, “Stage 2: the boot loader”) may use UUID too.
![]() |
Tip |
---|---|
You can probe UUID of a block special device with the |
For ext3 filesystem, the e2fsprogs
package provides:
The mkfs
(8) and fsck
(8) commans are provided by the e2fsprogs
package as front-ends to various filesystem dependent programs (mkfs.fstype
and fsck.fstype
). For ext3 filesystem, they are mkfs.ext3
(8) and fsck.ext3
(8) (they are hardlinked to mke2fs
(8) and e2fsck
(8)).
Similar commands are available for each filesystem supported by Linux.
Table 10.7. List of filesystem management packages
package |
popcon |
size |
description |
---|---|---|---|
|
V:61, I:99 |
2088 |
|
|
V:3, I:10 |
1156 |
Utilities for the Reiserfs filesystem. |
|
V:3, I:24 |
224 |
Utilities for the FAT filesystem. (Microsoft: MS-DOS, Windows) |
|
V:2, I:9 |
3132 |
Utilities for the XFS filesystem. (SGI: IRIX) |
|
V:1.3, I:6 |
632 |
Utilities for the NTFS filesystem. (Microsoft: Windows NT, ...) |
|
V:0.6, I:2 |
1116 |
Utilities for the JFS filesystem. (IBM: AIX, OS/2) |
|
V:0.08, I:0.7 |
1248 |
Utilities for the Reiser4 filesystem. |
|
V:0.03, I:0.4 |
324 |
|
|
V:0.01, I:0.05 |
576 |
Utilities for the btrfs filesystem. |
![]() |
Tip |
---|---|
Ext3 filesystem is the default filesystem for the Linux system and strongly recommended to use it unless you have some specific reasons not to. After Linux kernel 2.6.28 (Debian |
![]() |
Tip |
---|---|
Some tools allow access to filesystem without Linux kernel support (see Section 11.2.5, “Manipulating files without mounting disk”). |
The mkfs
(8) command creates the filesystem on a Linux system. The fsck
(8) command provides the filesystem integrity check and repair on a Linux system.
![]() |
Tip |
---|---|
Check files in |
![]() |
Caution |
---|---|
It is generally not safe to run |
![]() |
Tip |
---|---|
Use " |
Performance and characteristics of a filesystem can be optimized by mount options used on it (see fstab
(5) and mount
(8)). For example:
"defaults
" option implies default options: "rw,suid,dev,exec,auto,nouser,async
". (general)
"noatime
" or "relatime
" option is very effective for speeding up the read access. (general)
"user
" option allows an ordinary user to mount the file system. This option implies "noexec,nosuid,nodev
" option combination. (general, used for CD and floppy)
"noexec,nodev,nosuid
" option combination is used to enhance security. (general)
"noauto
" option limits mounting by explicit operation only. (general)
"data=journal
" option for ext3fs can enhance data integrity against power failure with some loss of write speed.
![]() |
Tip |
---|---|
You need to provide kernel boot parameter " |
Characteristics of a filesystem can be optimized via its superblock using the tune2fs
(8) command. For example on /dev/hda1
:
Execution of "sudo tune2fs -l /dev/hda1
" will display the contents of its filesystem superblock.
Execution of "sudo tune2fs -c 50 /dev/hda1
" will change frequency of filesystem checks (fsck
execution during boot-up) to every 50 boots.
Execution of "sudo tune2fs -j /dev/hda1
" will add journaling capability to the filesystem, i.e. filesystem conversion from ext2 to ext3. (Do this on the unmounted filesystem.)
Execution of "sudo tune2fs -O extents,uninit_bg,dir_index /dev/hda1 && fsck -pf /dev/hda1
" will convert it from ext3 to ext4. (Do this on the unmounted filesystem.)
![]() |
Warning |
---|---|
Filesystem conversion for the boot device to the ext4 filesystem should be avoided until GRUB boot loader supports the ext4 filesystem well and installed Linux Kernel version is newer than 2.6.28. |
![]() |
Warning |
---|---|
Please check your hardware and read manpage of |
You can test disk access speed of a harddisk, e.g. /dev/hda
, by "hdparm -tT /dev/hda
". For some harddisk connected with (E)IDE, you can speed it up with "hdparm -q -c3 -d1 -u1 -m16 /dev/hda
" by enabling the "(E)IDE 32-bit I/O support", enabling the "using_dma flag", setting "interrupt-unmask flag", and setting the "multiple 16 sector I/O" (dangerous!).
You can test write cache feature of a harddisk, e.g. /dev/sda
, by "hdparm -W /dev/sda
". You can disable its write cache feature with "hdparm -W 0 /dev/sda
".
You may be able to read badly pressed CDROMs on modern high head CD-ROM drive by slowing it down with "setcd -x 2
.
For partitions created on Logical Volume Manager (Linux) at install time, they can be resized easily by concatenating extents onto them or truncating extents from them over multiple storage devices without major system reconfiguration.
![]() |
Caution |
---|---|
Deployment of the current LVM system may degrade guarantee against filesystem corruption offered by journaled file systems such as ext3fs unless their system performance is sacrificed by disabling write cache of harddisk. |
If you have an empty partition (e.g., /dev/sdx
), you can format it with mkfs.ext3
(1) and mount
(8) it to a directory where you need more space. (You need to copy original data contents.)
$ sudo mv work-dir old-dir $ sudo mkfs.ext3 /dev/sdx $ sudo mount -t ext3 /dev/sdx work-dir $ sudo cp -a old-dir/* work-dir $ sudo rm -rf old-dir
If you have an empty directory (e.g., /path/to/emp-dir
) in another partition with usable space, you can create a symlink to the directory with ln
(8).
$ sudo mv work-dir old-dir $ sudo mkdir -p /path/to/emp-dir $ sudo ln -sf /path/to/emp-dir work-dir $ sudo cp -a old-dir/* work-dir $ sudo rm -rf old-dir
![]() |
Caution |
---|---|
Some software may not function well with "symlink to a directory". |
If you have usable space in another partition (e.g., /path/to/
), you can create a directory in it and stack that on to a directory where you need space with aufs.
$ sudo mv work-dir old-dir $ sudo mkdir -p /path/to/emp-dir $ sudo mount -t aufs -o br:/path/to/emp-dir:old-dir none work-dir
![]() |
Caution |
---|---|
Use of aufs for long term data storage is not good idea since it is under development and its design change may introduce issues. |
Since gaining root privilege is relatively easy with physical access (see Section 5.7.4, “Securing the root password”), it can not secure your private and sensitive data against possible theft of your PC. You must deploy data encryption technology to do it. Although GNU privacy guard (see Section 11.3, “Data security infrastructure”) can encrypt files, it takes some user efforts.
dm-crypt and eCryptfs facilitates automatic data encryption natively via Linux kernel modules with minimal user efforts.
Table 10.8. List of data encryption utilities.
Dm-crypt is a cryptographic filesystem using device-mapper. Device-mapper maps one block device to another.
eCryptfs is another cryptographic filesystem using stacked filesystem. Stacked filesystem stacks itself on top of an existing directory of a mounted filesystem.
![]() |
Note |
---|---|
Entire Debian system can be installed on a encrypted disk by the debian installer (lenny or newer) using dm-crypt/LUKS and initramfs. |
![]() |
Caution |
---|---|
Data encryption costs CPU time etc. Please weigh its benefits and costs. |
![]() |
Tip |
---|---|
See Section 11.3, “Data security infrastructure” for user space encryption utility: GNU Privacy Guard. |
You can encrypt contents of removable mass storage devices, e.g. USB memory stick on /dev/sdx
, using dm-crypt/LUKS. You simply formatting it as:
# badblocks -c 10240 -s -w -t random -v /dev/sdx # shred -v -n 1 /dev/sdx # fdisk /dev/sdx ... "n" "p" "1" "return" "return" "w" # cryptsetup luksFormat /dev/sdx1 ... # cryptsetup luksOpen /dev/sdx1 sdx1 ... # ls -l /dev/mapper/ total 0 crw-rw---- 1 root root 10, 60 2008-10-04 18:44 control brw-rw---- 1 root disk 254, 0 2008-10-04 23:55 sdx1 # mkfs.vfat /dev/mapper/sdx1 ... # cryptsetup luksClose sdx1
Then, it can be mounted just like normal one on to /media/<disk_label>
, except for asking password (see Section 11.1.10, “Removable mass storage device”) under modern desktop environment, such as Gnome using gnome-mount
(1). The difference is that every data written to it is encrypted. You may alternatively format media in different file format, e.g., ext3 with "mkfs.ext3 /dev/sdx1
".
![]() |
Note |
---|---|
If you are really paranoid for the security of data, you may need to overwrite multiple times in the above example. This operation is very time consuming though. |
If your original /etc/fstab
contains:
/dev/sda7 swap sw 0 0
then you can enable encrypted swap partition using dm-crypt as
# swapoff -a # echo "cswap /dev/sda7 /dev/urandom swap" >> /etc/crypttab # perl -i -p -e "s/\/dev\/sda7/\/dev\/mapper\/cswap/" /etc/fstab # swapon -a
You can encrypt files written under "~/Private/
" automatically using eCryptfs and the ecryptfs-utils
package.
run "ecryptfs-setup-private
" and set up "~/Private/
" by following prompts.
activate "~/Private/
" by issuing "ecryptfs-mount-private
".
move sensitive data files to "~/Private/
" and make symlinks.
move sensitive data directories to "~/Private/
" and make symlinks.
do the same for "~/.gnupg
" and other directories containing sensitive data.
create symlink from "~/.ssh
" to "~/Private/.ssh
"
deactivate "~/Private/
" by issuing "ecryptfs-umount-private
".
activate "~/Private/
" by issuing "ecryptfs-mount-private
" as you need encrypted data.
![]() |
Tip |
---|---|
Files and directories with " |
If you use your login password for wrapping encryption keys, you can automate mounting eCryptfs via Pluggable Authentication Module by having active lines in /etc/pam.d/common-auth
as:
auth required pam_unix.so nullok_secure auth required pam_ecryptfs.so unwrap
and active lines in /etc/pam.d/common-session
as:
session required pam_unix.so session optional pam_ecryptfs.so unwrap
This is quite convienient.
![]() |
Caution |
---|---|
If you use your login password for wrapping encryption keys, your encrypted data are as secure as your user login password (see Section 5.3, “Good password”). Unless you are careful to set up a strong password, your data will be at risk when someone runs password cracking software after stealing your laptop (see Section 5.7.4, “Securing the root password”). The |
Program activities can be monitored and controlled using specialized tools.
Table 10.9. List of tools for monitoring and controlling program activities
package |
popcon |
size |
description |
---|---|---|---|
|
V:6, I:86 |
152 |
The |
|
V:87, I:99 |
11448 |
The |
|
V:61, I:99 |
168 |
The |
|
V:0.5, I:7 |
424 |
On Intel-based laptops |
|
V:82, I:99 |
748 |
The |
|
V:51, I:89 |
508 |
The |
|
V:86, I:99 |
320 |
This package run processes according to a schedule (in background). |
|
V:51, I:84 |
220 |
The |
|
V:16, I:92 |
424 |
The |
|
V:9, I:88 |
420 |
The |
|
V:0.3, I:2 |
220 |
The |
|
V:0.02, I:0.15 |
216 |
The |
Display time used by the process invoked by the command.
# time some_command >/dev/null real 0m0.035s # time on wall clock (elapsed real time) user 0m0.000s # time in user mode sys 0m0.020s # time in kernel mode
A nice value is used to control the scheduling priority for the process.
Table 10.10. List of nice values for the scheduling priority.
nice value |
scheduling priority |
---|---|
19 |
lowest priority process (nice) |
0 |
very high priority process for user. |
-20 |
very high priority process for root. (not-nice) |
# nice -19 top # very nice # nice --20 wodim -v -eject speed=2 dev=0,0 disk.img # very fast
Sometimes an extreme nice value does more harm than good to the system. Use this command carefully.
The ps
(1) command on the Debian support both BSD and SystemV features and helps to identify the process activity statically.
Table 10.11. List of ps command styles.
style |
typical command |
feature |
---|---|---|
BSD |
|
display %CPU %MEM |
System V |
|
display PPID |
For the zombie (defunct) children process, you can kill them by the parent process ID identified in the (PPID
) field.
The pstree
(1) command display a tree of processes.
The top
(1) command on the Debian has rich features and helps to identify what process is acting funny dynamically.
Table 10.12. List of commands for top.
command key |
response |
---|---|
|
To show help. |
|
To set/reset display field. |
|
To reorder display field. |
|
To set sort key field. |
|
To kill a process. |
|
To renice a process. |
|
To quit the |
You can list all files opened by a process with a process ID (PID), e.g. 1 as:
$ sudo lsof -p 1
PID=1 is usually init
program.
You can trace program activity with strace
(1), ltrace
(1), or xtrace
(1) commands for system calls and signals, library calls, or communication between X11 client and server. For example:
$ sudo strace ls ...
You can also identify processes using files or sockets by fuser
(1). For example:
$ sudo fuser -v /var/log/mail.log USER PID ACCESS COMMAND /var/log/mail.log: root 2946 F.... syslogd
You see that file /var/log/mail.log
is open for writing by the syslogd
(8) command.
$ sudo fuser -v smtp/tcp USER PID ACCESS COMMAND smtp/tcp: Debian-exim 3379 F.... exim4
Now you know your system runs exim4
(8) to handle TCP connections to SMTP port (25).
The watch
(1) command executes a program repeatedly with a constant interval while showing its output in fullscreen.
$ watch w
This will display who is logged on to the system updated every 2 seconds.
There are several ways to repeat a command looping over files matching some condition, e.g. matching glob pattern "*.ext
".
for x in *.ext; do if [ -f "$x"]; then command "$x" ; fi; done
find
(1) and xargs
(1) combination:
find . -type f -maxdepth 1 -name '*.ext' -print0 | xargs -0 -n 1 command
find
(1) with "-exec
" option with a command:
find . -type f -maxdepth 1 -name '*.ext' -exec command '{}' \;
find
(1) with "-exec
" option with a short shell script:
find . -type f -maxdepth 1 -name '*.ext' -exec sh -c "command '{}' && echo 'successful'" \;
The above examples are written to ensure proper handling of funny file names such as ones containing spaces. See Section 11.1.5, “Idioms for the selection of files” for more advance uses of find
(1).
You can set up to start a process from graphical user interface (GUI).
Under Gnome desktop environment, a program program can be started with proper argument by drag-and-drop of an icon to the launcher icon or by "Open with ..." menu with right clicking. KDE can do the equivalent, too. Here is an example for Gnome to set up mc
program started in gnome-terminal
:
create an executable program "mc-term
" as:
# cat >/usr/local/mc-term <<EOF #!/bin/sh gnome-terminal -e "mc $1" EOF # chmod 755 /usr/local/mc-term
right clicking desktop space to select "Create Launcher ...
"
set "Type" to "Application
"
set "Name" to "mc
"
set "Command" to "mc-term %f
"
click "OK"
right click folder to select "Open with Other Application ...
"
click open "Use a custom command" dialog and enter "mc-term %f
"
click "Open".
![]() |
Tip |
---|---|
Launcher is a file at " |
Some programs start another program automatically. Here are check points for customizing this process:
configuration file of the parent program such as "/etc/mc/mc.ext
".
system configuration menu such as "System" -> "Preferences" -> "Preferred Application" for Gnome.
environment variables such as "BROWSER
", "EDITOR
", "VISUAL
", and "PAGER
" (see eviron
(7)).
the update-alternatives
(8) system for programs such as "editor
", "view
", "x-www-browser
", "gnome-www-browser
", and "www-browser
" (see Section 2.4.7, “Setting a default text editor”).
the "$HOME/.mailcap
" and "/etc/mailcap
" file contents which associate MIME type with program (see mailcap
(5)).
the the "$HOME/.mime.types
" and "/etc/mime.types
" file contents which associate file name extension with MIME type (see run-mailcap
(1)).
![]() |
Tip |
---|---|
The |
![]() |
Tip |
---|---|
The |
Use the kill
(1) command to kill (or send a signal to) a process by the process ID.
Use killall
(1) or pkill
(1) commands to do the same by the process command name and other attributes.
Table 10.13. List of frequently used signals for kill command.
signal value |
signal name |
function |
---|---|---|
1 |
HUP |
restart daemon |
15 |
TERM |
normal kill |
9 |
KILL |
kill hard |
Run the at
(1) command to schedule a one-time job:
$ echo 'command -args'| at 3:40 monday
Use cron
(8) to schedule tasks regularly. See crontab
(1) and crontab
(5).
Run the command "crontab -e
" to create or edit a crontab file to set up regularly scheduled events.
Example of a crontab file:
# use /bin/sh to run commands, no matter what /etc/passwd says SHELL=/bin/sh # mail any output to paul, no matter whose crontab this is MAILTO=paul # Min Hour DayOfMonth Month DayOfWeek command (Day... are OR'ed) # run at 00:05, every day 5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1 # run at 14:15 on the first of every month -- output mailed to paul 15 14 1 * * $HOME/bin/monthly # run at 22:00 on weekdays(1-5), annoy Joe. % for newline, last % for cc: 0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%.%% 23 */2 1 2 * echo "run 23 minutes after 0am, 2am, 4am ..., on Feb 1" 5 4 * * sun echo "run at 04:05 every sunday" # run at 03:40 on the first Monday of each month 40 3 1-7 * * [ "$(date +%a)" == "Mon" ] && command -args
![]() |
Tip |
---|---|
For the system not running continuously, install the |
Insurance against system malfunction is provided by the kernel compile option "Magic SysRq key" (SAK key) which is now the default for the Debian kernel. Pressing Alt-SysRq followed by one of the following keys does the magic of rescuing control of the system:
Table 10.14. List of SAK command keys.
key following Alt-SysRq |
function |
---|---|
|
Unraw restores the keyboard after things like X crashes. |
|
Changing the console loglevel to 0 reduces error messages. |
|
SAK (system attention key) kills all processes on the current virtual console. |
|
Send a SIGTERM to all processes, except for |
|
Send a SIGKILL to all processes, except for |
|
Sync all mounted filesystems. |
|
Remount all mounted filesystems read-only (umount). |
|
Reboot the system without syncing or unmounting. |
The combination of "Alt-SysRq s", "Alt-SysRq u", and "Alt-SysRq r" is good for getting out of really bad situations.
See /usr/share/doc/linux-doc-2.6.*/Documentation/sysrq.txt.gz
.
![]() |
Caution |
---|---|
The Alt-SysRq feature may be considered a security risk by allowing users access to root-privileged functions. Placing " |
![]() |
Tip |
---|---|
From SSH terminal etc., you can use the Alt-SysRq feature by writing to the |
You can send message to everyone who is logged on to the system with the wall
(1) command:
$ echo "We are shutting down in 1 hour" | wall
For the PCI-like devices (AGP, PCI-Express, CardBus, ExpressCard, etc.), lspci
(8) command (probably with "-nn
" option) is a good start for the hardware identification
Alternatively, you can identify the hardware by reading contents of /proc/bus/pci/devices
or browsing directory tree under /sys/bus/pci
(see Section 2.2.12, “procfs and sysfs”).
Table 10.15. List of hardware identification tools.
package |
popcon |
size |
description |
---|---|---|---|
|
V:43, I:92 |
708 |
Linux PCI Utilities, |
|
V:27, I:97 |
520 |
Linux USB utilities, |
|
V:1.0, I:16 |
172 |
PCMCIA utilities for Linux 2.6, |
|
V:0.2, I:1.5 |
484 |
Collection of tools for SCSI hardware management, |
|
V:0.02, I:0.2 |
108 |
Plug and Play BIOS utilities, |
|
V:0.7, I:5 |
116 |
Displays system information from |
|
V:1.1, I:5 |
804 |
Information about hardware configuration, |
|
V:5, I:16 |
928 |
Hardware identification system, |
Although most of the hardware configuration on modern GUI desktop systems such as Gnome and KDE can be managed through accompanying GUI configuration tools, it is a good idea to know some basics methods to configure them.
Table 10.16. List of hardware configuration tools.
package |
popcon |
size |
description |
---|---|---|---|
|
V:42, I:60 |
1980 |
Hardware Abstraction Layer, |
|
V:56, I:96 |
948 |
Linux console font and keytable utilities. |
|
V:21, I:28 |
616 |
X server utilities. |
|
V:52, I:89 |
196 |
Daemon to manage events delivered by the Advanced Configuration and Power Interface (ACPI) |
|
V:3, I:34 |
92 |
Utilities for ACPI devices |
|
V:1.3, I:13 |
144 |
Daemon to manage events delivered by the Advanced Power Management (APM) |
|
V:1.0, I:1.3 |
1800 |
Daemon to manage battery, temperature, ac, cpufreq (SpeedStep, Powernow!) control and monitor with ACPI and APM supports. |
|
V:0.09, I:0.17 |
244 |
Allow idle hard disks to spin down |
|
V:0.09, I:0.12 |
140 |
Puts a laptop to sleep during inactivity |
|
V:10, I:34 |
272 |
Hard disk access optimization. Very effective but dangerous. You must read |
|
V:5, I:14 |
828 |
Control and monitor storage systems using S.M.A.R.T. |
|
V:2, I:5 |
176 |
Collection of tools for serial port management. |
|
V:0.5, I:4 |
248 |
Collection of tools for memory hardware management. |
|
V:0.2, I:1.5 |
484 |
Collection of tools for SCSI hardware management. |
|
V:0.3, I:0.5 |
208 |
A program to configure touchpad devices |
|
V:0.11, I:0.5 |
64 |
Compact disc drive access optimization. |
|
I:0.2 |
68 |
Larger mouse cursors for X |
|
V:0.02, I:0.10 |
88 |
Simple front end to powertweak, |
Here, ACPI is a newer framework for the power management system than APM.
The following will set system and hardware time to MM/DD hh:mm, CCYY.
# date MMDDhhmmCCYY # hwclock --utc --systohc # hwclock --show
Times are normally displayed in the local time on the Debian system but the hardware and system time usually use UTC.
If the hardware (BIOS) time is set to GMT, change the setting to UTC=yes
in the /etc/default/rcS
.
If you wish to update system time via network, consider to use the NTP service with the packages such as ntp
, ntpdate
, and chrony
. See:
The ntp-doc
package
![]() |
Tip |
---|---|
The |
There are several components to configure character console and ncurses
(3) system features:
the terminfo
(5) file
the TERM
(7) environment variable
the setterm
(1) command
the stty
(1) command
the tic
(1) command
the toe
(1) command
If the terminfo
entry for xterm
doesn't work with a non-Debian xterm
, change your terminal type from xterm
to one of the feature-limited versions such as xterm-r6
when you log in to a Debian system remotely. See /usr/share/doc/libncurses5/FAQ
for more. dumb
is the lowest common denominator for terminfo
.
Device drivers for sound cards for current Linux 2.6 are provided by Advanced Linux Sound Architecture (ALSA). ALSA provides emulation mode for previous Open Sound System (OSS) for compatibility.
Run "dpkg-reconfigure linux-sound-base
" to select the sound system to use ALSA via blacklisting of kernel modules. Unless you have very new sound hardware, udev infrastructure should configure your sound system.
![]() |
Tip |
---|---|
Use " |
![]() |
Tip |
---|---|
If you can not get sound, your speaker may be connected to a muted output. Modern sound system has many outputs. The |
Application softwares may be configured not only to access sound devices directly but also to access them via some standardized sound server system.
Table 10.17. List of sound packages
package |
pocon |
size |
description |
---|---|---|---|
|
V:20, I:58 |
136 |
Base package for ALSA and OSS sound systems |
|
I:58 |
456 |
ALSA driver configuration files |
|
V:38, I:58 |
1984 |
Utilities for configuring and using ALSA |
|
V:17, I:25 |
60 |
OSS compatibility under ALSA preventing " |
|
V:27, I:67 |
68 |
Enlightened Sound Daemon (ESD) common (Enlightenment and GNOME) |
|
V:4, I:35 |
84 |
Enlightened Sound Daemon (ESD) server (Enlightenment and GNOME) |
|
V:10, I:19 |
168 |
Enlightened Sound Daemon (ESD) client (Enlightenment and GNOME) |
|
V:2, I:2 |
96 |
Enlightened Sound Daemon (ESD) library Enlightenment and GNOME) |
|
V:39, I:64 |
92 |
Enlightened Sound Daemon (ESD) library (Enlightenment and GNOME) - OSS |
|
I:15 |
36 |
aRts server (KDE) |
|
V:22, I:45 |
6180 |
aRts library (KDE) |
|
V:21, I:50 |
72 |
aRts library (KDE) |
|
V:1.5, I:6 |
400 |
JACK Audio Connection Kit. (JACK) server (low latency) |
|
V:14, I:26 |
540 |
JACK Audio Connection Kit. (JACK) library (low latency) |
|
I:32 |
48 |
JACK Audio Connection Kit. (JACK) library (low latency) |
|
V:0.18, I:0.3 |
328 |
Network Audio System (NAS) server |
|
V:24, I:63 |
204 |
Network Audio System (NAS) library |
|
V:0.8, I:2 |
1264 |
PulseAudio server, replacement for ESD |
|
V:3, I:27 |
508 |
PulseAudio client library, replacement for ESD |
|
V:0.7, I:1.8 |
612 |
PulseAudio server library, replacement for ESD |
|
V:18, I:61 |
2644 |
GStreamer: Gnome sound engine |
|
V:6, I:51 |
24 |
xine: KDE older sound engine |
|
I:5 |
472 |
Phonon: KDE new sound engine |
There is usually a common sound engine for each popular desktop environment. Each sound engine used by the application can choose to connect to different sound servers.
For disabling the screen saver, use following commands.
Table 10.18. List of commands for disabling the screen saver.
environment |
command |
---|---|
The Linux console |
|
The X Window by turning off screensaver |
|
The X Window by disabling dpms |
|
The X Window by GUI configuration of screen saver |
|
One can always unplug the PC speaker. Removing pcspkr
kernel module does this for you.
The following will prevent the readline
program used by the bash
to beep when encountering "\a" (ASCII=7):
$ echo "set bell-style none">> ~/.inputrc
The kernel boot message in the /var/log/dmesg
contains the total exact size of available memory.
The free
(1) and top
(1) commands display information on memory resources on the running system.
$ grep '^Memory' /var/log/dmesg Memory: 990528k/1016784k available (1975k kernel code, 25868k reserved, 931k data, 296k init) $ free -k total used free shared buffers cached Mem: 997184 976928 20256 0 129592 171932 -/+ buffers/cache: 675404 321780 Swap: 4545576 4 4545572
For my MacBook with 1GB=1048576k DRAM (video system steals some of this):
Table 10.19. List of memory sizes reported.
report |
size |
---|---|
Total size in dmesg |
1016784k = 1GB - 31792k |
Free in dmesg |
990528k |
Total under shell |
997184k |
Free under shell |
20256k |
Do not worry about the large size of "used
" and the small size of "free
" in the "Mem:
" line, but read the one under them (675404 and 321780 in the example below) and relax.
Poor system maintenance may expose your system to external exploitation.
For system security and integrity check, you should start with:
debsums
package: See debsums
(1) and Section 3.5.2, “Top level Release file and authenticity”.
chkrootkit
package: See chkrootkit
(1).
clamav
package family: See clamscan
(1) and freahclam
(1).
Table 10.20. List of tools for system security and integrity check
package |
popcon |
size |
description |
---|---|---|---|
|
V:3, I:4 |
264 |
This mails anomalies in the system logfiles to the administrator |
|
V:2, I:3 |
236 |
This verifies installed package files against MD5 checksums. |
|
V:2, I:6 |
852 |
Rootkit detector. |
|
V:2, I:10 |
420 |
Anti-virus utility for Unix - command-line interface. |
|
V:0.8, I:1.0 |
3072 |
Report system security vulnerabilities |
|
V:0.5, I:0.7 |
5020 |
File and directory integrity checker |
|
V:0.4, I:1.8 |
476 |
Active password cracking tool |
|
V:0.3, I:0.5 |
1112 |
Advanced Intrusion Detection Environment - static binary |
|
V:0.2, I:0.6 |
1484 |
Security hardening tool |
|
V:0.13, I:0.2 |
440 |
A file integrity verification program |
|
V:0.05, I:0.3 |
204 |
Password guessing program |
Here is a simple script to check for typical world writable incorrect file permissions.
# find / -perm 777 -a \! -type s -a \! -type l -a \! \( -type d -a -perm 1777 \)
![]() |
Caution |
---|---|
Since the |
Debian distributes modularized Linux kernel as packages for supported architectures.
There are few notable features on Linux kernel 2.6 compared to 2.4.
Devices are created by the udev system (see Section 4.5.10, “The udev system”).
Read/write accesses to IDE CD/DVD devices do not use the ide-scsi
module.
Network packet filtering functions use iptable
kernel modules.
Most normal programs don't need kernel headers and in fact may break if you use them directly for compiling. They should be compiled against the headers in /usr/include/linux
and /usr/include/asm
provided by the libc6-dev
package (created from the glibc
source package) on the Debian system.
![]() |
Note |
---|---|
For compiling some kernel-specific programs such as the kernel modules from the external source and the automounter daemon ( |
Debian has its own method of compiling the kernel and related modules.
Table 10.21. List of key packages to be installed for the kernel recompilation on the Debian system
package |
popcon |
size |
description |
---|---|---|---|
|
I:40 |
48 |
essential packages for building Debian packages: |
|
V:51, I:81 |
132 |
compress and decompress utilities for bz2 files |
|
V:4, I:28 |
6812 |
developer's libraries and docs for ncurses |
|
V:4, I:8 |
7164 |
git: distributed revision control system used by the Linux kernel |
|
V:4, I:26 |
456 |
provide fakeroot environment for building package as non-root |
|
V:29, I:96 |
412 |
tool to build an initramfs (Debian specific) |
|
V:3, I:18 |
2304 |
tool to build Linux kernel packages (Debian specific) |
|
V:3, I:22 |
512 |
tool to help build module packages (Debian specific) |
|
V:2, I:13 |
1592 |
helper scripts for a Debian Package maintainer (Debian specific) |
|
I:0.15 |
128 |
Linux kernel source tree for building Debian kernel images (Debian specific) |
If you use initrd
in Section 4.3, “Stage 2: the boot loader”, make sure to read the related information in initramfs-tools
(8), update-initramfs
(8), mkinitramfs
(8) and initramfs.conf
(5).
![]() |
Warning |
---|---|
Do not put symlinks to the directories in the source tree (e.g. |
![]() |
Note |
---|---|
When compiling the latest Linux kernel on the Debian |
The Debian standard method for compiling kernel source to create a custom kernel package uses make-kpkg
(1) command. The official documentation is in (the bottom of) /usr/share/doc/kernel-package/README.gz
. See kernel-pkg.conf
(5) and kernel-img.conf
(5) for customization.
Here is an example for amd64 system:
# aptitude install linux-tree-<version> $ cd /usr/src $ tar -xjvf linux-source-<version>.tar.bz2 $ cd linux-source-<version> $ cp /boot/config-<oldversion> .config $ make menuconfig ... $ make-kpkg clean $ fakeroot make-kpkg --append_to_version -amd64 --initrd --revision=rev.01 kernel_image modules_image $ cd .. # dpkg -i linux-image*.deb
reboot to new kernel with "shutdown -r now
" .
![]() |
Caution |
---|---|
When you intend to create a non-modularized kernel compiled only for one machine, invoke |
The Debian standard method for creating and installing a custom module package for a custom kernel package uses module-assistant
(8) command and module-source packages. For example, following will build the unionfs
kernel module package and installs it.
$ sudo aptitude install module-assistant ... $ sudo aptitude install unionfs-source unionfs-tools unionfs-utils $ sudo m-a update $ sudo m-a prepare $ sudo m-a auto-install unionfs ... $ sudo apt-get autoremove
You can still build Linux kernel from the pristine sources with the classic method. You must take care the details of the system configuration manually.
$ cd /usr/src $ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-<version>.tar.bz2 $ tar -xjvf linux-<version>.tar.bz2 $ cd linux-<version> $ cp /boot/config-<version> .config $ make menuconfig ... $ make dep; make bzImage $ make modules # cp ./arch/x86_64/boot/bzImage /boot/vmlinuz-<version> # make modules_install # depmod -a # update-initramfs -c -k <version>
edit /etc/lilo.conf
and run /sbin/lilo
, if you use lilo
.
edit /boot/grub/menu.lst
, if you use grub
.
reboot to new kernel with "shutdown -r now
" .
Although most of hardware drivers are available as free software and as a part of the Debian system, you may need to load some non-free external drivers to support some hardwares, such as Winmodem, on your system.
Check pertinent resources:
http://en.wikipedia.org/wiki/Comparison_of_open_source_wireless_drivers
Google or other search engines with keyword "Linmodem".
http://madwifi-project.org (there is ath5k which contains free drivers)
The chroot
(8) program is most basic way to run different instances of the GNU/Linux environment on a single system simultaneously without rebooting. I will explain simple chroot systems in the following as examples.
For serious chroot setup with the detail configuration, please consider to use the specialized schroot
package.
A chroot Debian environment can easily be created by the debootstrap
or cdebootstrap
command.
For example, the following will create a sid
chroot on /sid-root
while having fast Internet access:
main # debootstrap sid /sid-root http://ftp.debian.org/debian/
watch it download the whole system
main # echo "proc-sid /sid-root/proc proc none 0 0" >> /etc/fstab main # echo "devpts-sid /sid-root/dev/pts devpts defaults 0 0" >> /etc/fstab main # mount -a main # cp -f /etc/passwd /sid-root/etc/passwd main # cp -f /etc/shadow /sid-root/etc/shadow main # cp -f /etc/group /sid-root/etc/group main # cp -f /etc/hosts /sid-root/etc/hosts main # chroot /sid-root /bin/bash chroot # cd /dev; /sbin/MAKEDEV generic ; cd - chroot # vi /etc/apt/sources.list
point the source to unstable
chroot # aptitude update ... chroot # aptitude install locales ...
add "en_US.UTF-8" as locale and make it default
Do you want to continue? [Y/n/?] y chroot # aptitude install mc vim ... Do you want to continue? [Y/n/?] y ... chroot # exit main #
At this point you should have a fully working Debian sid system, where you can play around without fear of affecting your main Debian installation.
![]() |
Caution |
---|---|
If you use bind mount for directories such as home directory in the chroot, you must be careful for its side effects. I heard people lost their home directory after executing " |
This debootstrap
trick can also be used to install Debian to a system without using a Debian install disk, but instead from another GNU/Linux distribution.
Typing "chroot /sid-root /bin/bash
" is easy, but it retains all sorts of environment variables that you may not want, and has other issues. A much better approach is to run another login process on a separate virtual terminal where you can log in to the chroot directly.
Since on default Debian systems tty1
to tty6
run Linux consoles and tty7
runs the X Window System, let's set up tty8
for a chrooted console as an example. After creating a chroot system, type from the root shell of the main system:
main # echo "8:23:respawn:/usr/sbin/chroot /sid-root /sbin/getty 38400 tty8" >> /etc/inittab main # init q
reload init
You want to run the latest X and GNOME safely in your chroot? That's entirely possible! The following example will make GDM run on virtual terminal vt9
.
First install a chroot system. From the root of the main system, copy key configuration files to the chroot system.
main # cp /etc/X11/xorg.conf /sid-root/etc/X11/xorg.conf main # chroot /sid-root chroot # cd /dev; /sbin/MAKEDEV generic ; cd - chroot # aptitude install gdm gnome x-window-system chroot # vim /etc/gdm/gdm.conf
change "[servers]
" section with "s/vt7/vt9/
" to make the first virtual console in the chroot from vt7
to vt9
.
chroot # /etc/init.d/gdm start
Now you can easily switch back and forth between full X environments in your chroot and your main system just by switching between Linux virtual terminals; e.g. by using Ctrl-Alt-F7 and Ctrl-Alt-F9. Have fun!
A chroot environment for another Linux distribution can easily be created. You install a system into separate partitions using the installer of the other distribution. If its root partition is in /dev/hda9
:
main # cd / ; mkdir /other-dist main # mount -t ext3 /dev/hda9 /other-dist main # chroot /other-dist /bin/bash
There is a more specialized chroot package, pbuilder
, which constructs a chroot system and builds a package inside the chroot. It is an ideal system to use to check that a package's build-dependencies are correct, and to be sure that unnecessary and wrong build dependencies will not exist in the resulting package.
There are several system virtualization and emulation related packages in Debian beyond simple chroot.
Table 10.22. List of virtualization tools
package |
pocon |
size |
description |
---|---|---|---|
|
V:1.0, I:1.7 |
1900 |
Specialized tool for executing Debian binary packages in chroot |
|
V:0.08, I:0.3 |
452 |
Tool for building Debian binary packages from Debian sources |
|
V:0.5, I:2 |
1116 |
Personal package builder for Debian packages |
|
V:1.5, I:12 |
260 |
Bootstrap a basic Debian system (written in sh) |
|
V:0.6, I:3 |
156 |
Bootstrap a Debian system (written in C) |
|
V:0.04, I:0.2 |
156 |
A tool for building complete Linux filesystem images |
|
V:0.11, I:0.5 |
17816 |
User-mode Linux (kernel) |
|
V:0.2, I:1.9 |
996 |
Tools to manage debian XEN virtual server |
|
V:0.08, I:0.6 |
3072 |
Bochs: IA-32 PC emulator |
|
V:0.8, I:6 |
30752 |
Qemu: fast generic processor emulator |
|
V:2, I:2 |
22272 |
VirtualBox: x86 virtualization solution on i386 and amd64 |
|
V:2, I:15 |
96 |
Wine: Windows API Implementation (standard suite) |
|
V:0.6, I:3 |
2240 |
DOSBox: x86 emulator with Tandy/Herc/CGA/EGA/VGA/SVGA graphics, sound and DOS |
|
V:0.6, I:1.0 |
2928 |
Linux-VServer virtual private servers - user-space tools |
|
V:0.3, I:0.7 |
1120 |
OpenVZ server virtualization solution - control tools |
|
V:0.3, I:0.7 |
272 |
OpenVZ server virtualization solution - quota tools |
See Wikipedia article http://en.wikipedia.org/wiki/Comparison_of_virtual_machines for detail comparison of different virtualization solutions.