Archive for July, 2007

Inside Linux The following shows a sample nfs (Web hosting services)

Sunday, July 15th, 2007

Inside Linux The following shows a sample nfs script. # . /etc/rc.config nfs=no while read where what type options rest ; do case “$where” in #*|”") ;; *) case “$options” in *noauto*) ;; *) if test “$type” = “nfs” ; then nfs=yes break fi ;; esac esac done < /etc/fstab case `uname -r` in 0.*|1.*|2.0.*) RPCSTATD="" ; RPCLOCKD="" ;; *) test -x /usr/sbin/rpc.kstatd && RPCSTATD=/usr/sbin/rpc.kstatd test -x /usr/sbin/rpc.klockd && RPCLOCKD=/usr/sbin/rpc.klockd ;; esac return=$rc_done case "$1" in start|reload) test "$nfs" = "yes" || exit 0; test -n "$RPCLOCKD" && startproc $RPCLOCKD test -n "$RPCSTATD" && startproc $RPCSTATD echo -n "Importing Network File System (NFS)" mount -at nfs || return=$rc_failed sleep 1 ldconfig -X 2>/dev/null echo -e “$return” ;; stop) test “$nfs” = “yes” && echo -n “Remove Net File System (NFS)” umount -at nfs & sleep 2 test “$nfs” = “yes” && echo -e “$return” ;; restart) $0 stop && $0 start || return=$rc_failed ;; status) mount -t nfs | while read from x point rest ; do echo -e “$from 33[50G$point” done ;; *) echo “Usage: $0 {start|stop|status|reload|restart}” exit 1 esac test “$return” = “$rc_done” || exit 1 exit 0 As mentioned previously, mountd is the mount daemon and nfsd is the NFS server daemon. On your distribution, the daemons may be named rpc.mountd and rpc.nfsd. Be sure to check the documentation for your Linux distribution. Remember, the portmapper must be invoked and running before the mountd and nfsd daemon. Exporting Filesystems There is no broadcast of available filesystems by the server to NFS clients. The NFS server maintains a list of exported filesystems and the restrictions that are applicable for each export, called the filesystem table. When a mount request is received from an NFS client, the NFS server checks the request against its filesystem table. If the filesystem is in the list and the restrictions are satisfied, the server permits the mount. The filesystem table and the contents of the /etc/exports file can be different. The NFS server creates the filesystem table from the contents of the /etc/exports file at the time that it initializes. The filesystem table is not updated by the NFS server unless the system is rebooted or the exportfs command is executed. page 220 #BREAK# Inside Linux The exportfs command is used to maintain the table of exported filesystems. On some Linux distributions, the table exists as the /var/lib/nfs/xtab file. Unfortunately, not all Linux distributions have the exportfs command installed. If you do not have one, you can create a script to perform the logic. The following demonstrates the minimum for the script: #!/bin/bash killall -HUP /usr/sbin/rpc.mountd killall -HUP /usr/sbin/rpc.nfsd Be sure that the command name for each daemon is correct for your Linux distribution and that the directory path is appropriate. The HUP signal is sent to the daemons, effectively telling them to reinitialize. The net effect is that the /etc/exports file is read from disk by the NFS server and the filesystem table is regenerated. For some Linux distributions, the rcnfsserver command can be executed to update the filesystem table if changes have been applied to the /etc/exports file. A man page may not exist for this command, so do not count on using that method for verification of rcnfsserver. For example, for the installed version of SuSE Linux 6.3 (on my machine), no man entry exists for rcnfsserver, but executing the which command reveals the file’s existence, as shown in the following dialog: stimpy $ man rcnfsserver No manual entry for rcnfsserver stimpy $ which rcnfsserver /usr/sbin/rcnfsserver stimpy $ rcnfsserver Usage: /usr/sbin/rcnfsserver {start|stop|status|reload|restart} stimpy $ Another method of updating the filesystem table is to stop and start the daemons using the nfs command. The following dialog demonstrates this: stimpy $ cd /etc/rc.d/init.d stimpy $ nfs stop stimpy $ nfs start stimpy $ If the restart option is available for the nfs command, you can invoke the command that way, as in the following dialog. The previous section, “The mountd and nfsd Daemons,” discusses the nfs command in more detail. stimpy $ cd /etc/rc.d/init.d stimpy $ nfs restart stimpy $ Before you create any script to force a reread of the /etc/exports file, check to see if either the exportfs or rcnfsserver command exists. Using the NFS Client There is not much to using an NFS client. The only requirements are that an NFS server is running, that at least one filesystem exists to mount, and the proper restrictions are satisfied. You use the mount command to import a filesystem. This is what the term “NFS client” refers to. The mount command is used to execute a request to the NFS Server for importing a remote filesystem. The basic usage for the mount command is shown in the following: mount -t type device dir This tells the system to attach (or mount) the filesystem found on device (device), which is of type type, at the dir directory. Conversely, you use the umount command to unmount (or detach) the filesystem. The following dialog demonstrates the use of the mount command to import an NFS filesystem: stimpy $ mount -t nfs sillyhost:home/bill /home/bill Some distributions of Linux prefer that you execute the mount command with the -F option, as shown in the following dialog: stimpy $ mount -F nfs sillyhost:home/bill /home/bill Be sure to check the mount man page for the proper syntax for your Linux distribution. page 221 #BREAK# Inside Linux To enforce that the system mounts an nfs filesystem at boot, you should edit the /etc/fstab file as usual. You should ensure that the -t nfs type is specified. In the following dialog, the contents of the /etc/fstab file shows an entry to mount an nfs type filesystem. stimpy $ cat /etc/fstab /dev/hda7 swap swap defaults 0 0 /dev/hda6 / ext2 defaults 1 1 /dev/hdc /cdrom iso9660 ro,noauto,user,exec 0 0 /dev/hda5 /mnt/rh ext2 defaults 1 1 /dev/fd0 /flop auto noauto,user 0 0 sillyhost:home/bill /home/bill nfs rsize=8192,wsize=8192,timeo=14,intr 0 0 none /proc proc defaults 0 0 Using our previous example, the sillyhost… entry will be automatically mounted at system boot. This sample should work for most all Linux distributions. You should always check the documentation for your distribution to be certain. You can also easily mount a filesystem by specifying the mount point, if the device is listed in the /etc/fstab file. For example, referring to the previous /etc/fstab sample, if you want to mount the /dev/hda5 device, you simply issue the mount command as shown in the following dialog: stimpy $ mount /mnt/rh stimpy $ Because the entry exists in the /etc/fstab file, all the proper parameters are available to mount the device to the identified mount point. From here, all you do is access the filesystem as you normally would with any mounted filesystem. The mount Command The following section details the mount command. The mount command, these days, consists of many options. I hope to clarify the usage for mount. The official usage for the mount command is shown as follows: mount [-hV] mount -a [-fFnrsvw] [-t vfstype] mount [-fnrsvw] [-o options [,…]] device | dir mount [-fnrsvw] [-t vfstype] [-o options] device dir As you can see, four variant usages exist for the mount command, each one for a specific application. All UNIX and Linux files are organized within a filesystem that is a hierarchical tree starting at /, known as root. This is not to be confused with the root user. Normally, the filesystem consists of more than one device; the mount command is used to import (or attach) these devices to the root filesystem. To unmount a filesystem, you use the umount command. The most common form of usage for mount is as follows: mount -t type device dir This execution mounts the device device of type -t type onto the dir directory. The local directory (mount point) becomes the root of the mounted device. Ironically, four usages for the mount command do not perform a device mount. They are as follows: mount -h mount -V mount [-t type] mount The first form prints only help text associated with the mount command. The second form displays the version of mount and exits. The third form of mount lists all the filesystems of the type identified that are mounted. The last form lists all the filesystems that are mounted. The form of the identified device is a block special device by filename. Some examples are /dev/hdc for a CD-ROM and /dev/fd0 for a floppy disk. Another example is /dev/hdb11 representing the tenth logical drive on the second IDE hard drive or /dev/hda5 representing the fourth logical drive on the first hard disk (these do exist on my system). You are not restricted to identifying a device as previously shown. You can also identify devices as some.domain.name:/directoryName. page 222 #BREAK# Inside Linux You can add devices that are continually mounted at boot to the /etc/fstab file. The /etc/fstab file can be helpful in several ways. If an entry for a device exists in the file, you can mount it manually by specifying only the device or the mount point. The following example demonstrates this. The first dialog shows an entry in the /etc/fstab file: stimpy $ cat /etc/fstab … /dev/hda5 /mnt/rh ext2 defaults 1 1 … Assuming that the /dev/hda5 entry exists as shown, you can mount the device onto the /mnt/rh directory by issuing one of the two following mount commands: stimpy $ mount /dev/hda5 stimpy $ mount /mnt/rh You do not need to specify the device type, device, and mount points because this information is already specified in the /etc/fstab file. Customarily, the superuser (root) is the only user that can execute the mount command. With the /etc/fstab file, however, you can use the user option, allowing anyone to mount the corresponding device. You should know that only the user that mounted the device is allowed to unmount the device. If you want any user to be able to unmount a device, you should use the users option rather than the user option. Options for mount A whole host of options are available for the mount command. In this section, I explore the options available, providing descriptions for each. Table 12.4 outlines the various options available to you. Table 12.4. Options for the mount Command Option Description -V Show the version. -h Show a help message. -v Verbose mode. -F This option will fork an individual invocation of mount for each device. The advantage is speed. If you are mounting NFS devices, the timeouts will be concurrent. The downside is that the order of mounts is arbitrary. -f This option is a sort of “test” (or fake) mode. If you are having problems with mount, this option acts as a debugger (use with the -v option). -n Perform the mount and exclude writing the entry in /etc/mtab. -s Mainly used for the Linux autofs-based automounter. This tells mount to allow for awkward mount options versus failing. -r Mount the filesystem as read-only; synonymous with the -o ro option. -w Mount the filesystem as read/write; synonymous with -o rw. This is the default. -L label Mount the partition possessing the specified label. -U uuid Mount the partition possessing the specified uuid. -t vfstype This option identifies the filesystem type. The currently supported filesystem types are (shown in linux/fs/filesystems.c) adfs, affs, autofs, coda, coherent, devpts, ext, ext2, hfs, hpfs, iso9660, minix, msdos, ncpfs, nfs, ntfs, proc, qnx4, romfs, smbfs, sysv, ufs, umsdos, vfat, xenix, xiafs. The coherent sysv, and xenix types are equivalent. Both the coherent and xenix types will be removed sometime in the future. page 223 #BREAK# Inside Linux Option Description -o Options are specified with a -o flag, using a comma to separate the options. The options are: atime Update the inode access time for every access; the default. auto Specify that the mount is acceptable with the -a option. defaults Use the default options, which are rw, suid, dev, exec, auto, nouser, and async. dev Interpret character or block special devices. exec Allow execution of binaries. noatime Do not allow updates to the inode access times on the filesystem. noauto The filesystem can only be explicitly mounted. nodev Do not interpret character or block special devices. noexec Disallow the execution of binaries on the mounted filesystem. nosuid Disallow set-user-id or set-group-id bits to occur. nouser Prohibit a non-root user to mount the filesystem; this is the default. remount Used to attempt a remount of an already mounted filesystem. Used to change the mount flags for a filesystem. ro Mount the filesystem as read-only. rw Mount the filesystem as read/write. sync Synchronize I/O to the filesystem. user Permit an ordinary user to mount the filesystem; implies the options noexec, nosuid, and nodev. The man page for the mount command provides more level of detail for filesystem-specific mounts. Be sure to refer to it for any special needs you may have. page 224 #BREAK# Inside Linux Optimizing NFS on Low-Bandwidth Connections So many variables are at work when you analyze network activity that a whole chapter can be written about it. This section touches on only three options for adjusting the performance of NFS on low- bandwidth connections. The section is short and sweet to keep things simple. Admittedly, the NFS protocol is a sluggish protocol. Therefore, if you throw NFS over a sluggish line such as a modem or ISDN line, expect poor performance. Some of the TCP/IP protocols, such as FTP, are quicker than NFS. The advantage to using NFS is that you do not have to copy files back and forth as you do with FTP. You access the mounted filesystems as if they were native to the machine. You will have to adjust the NFS parameters to allow its use over sluggish lines. If you do not adjust the settings, NFS will report errors. First, you should refrain from using the soft mount option, because timeouts will begin to surface. Using the hard mount option will force retries. Two other options need to be altered: retrans and timeo. The format for retrans is retrans=n, in which n is a number. This number represents the number of times to repeat a request before the request is aborted. The format for timeo is timeo=n, in which n is a number. This number represents the RPC timeout period in tenths of a second. The default value is vendor specific, normally ranging from 5 to 10 tenths of a second. Under Linux, the default value is 7 tenths of a second. If a reply does not occur within the time identified by timeo, a minor timeout has occurred. At this time, the timeo value is doubled and the request is re-sent. This process continues until the retrans count is reached. If the client does not receive a reply, a major timeout has occurred. What, then, is the general rule? You should concentrate on varying the timeo value versus the retrans option. Increasing the retrans value will generate more requests to the NFS server, which creates a load on the server. Generally, doubling the timeo value will solve timeout issues. Summary In this chapter, you explored the use of the Network File System (NFS), beginning with an overview of NFS, developed by Sun Microsystems, which advertises an installed base of about eight million systems. NFS is a protocol used for file sharing. NFS consists of a client program and the server program. The NFS server responsibility is to export a file or directory. The NFS client then mounts the required filesystem. Next, I discussed the NFS client, including the automounter. The automounter, which is a client-side enhancement, provides the functionality to automatically mount a filesystem. When the operation is complete, the automounter unmounts the device. The NFS server was discussed next. The role of the NFS server is to make filesystems available by exporting them. I then covered setting up the NFS server, including the portmapper, mountd, and nfsd daemons. The /etc/exports file was covered, which contains the filesystems that the NFS server can export to clients. The NFS client was covered, consisting of the mount command. The success of the mount command is dependent on a running NFS server and a filesystem that can be mounted. Finally, the mount command was discussed in a fair amount of detail. page 225 #BREAK# Inside Linux Chapter 13. Dial-Up Networking Services: SLIP and PPP Linux provides two protocols for serial-line connectivity. Specifically, connectivity is through a modem, whether it is an asynchronous, an ISDN, or a synchronous modem. The two protocols are Serial Line Internet Protocol (SLIP) and Point-to-Point (PPP). Both protocols provide the functionality to establish connectivity with a remote system. The connection is made to an Internet service provider (ISP) or through a gateway. The first part of this chapter focuses on the SLIP protocol. The last part of the chapter examines PPP in detail. Serial Line Internet Protocol (SLIP) In this first section, we examine SLIP in detail. Although PPP is the more widely used dial-up protocol, SLIP continues to be a contender and is supported by most public and private ISPs. We begin the SLIP journey with a brief overview and then jump into the configuration and use of SLIP. SLIP Overview The only hardware requirements for SLIP are a serial port with a FIFO buffer and a modem. If you are using an older computer - an 80286 (or compatible), for example, you may want to check your serial port UART chip set. At a minimum, you want to have a 16550 UART. SLIP supports the TCP/IP protocols over a serial line, whether it’s over a dial-up phone line or a dedicated leased line. You should contact your ISP to obtain the configuration requirements for SLIP connectivity with their system. Configuring SLIP is a fairly straightforward task, and you should be up and running with a minimal amount of fuss. Logically, the network for a SLIP connection consists of only two machines: the SLIP server (provided by your ISP) and the SLIP host, which is your end. We refer to SLIP as a point-to-point network connection because only two endpoints are within the network. Think of SLIP (and PPP) in the same light as the phone system. You pick up your receiver and dial the destination phone number. When your party answers at the other end of the line, a network connection is established. This is also considered a point-to-point connection. If either end disconnects, the network connection is broken. When a connection is established from the host to the server, a logon sequence is initiated to verify your identity. After the verification process is complete, the server furnishes an IP address for your host. This IP address can either be dynamic or static. If the address given to your host is a static address, that address is the same every time you establish a SLIP connection. If your SLIP server provides for dynamic IP addresses, every time you establish a SLIP connection your host will receive a different IP address. The SLIP server will output the IP addresses (among other data) that are assigned for the current session. The Dial-Up IP Protocol (dip) program can capture the dynamic IP address and configure the SLIP driver automatically. The dip program is used to simplify connectivity to the SLIP server. We discuss the use of dip in a section that follows. Some information that you must have available, if you’re using a dial-up connection, includes the ISP’s phone number, the authentication type, whether your ISP provides static or dynamic IP addresses, the ISP domain name, the DNS address list, whether the ISP uses a default gateway or a static gateway, and the maximum connection speed provided by the ISP. If your ISP is using static IP addressing, you will need the IP address assigned to your host. Also, if your ISP is using a static gateway, be sure to obtain the address for it. Beginning with the next section, we discuss the specifics of SLIP configuration under Linux. page 226 #BREAK# Inside Linux SLIP Preflight Checklist Setting up your Linux system to enable SLIP is fairly easy. SLIP configuration is a one-time setup; you should not have to change any of your settings unless you switch to another service provider or your service provider’s configuration changes. In the following sections, we discuss the prerequisites that must be addressed before jumping into the actual use and setup of SLIP. We also examine the various configuration files and requirements of TCP/IP networking to enable SLIP. Verifying the Loopback Interface The loopback interface, sometimes called the dummy interface, is used to provide an IP address for your machine, provided that the only network interface you are using is SLIP or PPP. Also, some applications require the loopback interface in order to run. In addition, other TCP/IP services require an IP address to be functional. If your machine is part of a real ethernet network, the loopback interface is not required. The loopback interface is specified by the network name lo - that is, LO is lowercase. To activate the loopback interface, the ifconfig command is used. The IP address that is designated for loopback is 127.0.0.1; this is an address designated by the InterNIC as reserved for no entity. The syntax for the ifconfig command is ifconfig interface [aftype] options | address … To enable the lo interface with the address 127.0.0.1, you invoke the ifconfig command, as shown in the following dialog: stimpy $ ifconfig lo 127.0.0.1 This will execute ifconfig and its result will be to assign the IP address 127.0.0.1 to the loopback address. You can obtain the status of any active interfaces by invoking ifconfig without any arguments. Check the man page for ifconfig for a complete rundown of options. The following shows the output of an ifconfig inquiry: stimpy $ ifconfig lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:3924 Metric:1 RX packets:25 errors:0 dropped:0 overruns:0 frame:0 TX packets:25 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 ppp0 Link encap:Point-to-Point Protocol inet addr:32.100.174.75 P-t-P:32.96.116.18 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:15 errors:0 dropped:0 overruns:0 frame:0 TX packets:17 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:10 stimpy $ The ifconfig command responds that two interfaces are active: lo and ppp0. Next, you should verify the contents of your /etc/hosts file for the loopback entry. The following is the contents of an /etc/hosts file: # hosts This file describes a number of hostname-to-address # mappings for the TCP/IP subsystem. It is mostly # used at boot time, when no name servers are running. # On small systems, this file can be used instead of a # “named” name server. # IP-Address Full-Qualified-Hostname Short-Hostname 127.0.0.1 localhost The name is not necessarily important as long as you map the corresponding interface name to the logical hostname. Verifying /etc/resolv.conf File The /etc/resolv.conf file is used for name resolution. Entries found in this file designate a DNS server and its associated IP address. More than one DNS server can be specified in this file. As mentioned previously, your ISP can provide you with the DNS server(s) and their associated IP address. The following is sample output from a /etc/resolv.conf file: # /etc/resolv.conf nameserver 165.87.194.244 nameserver 165.87.201.244 page 227 #BREAK# Inside Linux The /etc/resolv.conf file identifies the DNS servers that the resolver can contact to resolve hostnames. You can also set up your Linux to use DNS locally. Many Linux power users do this because it can cut down on name-resolution traffic from your host to the server (and vice versa). Doing this will provoke your DNS to cache DNS lookups, thereby decreasing accesses to the remote DNS for name resolution. Setting Up SLIP As mentioned previously, SLIP is used to establish a network connection between two machines: the server (remote machine) and the host (your machine). SLIP is so firmly entrenched that most ISPs support the protocol. A number of variations of SLIP exist, most notably CSLIP. CSLIP is a compressed version of SLIP that utilizes the Van Jacobson header-compression algorithm on outbound IP packets. The result is increased throughput, especially for interactive network sessions. Before implementing CSLIP, check with your ISP because most ISPs do not support CSLIP. Although SLIP is easy to configure and use, the core mechanism can seem complicated. For most distributions of Linux, the SLIP driver is an integral part of the kernel. This provides faster response and is more efficient. A special tty line discipline, SLIPDISC, is used to convert the specified serial line to SLIP mode. Under this discipline, the serial line cannot be used for any other purpose, other than to communicate with SLIP-aware applications. Effectively, any non-SLIP applications are blocked from using the device when SLIP is active. To establish a SLIP network connection, a pair of programs are utilized, specifically slattach and dip. You cannot use a generic communications application to dial up a remote SLIP server and establish a network connection. Both slattach and dip are used collectively to initiate and establish a SLIP network connection on a serial device using special system calls. The slattach command is used to convert a specified serial line to SLIP mode. Subsequently, the dip command is used to establish the network connection, login negotiation, and to initiate the SLIP connection on the serial line. Using slattach The following shows the syntax for the slattach command: slattach [option] [-c command] [-p protocol] [-s speed] [tty] Several options are available, such as enabling debug output and operating in quiet mode. Check the slattach man page for more details. The -c command switch is used to execute the specified command after the line is hung up (disconnected). This can be utilized to run one or more scripts or to automatically maintain (reestablish) a network connection if the line was severed. The -p protocol switch identifies the protocol to use for the serial line. For many versions of slattach, the default value is cslip (compressed SLIP). Other values that can be specified are adaptive (adaptive CSLIP/SLIP), kiss (a special protocol used to communicate with AX.25 packet radio terminal node controllers), ppp (Point-to-Point Protocol), slip (standard SLIP), and tty. The tty argument is used to return the serial device back into normal serial operation. Do not use the ppp argument to establish a PPP network connection, because PPP requires the pppd daemon to be active on the specified serial line. The adaptive option leaves it to the kernel to decide the type of SLIP protocol that the remote end uses. The -s speed switch simply designates a line speed to be used for the serial device. The following dialog switches /dev/cua3 to assume SLIPDISC line discipline and then attaches the device to the next active SLIP network interface: stimpy $ slattach /dev/cua3 & stimpy $ This assumes that the modem is on /dev/cua3. If no active SLIP connections exist, the line is attached to sl0 (that’s SL0, not S10). The second SLIP connection will be attached to sl1, and so on. Most Linux kernels support up to eight simultaneous SLIP links. page 228 #BREAK# Inside Linux As mentioned previously, the default protocol for slattach assumes CSLIP. The following dialog demonstrates invoking slattach to use normal SLIP: stimpy $ slattach -p slip /dev/cua3 & If you’re not sure which protocol option to use (SLIP or CSLIP), it is recommended to use adaptive because this leaves the decision to the kernel. You may have noticed in the dialogs that the ampersand (&) is used to put slattach into the background. Obviously, if you are invoking slattach from a terminal, you will want that terminal back. Otherwise, slattach will rob the terminal until such time that slattach is terminated. You can terminate slattach using the kill command - simply use the ps command to locate the process ID for slattach. The slattach command is not specific to SLIP. You can use slattach to enable other TCP/IP protocols such as KISS and PPP. Using ifconfig and route After we have a SLIP connection and we have associated our serial device for SLIP usage, we must configure the network interface. This is done the same as with any other (normal) network connection. The two commands we use for this purpose are ifconfig and route. The ifconfig command is used to configure the network interfaces. It is used at boot time to set up the required interfaces. The ifconfig command can be used from the command line, which is usually done only during debugging or testing, or during system tuning. If you execute ifconfig with no arguments, ifconfig shows the status of any active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argument is given, it displays the status of all interfaces, even those that are down. If you recall from the earlier section “Verifying the Loopback Interface,” we used ifconfig to configure the loopback interface. We repeat the syntax here to jog your memory: ifconfig interface [aftype] options | address … The route command is used to manipulate the IP routing table. The core functionality of route is to set up the static routes to specific hosts or networks via an interface. This interface should have already been configured with the ifconfig command. To add a route to the table, use the following syntax for route: route [-v] [-A family] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M] [window W] [irtt I] [reject] [mod] [dyn] [reinstate] [[dev] If] To delete a route from the table, use the following syntax for route: route [-v] [-A family] del [-net|-host] target [gw Gw] [netmask Nm] [metric N] [[dev] If] After control of the line is in possession of the SLIP driver, the network interface will have to be configured. You configure the network interface using the ifconfig and route commands. Let’s assume that the host is stimpy and we dialed a server with the name ren. The following dialog shows the commands to execute: stimpy $ ifconfig sl0 stimpy pointopoint ren stimpy $ route add ren As you can see, the first command configures the (first serial) interface as a point-to-point link to ren. The second command, route invocation, adds the machine ren to the routing tables. Some implementations of Linux may require that you identify the device (with the dev option) to the route command. To take down the interface, use the same commands but in reverse order. For example, you first execute route to remove the entries from the routing tables. Second, you execute ifconfig to take down the serial interface. Finally, you need to terminate the slattach process. You can run the ps command to locate the process ID for the running slattach process and then issue the kill command to terminate it. For example, the following dialog demonstrates the commands to execute and the order in which to execute them: stimpy $ route del ren stimpy $ ifconfig sl0 down stimpy $ ps a | grep slattach 4918 p1 S 0:00 slattach /dev/cua1 stimpy $ kill 4918 In the next section, we take a look at the dip command, which is the Dial-Up IP Protocol driver. page 229 #BREAK# Inside Linux Using dip for SLIP Automation Looking back on the last sections, you are probably thinking, “Getting connected is fairly easy, but I’d like to automate that whole process.” Well, that is what computers are all about, right? And Linux offers just the program for you; the program is called the Dial-Up IP Protocol (dip). In this section, we explore the use of dip and how it can help with automating the SLIP process. The dip command supports the processing of a chat script, allowing you to specify a command-response dialog to help with dialing, connecting, and the login process. You can also include commands to automate the setup of the SLIP network interface and establish entries to the kernel routing tables. The following shows the syntax for dip, in its most general form: dip [options …] [script file] A lot of supporting information is given in this section for the dip command. A sample dip script is supplied at the end of the section, preceded by a variables list and a command list. But first, Table 13.1 lists the most common command-line arguments to dip. Table 13.1. Common dip Command Arguments Switch Description -a Prompt for username and password. -i Act as a dial-in server. -k Kill the dip process that has locked the specified tty device or the most recent invocation of dip. -l line Indicate the line to be killed. -m mtu Set the Maximum Transfer Unit (MTU); the default is 296. -p proto Set the line protocol to be one of these: SLIP, CSLIP, SLIP6, CLSIP6, PPP, or TERM. -t Run dip in test (interactive or command) mode. -v Set verbose mode. This enables debug output to include echoing of each line of the script. As you can see, dip can also be used as a dial-in server, as represented by the -i switch. The dip command can also be invoked in interactive mode (or command mode), as designated by the -t switch. This allows you to participate in the dial-up and login process, allowing you to record the prompts and responses required to establish a modem connection. You can then use the results and establish a script file to automate the process. Table 13.2 lists the commands supported by dip. Simply type the command, plus any required arguments, and press Enter. These commands can be included in a chat script or executed while you are in command mode: Table 13.2. Common dip Commands Command Description label: Defines a label. beep [times] Beeps on user’s terminal [times] times. bootp [howmany [howlong]] Uses the BOOTP protocol to fetch both local and remote IP addresses. Break Sends a BREAK. chatkey keyword [code] Allows you to add to dip’s modem response words. config [interface|routing][pre|up|down|post] Stores interface configuration {arguments…} parameters. databits 7|8 Sets the number of data bits. page 230 #BREAK# Inside Linux Command Description dec $variable [decrementvalue|$ variable] Decrements a variable; the default is 1. Default Instructs dip to set the default route to the remote host it connected to. dial phonenumber [timeout] Transmits the string in the init variable as the modem initialization string and then dials the specified number. The default timeout is 60 seconds. Dip will parse any strings returned by the modem and will set $errlvl accordingly. The standard codes are as follows: 0 - OK, 1 CONNECT, 2 - ERROR, 3 - BUSY, 4 - NO CARRIER, 5 NO DIALTONE. You can change or add to these with the chatkey command. echo on|off Enables or disables the display of modem commands. exit [exit-status] Exits script leaving established [C]SLIP connection intact and dip running. flush Flushes input on the terminal. get $variable [value|ask|remote [timeout_value| $variable]] Gets the value for a specified variable. If the second parameter is ask, a prompt is printed and the appropriate value is read from standard input. If the second parameter is remote, the value is read from the remote machine. Otherwise, the second parameter is a constant or another variable that will supply the value. goto label Transfers control to the specified label within the chat script. Help Prints a list of commands. if expr goto label Tests a result code. The expr must have the form $variable op constant where op is one of the following: ==, !=, <, >, <=, or >=. inc $variable [incrementvalue|$ variable] Increments the specified variable. The default increment value is 1. init init-string Sets the initialization string to the indicated string (default is AT E0 Q0 V1 X4). Note that the initialization string is sent before the dialing command is issued. mode [SLIP|CSLIP|SLIP6|CSLIP6|PPP|TERM] Sets the line protocol. modem modem-name Sets the type of modem. netmask xxx.xxx.xxx.xxx Indicates the netmask address to use. onexit Executes the specified command upon dip’s exit. Works like the shell command, but is executed (only) when dip finishes. The onexit command that is executed is the last one encountered; any previous onexit commands are replaced by the new ones. parity E|O|N Sets the type of parity. password Prompts for a password and transmit it. proxyarp Requests Proxy ARP to set. print $variable Prints the contents of some variable. psend command [arguments] Sends the output of specified command to the serial driver, optionally passing arguments to command. The UID is reset to the real UID before running command. page 231 #BREAK# Inside Linux Command Description port tty_name Sets the name of the terminal port to use. (The path /dev/ is assumed.) quit Exits with nonzero exit status. reset Resets the modem. Does not work properly on several modems. securidfixed fixedpart Stores the fixed part of the SecureID password. securid Prompts for the variable part of the password generated by the ACE System SecureID card. The fixed part of the password must already have been stored using a secureidf command. The two parts are concatenated and sent to the remote terminal server. send text-string Sends a string to the serial driver. shell command [parameters] Executes command through the default shell (obtained from the shell variable) with parameters as the command-line arguments. dip variable substitution is performed before executing the command. If you don’t want a parameter beginning with a $ to be interpreted as a dip variable, precede it with a . skey [timeout | $variable] Tells dip to look for an S/Key challenge from the remote terminal server. dip then prompts the user for the secret password, generates the response, and sends it to the remote host. The optional parameter timeout sets how long dip is to wait to see the challenge. $errlvl is set to 1 if the skey command times out. If skey successfully sends a response, $errlvl is set to 0. Requires S/Key support to be compiled in. sleep time-in-secs Waits some time. speed bits-per-sec Sets port speed (default is 38400). Note that the actual speed associated with 38400 can be changed using setserial(8). Also, you should tell port’s real speed here because dip takes care of the set_hi and such bits by itself. Also, don’t be afraid, if you told the speed 57600 and it reports back 38400. Everything’s okay, the proper flags were applied, and the real port speed will be what you told it to be - that is, 57600. stopbits 1|2 Sets the number of stop bits. term Enters a terminal mode. timeout time-in-sec Sets timeout. This defines the period of inactivity on the line, after which dip will force the line down and break the connection (and exit). wait text [timeout_value | $variable] Waits for some string to arrive. page 232 #BREAK# Inside Linux The following table lists the special variables that can be used within a script file. Some of these variables can be set with a value and some are read-only; all variables can be read for their contents. Note that the variable names are lowercase and must begin with a dollar sign. Table 13.3 briefly describes each variable’s purpose. Table 13.3. Variables for a dip Chat File Variable Description $errlvl Holds the result of the previous command $locip IP Number of local host in dotted quad notation $local Fully qualified local hostname $rmtip IP Number of remote host in dotted quad notation $remote Fully qualified remote hostname $mtu Maximum Transfer Unit (maximum number of bytes that are transferred at once) $modem Modem type (at present, the only valid value is HAYES) $port Name of the terminal port to use $speed Transfer rate between the local host and the modem, in bits/sec Something to note: dip will resolve any hostname to its IP address if you supply the hostname in the local and remote special variables. Sample dip Script The following is a sample dip script: # bugs.dip # top: # define the name for connection.”ren.stimpy.net” get $local ren.stimpy.net # set up the remote end “bugs.bunny.net” get $remote bugs.bunny.net # set up the netmask 255.255.255.0 netmask 255.255.255.0 # define the serial port and speed. port cua02 speed 38400 # clean up the modem (reset it) reset flush # if your modem doesn’t respond properly to # the previous “reset”, then comment out # the reset or delete it altogether. then # uncomment the following two lines. # send ATZr # wait OK 3 # set the initialization string for modem, then dial get $init ATQ0V1E1X4 dial 123-4567 if $errlvl != 0 goto modem_ERR wait CONNECT 60 if $errlvl != 0 goto modem_ERR # if we got to here, we’re connected … # … log in to the remote system login: sleep 2 send rnrn wait ogin: 10 if $errlvl != 0 goto login_ERR send THE_USERNAMEn sleep 2 wait word: 10 if $errlvl != 0 goto pswrd_ERR send THE_PASSWORDn page 233 #BREAK# Inside Linux log-success: # we’re logged in, now wait for prompt wait SOMETEXT 15 if $errlvl != 0 goto prompt_ERR # if we’ve gotten here, then we’ve completed # all tasks required for SLIP connectivity fini: # set up SLIP get $mtu 296 # Ensure execution of route default print CONNECTED $locip == $rmtip mode CSLIP goto exit # prompt_ERR: print Time out waiting for login prompt goto error # login_ERR: print Time out waiting for logon goto error # pswrd_ERR: print Time out waiting for password prompt goto error # modem_ERR: print Problem with the modem goto general_ERR # general_ERR: print Could not connect with the remote system quit 1 exit: exit This sample script can be used to connect to bugs.bunny.net by invoking dip with the script name as its argument: # dip bugs.dip After successfully connecting to bugs and CSLIP has been engaged, dip will detach itself from the terminal and become a daemon process (or background process). Recall that if you invoke dip with the -k switch, dip will kill the dip process that has locked the specified tty device or the most recent invocation of dip. The following dialog demonstrates this: # dip -k Let’s take a look at the script file. The first statement in the script is a get command, which actually sets a variable to the specified value. In this script, the first statement, $local, is set to ren.stimpy.net. The second statement sets the variable $remote to bugs.bunny.net. Those lines follow: get $local ren.stimpy.net # set up the remote end “bugs.bunny.net” get $remote bugs.bunny.net The next line is the netmask statement; this statement and the next four statements (through reset) configure the terminal and reset the modem. You may experience a problem with the reset command; this command does not work with all modems. If you do have problems, either comment out the reset statement or remove the line altogether. Next, uncomment the two lines that read as follows: # send ATZr # wait OK 3 The statement following the reset statement, flush, purges any modem strings that may exist in the (receive) buffer. This ensures that no extraneous strings are in the buffer when the login sequence executes. The wait statement instructs dip to wait for the string specified as the first argument to wait. The second argument specifies a timeout as a number of seconds; if the string is not detected within the timeout range, the $errlvl variable is set to 1. The $errlvl variable is checked for success; if it is nonzero, the previous statement failed and we branch out to the appropriate error section. The following excerpt demonstrates the sequence: wait ogin: 8 if $errlvl != 0 goto login_ERR page 234 #BREAK# Inside Linux The concluding commands that are executed after the login is successful are default, which makes the SLIP link the default route to all hosts, and mode, which enables SLIP mode on the line and configures the interface and routing table for you. The next command, goto exit, routes the execution of the script around the error statements that follow. The following section of the script deals with exceptional conditions. Each label is used to deal with a specific error (exceptional) condition. A message is printed and then a goto statement is used to branch to the generic error message routine. Notice that the modem_ERR: section does not require a goto statement; it could just fall through to the general_ERR statement. The reason we use a goto statement is that we may need to add another error statement. If you insert the new statement after modem_ERR, you might forget to include the goto statement. prompt_ERR: print Time out waiting for login prompt goto general_ERR # login_ERR: print Time out waiting for logon goto general_ERR # pswrd_ERR: print Time out waiting for password prompt goto general_ERR # modem_ERR: print Problem with the modem goto general_ERR # general_ERR: print Could not connect with the remote system quit 1 The last statement in the script is exit, which is used as an unconditional egress of the script. The SLIP connection remains valid and dip continues to run. If you recall, the command dip -k is used to kill the running dip process. Remember to provide the script filename as an argument to the dip command. If you do not provide the filename extension, dip assumes an extension of .dip. Utilizing dip for Static IP Connectivity This section addresses using dip to establish a SLIP connection when the IP addresses for the local and remote are well-known (static). The following script is generic in nature and can be modified for your use. # static.dip top: get $local some.local.name get $remote some.remote.name netmask 255.255.255.0 # set up the modem port cua02 speed 38400 reset flush # if your modem doesn’t respond properly to # the previous “reset”, then comment out # the reset or delete it altogether. then # uncomment the following two lines. # send ATZr # wait OK 3 # set the initialization string for modem, then dial get $init ATQ0V1E1X4 dial 123-4567 if $errlvl != 0 goto modem_ERR wait CONNECT 60 if $errlvl != 0 goto modem_ERR login: sleep 2 send rnrn wait ogin: 10 if $errlvl != 0 goto login_ERR send USER_NAMEn sleep 2 wait word: 10 if $errlvl != 0 goto pswd_ERR send USER_PASSWORDn page 235 #BREAK# Inside Linux log-success: # we’re logged in, now wait for prompt wait CONFIRMATION_TEXT 15 if $errlvl != 0 goto prompt_ERR # if we’ve gotten here, then we’ve completed # all tasks required for SLIP connectivity fini: # set up SLIP get $mtu 296 default print CONNECTED $locip == $rmtip mode CSLIP goto exit # prompt_ERR: print Time out waiting for login prompt goto error # login_ERR: print Time out waiting for logon goto error # pswd_ERR: print Time out waiting for password prompt goto error # modem_ERR: print Problem with the modem goto general_ERR # general_ERR: print Could not connect with the remote system quit 1 exit: exit It is acceptable to use dotted-quad addresses for the get $local and the get $remote statements, but as always, you should specify the machine names because dip will resolve the names to IP addresses automatically. After name resolution, dip will perform its magic of dialing, connecting, log in, and finally, switching the line into SLIP mode and configuring the routing tables. In the section that follows, we will take a look at dip usage for dynamic IP connectivity. Utilizing dip for Dynamic IP Connectivity This section demonstrates the use of dip to establish a SLIP connection when the IP address is not known for the local and remote machines. The dip command will capture the IP addresses through the serial line after connectivity is established. The following sample script file demonstrates the functionality required: # dynamic.dip top: # set up the modem port cua02 speed 38400 reset flush # if your modem doesn’t respond properly to # the previous “reset”, then comment out # the reset or delete it altogether. then # uncomment the following two lines. # send ATZr # wait OK 3 # set the initialization string for modem, then dial get $init ATQ0V1E1X4 dial 123-4567 if $errlvl != 0 goto modem_ERR wait CONNECT 60 if $errlvl != 0 goto modem_ERR login: sleep 2 send rnrn wait ogin: 10 if $errlvl != 0 goto login_ERR send USER_NAMEn sleep 2 wait word: 10 if $errlvl != 0 goto pswd_ERR send USER_PASSWORDn get $remote remote 10 page 236 #BREAK# Inside Linux if $errlvl != 0 goto remote_ERR get $local local 10 if $errlvl != 0 goto local_ERR log-success: # we’re logged in, now wait for prompt wait CONFIRMATION_TEXT 15 if $errlvl != 0 goto prompt_ERR # if we’ve gotten here, then we’ve completed # all tasks required for SLIP connectivity fini: # set up SLIP get $mtu 296 default print CONNECTED $locip == $rmtip mode CSLIP goto exit # prompt_ERR: print Time out waiting for login prompt goto error # login_ERR: print Time out waiting for logon goto error # pswd_ERR: print Time out waiting for password prompt goto error # modem_ERR: print Problem with the modem goto general_ERR # remote_ERR: print Time out getting remote IP address goto error # local_ERR: print Time out getting local IP address goto error # general_ERR: print Could not connect with the remote system quit 1 exit: exit In this script, the modem is set up and initialized. Next, the remote SLIP server is dialed and a connection is established. After the username and password have been submitted and verified, the remote and local IP addresses are captured by the dip command. The dip command does this by examining the incoming data for anything that looks like an IP address. The dip command will time out after 10 seconds if it cannot find an IP address. Finally, if everything passes inspection, dip switches the line into SLIP mode and configures the routing tables. Running diplogin as a SLIP Server Using dip to act as a SLIP server is relatively easy. The basic course of attack is to set up the various configuration files and then execute the diplogin command. You need to create an account for each user that will need SLIP connectivity to your system. You will also need to add an entry for every user to the /etc/diphosts configuration file. Define Account Entry in /etc/passwd First, you need to supply an entry in the /etc/passwd file for each user requiring SLIP service. Be sure to define diplogin as the login shell for each user entry in the /etc/passwd file. The following is a sample entry: stimpy:x:1000:100:Stimpson J. Cat:/home/stimpy:/user/sbin/diplogin In this sample, after stimpy has logged in, the login program sets the current directory to the home directory specified in the /etc/passwd file, which is /home/stimpy. Next, the diplogin command is executed, which is a symbolic link to the dip command (dip is run in input mode). Finally, the dip command scans the /etc/diphosts file for the identified username. page 237 #BREAK# Inside Linux Define Username Entry in /etc/diphosts Each user must be described in the /etc/diphosts file. The following is the template for an /etc/diphosts entry: user : password : remote host : local host : netmask : comments : protocol,MTU The first field, user, is the user name. The entry here must match the logged in user. The second field permits you to define an encrypted password for the user. If this field is not the null (empty) string, dip will display a prompt and the user must supply a password. If the special entry s/key is specified, then S/Key authentication will be enforced. Note that dip must be compiled with the S/Key option enabled. The third field of the entry specifies the name of the remote host. This entry may also be the actual IP address. If the entry is a hostname, name resolution will take place using the name server or the /etc/hosts file. The fourth field identifies the name of the local host. Like the third field, this may be the actual IP address. If the entry is a name, then name resolution will take place using the name server or the /etc/hosts file. The fifth field identifies the netmask and must be in dotted notation. If this field is empty, as in this sample entry that follows, the address 255.255.255.0 is used. The sixth field is merely used for commentary - it can contain any text. The dip command will not try to interpret the entry. The seventh field contains comma-separated flags. Possible flags are as follows: SLIP - use the SLIP protocol. CSLIP - use the Compressed SLIP protocol. SLIP6 - use the SLIP6 protocol. CSLIP6 - use the Compressed SLIP6 protocol. PPP - use the PPP protocol. number - defines the MTU parameter of this connection. You must specify one of the first five entries, a comma, and finally specify the MTU required. The following is a sample entry from an /etc/diphosts file for the user named stimpy. stimpy::stimpynet:localHost::Stimpson J. Cat:SLIP,296 This specifies that stimpy is the username. A password prompt is displayed and awaits user input. The remote host name is stimpynet and the localhost is named localHost. The netmask is not identified, so the address 255.255.255.0 is used. The text Stimpson J. Cat only provides additional information for the reader of the file. The protocol to use is SLIP, with an MTU value of 296. Execute diplogin After dip locates the correct line entry for the user, dip sets the terminal into raw mode and sets up the serial line to the defined SLIP protocol. Finally, after the line is enabled, routing table entries are defined to complete the connection. The dip command then continues to run in the background until the connection is dropped. After the line drops, the entries are removed from the routing table, and the line is returned to normal mode. Starting with the next section, we begin our journey with Point-to-Point Protocol. Point-to-Point Protocol (PPP) As was mentioned in the opening of the previous section, Linux provides two protocols for serial-line connectivity: Serial Line Internet Protocol (SLIP) and Point-to-Point Protocol (PPP). Both SLIP and PPP provide facilities to establish connectivity with a remote system. PPP is a protocol that was developed after SLIP and is now the preferred protocol over SLIP for serial-line connectivity. page 238 #BREAK# Inside Linux PPP Overview PPP is a more powerful and robust protocol than SLIP. It provides features and capabilities that are lacking with SLIP. You should always prefer PPP to SLIP when establishing a network connection over a serial line. The hardware requirements for PPP are the same as for SLIP; a serial port with a FIFO buffer and a modem are all that is required. PPP is used to support the TCP/IP protocols over a serial connection, whether it’s over a dial-up phone line (or ISDN), a null modem cable, a telnet link, or a dedicated leased line. At the lower levels, PPP is divided into two parts: the High-Level Data Link Control (HDLC) and the Link Control Protocol (LCP) . HDLC defines the ground rules for the structure of the PPP frames. This allows the frame to contain packets from protocols other than IP. A field within the frame identifies the protocol type. In addition to handling IP datagrams, PPP can also use Van-Jacobson (VJ) header compression. Effectively, this compresses the TCP packets, allowing increased performance. At a higher level, PPP functionality is also split into two parts: the HDLC and the pppd daemon. The pppd daemon delivers the LCP, support for user authentication, and the Network Control Protocols (NCP) for establishing the IP Control Protocol (IPCP). Beginning with the next section, we discuss the specifics of PPP configuration under Linux. PPP Preflight Checklist This section outlines the prerequisites that must be addressed before jumping into the actual use and setup of PPP. Some prerequisites are obvious, and others require explanation. The following list identifies the requirements for PPP usage: PPP support is available, either as a loadable module or statically. The PPP software is installed on your system. Your Linux system provides TCP/IP support. You have a modem installed on a known serial port. You have gathered the following information from your ISP to support PPP connectivity. Be prepared, some ISP support staff do not understand PPP and what is required for PPP connectivity, especially if the ISP is Microsoft influenced. Yet other ISPs can provide excellent support, both verbally and with written documentation. The following is a list of attributes you should acquire from your ISP for PPP connectivity: o The phone number to the ISP. o If using static IP assignment, you will need the IP address for your machine. Otherwise, you will be using dynamic IP assignment. o Does the remote server use PAP/CHAP? If so, you will need to obtain the ID and SECRET entries required for connecting to the ISP. Normally, these entries are your username and password. o The Domain Name Service (DNS) server address(es) for hostname resolution. If PPP is not installed on your system, you should refer to the distribution documentation. To install support, running the installation program provided with your Linux distribution should install the necessary components for PPP use. For example, with RedHat, use RPM to install the package that supports PPP. Under SuSE Linux, you can use YaST to install the PPP package. For Caldera OpenLinux, you can use the KPackage program to install RPM-compatible packages. page 239 #BREAK# Inside Linux You can easily check for the existence of PPP support using the dmesg command. You can invoke it as shown in the following dialog: stimpy $ dmesg | grep PPP PPP: version 2.3.3 (demand dialing) PPP line discipline registered. PPP BSD Compression module registered PPP Deflate Compression module registered stimpy $ You will need to visit a number of configuration files to enable PPP; these will be examined in sections that follow. Verify DNS Support After the PPP connection is established, your Linux machine will need to use the facilities of hostname resolution - resolving hostnames into their respective IP addresses. Your ISP should provide you with the names of its DNS servers. After you have this information, you need to provide entries in the /etc/resolv.conf and /etc/hosts.conf files. The /etc/resolv.conf file is used for name resolution. Entries found in this file designate a DNS server and its associated IP address. More than one DNS server can be specified in this file. As mentioned previously, your ISP can provide you with the DNS servers and their associated IP addresses. The following is sample output from an /etc/resolv.conf file: domain the-isp.domain.name nameserver 19.265.15.5 nameserver 19.265.15.10 Your ISP will have one or more DNS servers; be sure to enter all DNS servers and their respective IP addresses. You can also set up your Linux to use DNS locally. Many Linux power users do this because it can cut down on name-resolution traffic from your host to the server (and vice versa). Doing this will provoke your DNS to cache DNS lookups, thereby decreasing accesses to the remote DNS for name resolution. The following is a sample entry from an /etc/host.conf file: order hosts,bind multi on The first line tells the resolver to query information (resolution) from the /etc/hosts file. If resolution is not found there, the resolver queries the DNS server(s). Using PPP To establish a PPP network connection, a pair of programs are utilized, specifically chat and pppd. In the next section, we discuss the chat program. The pppd program is discussed in the section that follows. Using chat The chat program provides the automation required to establish a connection between your local machine and the remote PPP server. The objective of chat is to establish the connection between the local pppd and the remote’s pppd process. The syntax for chat is as follows: chat [options] scriptFile Table 13.4 lists the options available for chat. Be sure to refer to the man page for chat for more detailed information. As mentioned previously, two programs are used to establish PPP connec-ivity: chat and pppd. With SLIP connectivity, we have to use only the dip program. Unfortunately, pppd does not provide for dial-up and logging facilities. The chat program implements UUCP-style chat script functionality. In a nutshell, a chat script consists of alternating expect-send string sequences, separated by spaces. Optionally, subexpectsubsend string pairs can be used, separated by a dash. The following example demonstrates this: ogin:-BREAK-ogin: ppp ssword: myPswd page 240 #BREAK# Inside Linux Table 13.4. Common chat Options Switch Description -f chat file Read the chat script from the chat file. Multiple lines are permitted in the file. To separate strings, use the space or the tab character. -t timeout Set a timeout for receipt of the expect string. If the expect string is not received within the timeout period, reply string is not transmitted. -r report file Set the filename for report string output. -e Echo will be enabled when chat starts up. The ECHO keyword can be used to subsequently toggle echoing on and off. Output is to stderr. -v Verbose mode will be enabled when chat starts up. The chat program will log both text received from the modem and output strings to the modem, plus the state of chat. See the -s flag for logfile options. -V The chat script is executed in stderr verbose mode. The chat program will output all dialog to the stderr device. -s Use stderr. All log messages will be sent to stderr. -S Do not use the SYSLOG for logging. Normally, error messages are sent to SYSLOG. If -S is used, neither log messages from -v nor error messages are not sent to SYSLOG. -T phone number Pass in a string, normally a phone number, that is substituted for the T meta-character in a send string. -U phone number Pass in a string, normally a phone number, that is substituted for the U meta-character in a send string. script If a script is not specified with the -f option in a file, the script is submitted to the chat program. We will now break down and analyze what is happening in this script. The first line tells chat to expect the string ogin:. If chat does not receive the login prompt within the timeout period, chat will send a BREAK to the remote end and again will wait for the string ogin:. If ogin: is received, the break is not transmitted. When the login prompt is received (ogin:), chat will send the string ppp and wait for the string ssword:. If the prompt is received, chat will transmit the password myPswd. You should note that a carriage return character is sent immediately after the reply string. Chat scripts are fairly straightforward. The previous script is not a comprehensive one because it does not include the expect-send strings required to perform modem initialization, dial-up, and the login dialog. The following demonstrates a more comprehensive script, from start to finish. stimpy # chat -v ‘’ ATZ OK ATDT1234567 CONNECT ‘’ ogin:-BREAK-ogin: ppp word: stimpy3 The chat program anticipates that the first string is an expect string, but because the modem won’t expel text before we have sent something to it, the empty string (”") is specified as the (first) expect string. The first send string is ATZ, which is a modem reset for Hayes-oriented modems. Next, we expect to see the string OK as a response to the reset command. We follow up by submitting the dial command and the phone number to dial. The chat program then waits for the CONNECT string to return from the modem. The empty string is transmitted because we want to wait only on the login prompt. Finally, the login sequence is executed as shown in the previous example. You have probably noticed that most expect strings are not complete words. For example, instead of expecting the string Login, the string ogin: is used. Or, instead of expecting Password, the string word: is identified. The main reason to do this is expectation of the incoming text. It is possible that instead of Login, the text string is actually login (with a lowercase l). Or, instead of Password, the text string is actually password (with a lowercase p). You have to think about these seemingly insignificant details when developing chat scripts. Even if you are positive that your PPP server is sending Password, nothing prevents them from changing the text string. Suffice it to say that standard practice dictates using the few letters of the expect string. page 241 #BREAK# Inside Linux The chat program offers a number of escape sequences. Table 13.5 lists the escape sequences offered by chat. Any of the escapes can be in the send string. Table 13.5. Escape Sequences for chat Switch Description ‘’ Expects or sends the null (empty) string. Although no characters are transmitted, the implied return character is still sent. b Represents a backspace character. c Suppresses the newline character at the end of the reply string. Use this to send a string without a trailing return. It must be at the end of the send string. d Delays for one second. K Inserts a BREAK n Sends a newline (linefeed) character. N Sends the null character. p Pauses for 1/10 of a second. q Suppresses writing the string to SYSLOG. r Sends or expects a carriage return. s Represents a space character in the string. t Sends or expects a tab character. \ Sends or expects a backslash character. ddd Used to represent an ASCII character using the equivalent octal digits. ^C Substitutes the sequence with the control character represented by C. Some of the escape sequences may not be identified in the expect string. Be sure to consult the man page for chat for more information. We need to touch on the subject of security. Executing the chat program with the script dialog is subject to inspection by other users on the system. Anyone can execute the ps -ef command sequence and view the complete command line. You say you have not tried these switches to the ps command? Try it now to see the results. So, how do you deflect any users from examining the chat script? The solution is rather simple - you put the chat dialog into a file and then tell chat to use the contents of the file for the dialog. Referring back to Table 13.1, you will see that using the -f switch and supplying the script file as an argument will instruct chat to use the file’s contents for the chat dialog. The following demonstrates the syntax: stimpy $ chat -f chat_script_filename It is also easier to modify and maintain a script within a file, rather than modifying the command line. You cannot identify a chat file (with -f) and specify a chat dialog on the command line, because they’re mutually exclusive. The following is a sample chat script file: ‘’ ATZ OK ATDT1234567 CONNECT ‘’ ogin:-BREAK-ogin: ppp word: stimpy3 The expect-send pairs reside on the same line. This makes maintenance and troubleshooting much easier. It is always good to expect potential failure and to be able to recover from it. You can specify that a script should be aborted if some failure is detected. For example, chat cannot determine the difference between CONNECT and BUSY; chat does not know that the string BUSY is considered an exceptional condition. So, how do you inform chat of exceptional conditions? You do this by specifying abort strings. page 242 #BREAK# Inside Linux The chat keyword ABORT is used to specify an abort sequence. The following sample script demonstrates the use of ABORT: ABORT BUSY ABORT ‘NO CARRIER’ ‘’ ATZ OK ATDT5551212 CONNECT ‘’ The chat will abort execution of the script if it detects any of the identified ABORT sequences as an expect string. Using pppd The pppd command is the Point-to-Point Protocol Daemon. The syntax for pppd is as follows: pppd [tty_name] [speed] [options] Table 13.6 lists the more common options for the pppd command. Table 13.6. Common Options for pppd Option Description asyncmap Sets the async character map to . The map describes that control characters cannot be successfully received over the serial line. auth Specifies that the peer is required to authenticate itself before network packets can be sent or received. connect script Uses the executable or shell command specified by script to set up the serial line. crtscts Uses hardware flow control (RTS/CTS) on the serial port. defaultroute Adds a default route to the system routing tables. disconnect script Runs the executable or shell command specified by script after pppd has terminated the link. escape xx,yy,… Causes the characters to be escaped on transmission. The characters escaped are specified as hex numbers, delimited by commas. file name Reads the options from file name. lock Uses UUCP-style lock file for the serial device to ensure exclusive access to that device. mru n Sets the MRU value to n. The minimum value is 128 and the default is 1500. mtu n Sets the MTU value to n. passive Specifies that the passive option be used in the LCP. debug Enables connection debugging facilities. local Does not use the modem control lines; ignores the state of CD (Carrier Detect) and pppd will not change the state of DTR. login Utilizes the system password database for authenticating the peer using PAP. Also, records the user in the system wtmp file. modem Uses the modem control lines, which is the default. The pppd command will wait for the CD from the modem to be asserted when opening the serial device, and it will drop the DTR when the connection is terminated. netmask n Sets the interface netmask to n. nodetach Doesn’t detach from the controlling terminal. xonxoff Uses software flow control (that is, XON/XOFF) on the serial port. Be sure to refer to the man page for pppd for an exhaustive list of commands available. page 243 #BREAK# Inside Linux Option Files for pppd After pppd executes and before it scans the arguments on the command line, it scans a number of configuration files for default options. These files contain any of the valid command-line arguments. Comments can be included in the files and are delineated by the # sign. One file is the options file and is found in the /etc/ppp directory. This file is always searched and parsed when pppd first executes. It is accepted practice to use this file for any global defaults. Doing this can help with any potential security issues that could arise. For example, you could specify that PAP authentication be used from the peer; to do this, you include the auth option in the /etc/ppp/options file. The user cannot override this option. The following is an excerpt from a sample /etc/ppp/options file: # /etc/ppp/options # The name of this server. name # Enforce the use of the hostname usehostname # If no local IP address is given, # noipdefault # Specify which DNS Servers the incoming # Win95 or WinNT Connection should use #ms-dns 192.168.1.1 #ms-dns 192.168.1.2 # enable this on a server that already # has a permanent default route #nodefaultroute # Increase debugging level (same as -d). The # debug output is written to syslog LOG_LOCAL2. debug # Require the peer to authenticate itself before # allowing network packets to be sent or received. noauth # Use hardware flow control (i.e. RTS/CTS) to # control the flow of data on the serial port. crtscts # Specifies that pppd should use a UUCP-style # lock on the serial device lock # Use the modem control lines. modem # Set the MRU #mru 542 # Set the MTU to n #mtu # Set the interface netmask to , a 32 bit netmask in “decimal dot” # notation (e.g. 255.255.255.0). netmask 255.255.255.0 # Don’t fork to become a background process nodetach # Specifies that pppd should disconnect # if the link is idle for n seconds. idle 600 # —— A second file that is read after the /etc/ppp/options file is parsed is .ppprc. This file is found in the user’s home directory. Users have the ability to establish their own sets of default options by merely supplying the required options in the file. Script Files for pppd Connections In this section, we introduce a set of scripts to help automate log-in and PPP startup. After these files are set up, you have to execute only a single command to establish a PPP connection. The following files are used for version 2.1.2 of PPP: /usr/sbin/pppd /etc/ppp/options / etc/ppp/ppp-on / etc/ppp/ppp-off For version 2.2 of PPP, we add a third file to the list, as shown in the following: /usr/sbin/pppd /etc/ppp/options /etc/ppp/ppp-on /etc/ppp/ppp-off /etc/ppp/ppp-on-dialer page 244 #BREAK# Inside Linux The following is a sample ppp-on script. You should use this script file no matter whether you are using version 2.1.2 or 2.2 of PPP. #!/bin/sh # Script to initiate a PPP connection. # Change as required. TELEPHONE=123-4567 # The telephone number to the remote ACCOUNT=theAccount # Account name PASSWORD=thePassword # Password to use LOCAL_IP=0.0.0.0 # Local IP addressl; if dynamic = 0.0.0.0 REMOTE_IP=0.0.0.0 # Remote IP address; usually 0.0.0.0 NETMASK=255.255.255.0 # Netmask, if required # Export export TELEPHONE ACCOUNT PASSWORD # Location of the script which dials the phone and logs DIALER_SCRIPT=/etc/ppp/ppp-on-dialer # Initiate the connection exec /usr/sbin/pppd debug /dev/ttySx 38400 $LOCAL_IP:$REMOTE_IP connect $DIALER_SCRIPT You will have to modify the ppp-on script; the script previously shown is really a template. Starting from the top and moving down, you first have to supply the proper phone number to your ISP. Next, the ACCOUNT field is your username that is registered with your ISP. The field that follows ACCOUNT, PASSWORD, is the password you use for login purposes. You may need to alter the following lines: DIALER_SCRIPT=/etc/ppp/ppp-on-dialer … exec /usr/sbin/pppd debug /dev/ttySx 38400 If your pppd executable and ppp-on-dialer file exist in a different directory path, you will need to change those paths in the script file. Next, a sample ppp-on-dialer script is supplied as follows: #!/bin/sh # /usr/sbin/chat -v TIMEOUT 3 ABORT ‘nNO CARRIERr’ ABORT ‘nNO ANSWERr’ ABORT ‘nBUSYr’ ‘’ rAT ‘OK-+++c-OK’ ATH0 TIMEOUT 60 OK ATDT$TELEPHONE CONNECT ‘’ ogin:–ogin: $ACCOUNT sword: $PASSWORD The ppp-on-dialer script file contains the actual dialog that is required to dial up and log in to the remote PPP server. In this sample, three ABORT sequences are identified; be sure to add any other abort sequences you may require. Check your modem manual for any exceptional conditions (error strings) that may need to trigger an abort sequence. Also, pay close attention to the value for the TIMEOUT variable - you may need to extend this time. Finally, a sample ppp-off script is supplied as follows: #!/bin/sh # Find device to kill. if [ “$1″ = “” ]; then DEVICE=ppp0 else DEVICE=$1 fi # If the ppp0 pid file exists, then it’s running if [ -r /var/run/$DEVICE.pid ]; then kill -INT `cat /var/run/$DEVICE.pid` # If kill didn’t work, then no process # is running for this pid if [ ! “$?” = “0″ ]; then rm -f /var/run/$DEVICE.pid echo “ERROR: Deleted pid file” exit 1 fi # echo “Terminated PPP link: $DEVICE” exit 0 fi # # ppp not running echo “ERROR: Invalid PPP link: $DEVICE” exit 1 This last script is used to shut down PPP in a graceful fashion. You should not have to alter this file. page 245 #BREAK# Inside Linux And now, the moment of truth. After you have made all the required adjustments to the scripts, it is time to execute and test for success. First, you need to execute the ppp-on script file, as the following dialog demonstrates: stimpy $ ppp-on & stimpy $ The trailing ampersand (&) puts the execution of the script into the background and returns the command prompt. Testing the PPP Scripts At the end of the previous section, we executed the ppp-on script. An effective method of debugging the fruits of our labor is to examine the /var/log/messages file (or /var/adm/messages). You use the tail command to reveal the last messages written to the log. In the example that follows, I have requested an extract of the previous 200 messages written to the log file. I have parsed out only the lines that pertain to the PPP dialog. stimpy $ tail -200 /var/log/messages Oct 11 04:24:26 stimpy pppd[13718]: pppd 2.3.5 started by root, uid 0 Oct 11 04:24:26 stimpy pppd[13718]: Using interface ppp0 Oct 11 04:24:26 stimpy pppd[13718]: Connect: ppp0 <--> /dev/modem Oct 11 04:24:26 stimpy pppd[13718]: sent [LCP ConfReq id=0×1 … Oct 11 04:24:26 stimpy pppd[13718]: rcvd [LCP ConfAck id=0×1 … Oct 11 04:24:26 stimpy pppd[13718]: rcvd [LCP ConfReq id=0×1 … Oct 11 04:24:26 stimpy pppd[13718]: sent [LCP ConfAck id=0×1 … Oct 11 04:24:26 stimpy pppd[13718]: sent [PAP AuthReq id=0×1 user=”user” … Oct 11 04:24:29 stimpy pppd[13718]: sent [PAP AuthReq id=0×2 user=”user” Oct 11 04:24:32 stimpy pppd[13718]: sent [PAP AuthReq id=0×3 user=”user” Oct 11 04:24:34 stimpy pppd[13718]: rcvd [PAP AuthAck id=0×3 “”] Oct 11 04:24:34 stimpy pppd[13718]: Remote message: Oct 11 04:24:34 stimpy pppd[13718]: sent [IPCP ConfReq id=0×1 ] Oct 11 04:24:34 stimpy pppd[13718]: sent [CCP ConfReq id=0×1 … Oct 11 04:24:34 stimpy pppd[13718]: rcvd [IPCP ConfReq id=0×2 … Oct 11 04:24:35 stimpy pppd[13718]: sent [CCP ConfReq id=0×2] Oct 11 04:24:35 stimpy pppd[13718]: rcvd [IPCP ConfReq id=0×3 ] Oct 11 04:24:35 stimpy pppd[13718]: sent [CCP ConfRej id=0×4 < 04 02>] Oct 11 04:24:35 stimpy pppd[13718]: rcvd [CCP ConfReq id=0×5] Oct 11 04:24:35 stimpy pppd[13718]: sent [CCP ConfAck id=0×5] Oct 11 04:24:41 stimpy pppd[13718]: rcvd [IPCP ConfReq id=0×6 ] Oct 11 04:24:41 stimpy pppd[13718]: sent [IPCP ConfAck id=0×6 ] Oct 11 04:24:41 stimpy pppd[13718]: sent [IPCP ConfReq id=0×4 [options] Version 2.0.6 -s smb.conf pathname to smb.conf file -B IP addr broadcast IP address to use -O socket_options socket options to use -R name resolve order use these name resolution services only -M host send a winpopup message to the host … stimpy $ smbd -V Version 2.0.5a stimpy $ nmbd -V Version 2.0.5a stimpy $ In this dialog, a check is first made for the smbclient program. As mentioned previously, the smbclient program implements a simple FTP-like (command-line) client. The second command invoked is the smbd daemon with the -V switch. The smbd daemon provides file and print services to SMB clients. The last command invocation is to the nmbd daemon, which provides NetBIOS name resolution and browsing. Another interesting test is to execute the testparm utility, which allows you to test the smb.conf configuration file. If you successfully executed the commands just shown, you should execute testparm like this: stimpy $ testparm Load smb config files from /etc/smb.conf Processing section “[homes]” Processing section “[printers]” Loaded services file OK. ERROR: lock directory /var/lock/samba does not exist Press enter to see a dump of your service definitions … # Global parameters [global] workgroup = ARBEITSGRUPPE netbios name = netbios aliases = server string = Samba 2.0.5a interfaces = bind interfaces only = No … delete readonly = No dos filetimes = No dos filetime resolution = No fake directory create times = No [homes] comment = Heimatverzeichnis read only = No create mask = 0750 browseable = No [printers] comment = All Printers path = /tmp create mask = 0700 print ok = Yes browseable = No stimpy $ On the sixth line, note the error message ERROR: lock directory /var/lock/samba does not exist. This is not a significant error. It merely means that the Samba server is not currently running and most likely has never been executed. After executing the smbd daemon, you can check for the directory’s existence, as shown in the following dialog: stimpy $ ls -al /var/lock total 4 drwxrwxr-x 4 root uucp 1024 Feb 4 01:13 . drwxr-xr-x 17 root root 1024 Jan 8 11:38 .. drwxr-xr-x 3 root root 1024 Jan 8 11:34 subsys stimpy $ smbd -D stimpy $ ls -al /var/lock drwxrwxr-x 4 root uucp 1024 Feb 4 01:13 . drwxr-xr-x 17 root root 1024 Jan 8 11:38 .. drwxr-xr-x 2 root root 1024 Feb 4 01:18 samba drwxr-xr-x 3 root root 1024 Jan 8 11:34 subsys page 265 #BREAK# Inside Linux stimpy $ ps x PID TTY STAT TIME COMMAND 1 ? S 0:03 init [2] 2 ? SW 0:01 [kflushd] … 2792 ? S 0:00 smbd -D 2801 pts/0 R 0:00 ps x stimpy $ The first ls command shows that the /var/lock/samba directory does not exist yet. Next, the smbd daemon is invoked. A second invocation of the ls command reveals that the daemon indeed created the /var/lock/samba directory. The last command executed is ps x, which shows that the smbd daemon is indeed running. You might be wondering what the /var/lock/samba directory is used for. The Samba daemons, when they execute, write a file to the directory; this file contains the daemon’s process ID. For example, the following dialog shows the PID for the smbd daemon executed in the preceding dialog: stimpy $ ps x PID TTY STAT TIME COMMAND 1 ? S 0:03 init [2] 2 ? SW 0:01 [kflushd] … 2792 ? S 0:00 smbd -D 2802 ? Z 0:00 [cron ] 2824 pts/0 R 0:00 ps x stimpy $ ls -al /var/lock/samba total 3 drwxr-xr-x 2 root root 1024 Feb 4 01:24 . drwxrwxr-x 4 root uucp 1024 Feb 4 01:13 .. -rw-r–r–1 root root 20 Feb 4 01:24 smbd.pid stimpy $ cat /var/lock/samba/smbd.pid 2792 stimpy $ You can use this PID to control the daemons, such as restarting the daemon or terminating it. One word of caution: Do not kill the daemons with the SIGKILL (9) signal. This will leave the shared memory area in an unstable state. We will discuss sending signals to the daemons later. Installing Samba If Samba does not exist on your system, use the distribution’s installation program. Most Linux distributions allow you to run the Linux installation program to install, remove, and update packages. For example, installing Samba on Red Hat is a simple matter of executing the package manager. The following sample dialog demonstrates executing the rpm command to install the Samba package under Red Hat: stimpy $ rpm -ivh samba-2.06-1.i386.rpm If you are running SuSE Linux, you should execute the YaST tool. From the YaST main menu, select the Choose, Install Packages menu option. Next, select the Change, Create Configuration menu option. The Samba suite is found in the N - Network package. Simply select it, return to the previous menu, and select the Start Installation menu option. YaST will install the Samba suite and configure your system. If you downloaded the Samba package from the SuSE Web site, you can still use YaST to install the package. Again, start YaST and select the Choose, Install Packages menu option. Next, select the Install Packages menu option and browse to the directory where the Samba package resides. Select the Samba package with the Spacebar, and then press the F10 function key to start the installation. Once you have installed the package, the SuSEConfig utility will configure and update your SuSE system. If you are running TurboLinux, you will use the TurboPkg or XTurboPkg tool. Using these tools, you can install an RPM package from a local filesystem, CD-ROM, or FTP server. If you are using Caldera’s OpenLinux, you can execute the kpackage program from within the KDE. You can find kpackage on the Caldera Open Administration System menu, or you can select Menu, COAS menu and choose the kpackage icon. Figure 15.1 shows kpackage in action. If you are running the Slackware distribution, you can use the Setup utility to execute the package tool. You can execute Setup from within a graphical shell window or from the text mode shell. Figure 15.2 shows Setup running in a KDE shell window. page 266 #BREAK# Inside Linux Figure 15.1. The kpackage program running in Caldera OpenLinux. Figure 15.2. The Setup program running in a Slackware KDE window. If you are using another Linux distribution, be sure to check the documentation for proper package selection and installation. By this time, the complete Samba package should be installed and at least partially configured. Configuring Samba A single configuration file, smb.conf, completely controls Samba’s behavior. For Linux, the configuration file exists in the /etc directory. Under most versions of UNIX, however, the configuration file exists in the /usr/local/samba/lib directory. If you downloaded the Samba suite, be sure to check the documentation for the configuration file’s location. page 267 #BREAK# Inside Linux page 268 Configuring for the Samba Web Administration Tool (SWAT) Two more important steps are required. These steps relate to the use of the Samba Web Administration Tool (SWAT). SWAT, which was added to version 2.0 of Samba, is a browser-based administration tool used to configure Samba. You can use SWAT to set up the Samba server and update its configuration. You can also set up Samba by hand, which many administrators still prefer. If you are new to Samba, there will be less trial and error in setting up Samba if you use SWAT. The first file you need to check is the /etc/services file. You must ensure that there is an entry for the SWAT tool. The following is a snippet from this file: # # netplan # netplan 12000/tcp # # swat is the Samba Web Administration Tool # swat 901/tcp # # Entries for IBM DB2 Database # db2cdb2inst1 50000/tcp # Connection port for DB2 instance db2inst1 db2idb2inst1 50001/tcp # Interrupt port for DB2 instance db2inst1 Notice the entry for SWAT. If your /etc/services file does not have this entry, you will have to add it manually. Fire up your favorite text editor, and add the entry just as it appears here. The 901 specifies the port to use to communicate with SWAT. The /etc/services file identifies the available network services and their corresponding port numbers and whether they use TCP or UDP. Next, you need to check the inetd.conf file that is found in the /etc directory. The following is a snippet from the /etc/inetd.conf file: # # netbios-ssn stream tcp nowait root /usr/sbin/smbd smbd -l /var/log/samba -s /etc/smb.conf # netbios-ns dgram udp wait root /usr/sbin/nmbd nmbd # # swat is the Samba Web Administration Tool swat stream tcp nowait.400 root /usr/sbin/swat swat # # amanda backup server with indexing capabilities The line that begins swat stream… is the line you need to verify in your /etc/inetd.conf file. It is quite possible that the entry is there but is commented out (as it was on my SuSE Linux system). If the line is prefixed with a #, simply remove the character. If the line does not exist, be sure to type it exactly as shown in the example. If you edited the /etc/inetd.conf file, you must tell the inetd daemon to reread this file. You can also reboot the machine, and the changes will take effect. Otherwise, you should issue the HUP signal to the inetd daemon to force the daemon to reread the /etc/inetd.conf file. The following dialog demonstrates this procedure: stimpy $ ps x | grep inet 124 ? S 0:00 /usr/sbin/inetd 3691 pts/0 S 0:00 grep inet stimpy $ kill -HUP 124 stimpy $ First, you execute the ps command, looking for the inetd entry. You can run grep against the ps command to help ferret out the entry. Once you have determined the process ID for the inetd daemon, you can execute the kill command, passing the HUP signal to the daemon. This forces the daemon to reread its configuration file. The smb.conf Configuration File If you installed Samba from your Linux distribution’s CD-ROM, a “default” smb.conf file should exist in the /etc directory. If you downloaded the Samba suite, the installation scripts might not have placed an smb.conf file in the /etc directory. Be sure to check the Samba directory tree for a sample smb.conf file. Be sure to copy it to the directory where Samba expects it. The smb.conf file is the configuration file for the Samba suite. This file contains runtime configuration information and is designed to be configured and administered by the SWAT utility. #BREAK# Inside Linux The file consists of sections and parameters. A section is identified by a name enclosed in square brackets. A section continues until the next section is identified. The following is a sample section: [global] Within each section are one or more parameters, given as key-value pairs, as in the following example: name = value The smb.conf file is line-oriented. In other words, each line represents a comment, section, or parameter. Both section and parameter names are case-insensitive. A comment line can begin with either a semicolon (;) or a hash (#) character. As with other typical UNIX configuration files, the backslash () is used as the line-continuation character. The value part of an entry can be a string or a boolean value. Valid boolean values are yes or no, 0 or 1, and true or false. The following is a sample smb.conf file, taken directly from a freshly installed version of Samba (version 2.0.6) on version 6.3 of SuSE Linux. Example 15.1. Sample Samba smb.conf Configuration File ; /etc/smb.conf ; [global] workgroup = arbeitsgruppe guest account = nobody keep alive = 30 os level = 2 kernel oplocks = false security = user ; Uncomment the following, if you want to use an existing ; NT-Server to authenticate users, but don’t forget that ; you also have to create them locally!!! ; security = server ; password server = 192.168.1.10 ; encrypt passwords = yes printing = bsd printcap name = /etc/printcap load printers = yes socket options = TCP_NODELAY map to guest = Bad User ; Uncomment this, if you want to integrate your server ; into an existing net e.g. with NT-WS to prevent nettraffic ; local master = no ; ; Please uncomment the following entry and replace the ; ip number and netmask with the correct numbers for ; your ethernet interface. ; interfaces = 192.168.1.1/255.255.255.0 ; If you want Samba to act as a wins server, please set ; ‘wins support = yes’ wins support = no ; If you want Samba to use an existing wins server, ; please uncomment the following line and replace ; the dummy with the wins server’s ip number. ; wins server = 192.168.1.1 ; ; Do you want samba to act as a logon-server for ; your windows 95/98 clients, so uncomment the ; following: ; logon script =%U.bat ; domain logons = yes ; domain master = yes ; [netlogon] ; path = /netlogon [homes] comment = Heimatverzeichnis browseable = no read only = no create mode = 0750 ; ; The following share gives all users access to the Server’s CD drive, ; assuming it is mounted under /cd. To enable this share, please remove ; the semicolons before the lines ; [cdrom] ; comment = Linux CD-ROM ; path = /cd ; read only = yes ; locking = no [printers] comment = All Printers browseable = no printable = yes public = no read only = yes create mode = 0700 directory = /tmp ; end of file page 269 #BREAK# Inside Linux A number of sections are defined in this file. Three special sections are predefined: [global]. Parameters in this section apply globally to the server. This section also defines default values for other sections in the configuration file. [homes]. This section allows clients (users) to connect to their home directory. [printers]. This section works like [homes], but for printers. Users can connect to any printer defined in the /etc/princap file. Each section in the configuration file, except for the [global] section, describes a shared resource. The shared resource is also referred to as a share. The section name, such as [netlogon] or [cdrom], identifies the shared resource. The parameters within the section are used to define the share’s attributes. Variable Substitution You can set up some of the strings to accept substitutions. The substitution identifier is replaced with an actual value. For example, consider the following entry: path = /home/%u If the user who is connected is “daffy,” the entry will be finalized like this: path = /home/daffy Table 15.1 details the substitutions that are available in Samba. Table 15.1. Variable Substitutions for the smb.conf File Flag Description %S Replaced by the name of the current service, if available. %P Replaced by the root directory, if available. %u Replaced by the service’s username, if available. %g Replaced by the primary group name of %u. %U Replaced by the session username. %G Replaced by the primary group name of %U. %H Identifies the home directory of the user %u. %v The version of Samba that is running. %h Replaced by the Internet hostname that Samba is executing on. %m Replaced by the client machine’s NetBIOS name. %L Replaced by the server’s NetBIOS name. %M Replaced by the client machine’s Internet name. %N Extracts the name of the NIS home directory server. %p Replaced by the path of the service’s home directory. %R Replaced by the protocol level as soon as protocol negotiation has finished. The values can be CORE, COREPLUS, LANMAN1, LANMAN2, or NT1. %d Extracts the process ID of the current server process. %a Replaced by the remote machine’s architecture. You should not consider this option 100percent reliable. Some of the architectures that it recognizes are Samba, Windows for Workgroups, Windows NT, and Windows 95. All others get the value UNKNOWN. page 270 #BREAK# Inside Linux Flag Description %I Replaced by the client machine’s IP address. %T Replaced by the current date and time. If you are not quite sure of the exact result of some of these substitutions, experiment to validate the outcome. Do not experiment on a production system. Use of Name Mangling Samba supports the concept of name mangling so that DOS and Windows clients can use files that don’t conform to their 8.3 format. The case of filenames can also be set using this feature. A number of options determine the name-mangling behavior provided by Samba; they are listed in this section. The testparm utility can be used to determine the defaults. Each server can set each of these name-mangling options. Table 15.2 details the substitutions that are available in Samba. Table 15.2. Name-Mangling Options Flag Description mangle case = yes/no Used to control whether filenames should be mangled, which are not completely specified by the default case configuration option. The default is no. case sensitive = yes/no Used to control whether filenames are case-sensitive. The default is no. default case = upper/lower Controls the default case for new filenames. The default is lower. preserve case = yes/no Controls whether new files are created with the case that the client uses. Otherwise, they are forced to be the default case. The default is yes. short preserve case = yes/no Controls whether new files (created by Samba) should conform to 8.3 syntax. In other words, if filenames are created in upper case or if they are forced to the default case. The default is yes. The default for version 2.0 of Samba is the same as a Windows NT server - it is case-insensitive but preserves case. Using SWAT The Samba Web Administration Tool (SWAT) is used to maintain the smb.conf configuration file. Using the SWAT tool frees you from having to maintain the configuration file by hand. Although some power users would rather edit than click, the majority of administrators find it easier to maintain the smb.conf file using SWAT. The interface for SWAT is a Web browser. You need to edit your /etc/inetd.conf and /etc/services to allow SWAT to be launched via inetd. As mentioned in the earlier section “Configuring for the Samba Web Administration Tool (SWAT),” you must ensure that your /etc/services and /etc/inetd.conf files have the proper entries for running SWAT. In the /etc/services file, you must have the following entry: swat 901/tcp /etc/inetd.conf should have an entry like this: swat stream tcp nowait.400 root /usr/local/samba/bin/swat swat If you have to edit one (or both) of these files, you must send the HUP signal to the inetd daemon. The following dialog demonstrates this: stimpy $ ps x | grep inet 124 ? S 0:00 /usr/sbin/inetd 3691 pts/0 S 0:00 grep inet stimpy $ kill -HUP 124 stimpy $ This tells the inetd daemon to reread its configuration files. page 271 #BREAK# Inside Linux To execute SWAT, you must first start your Web browser. As soon as the browser is running, you need to connect to http://localhost:901. After the browser connects, a dialog box appears, waiting for you to log in for the SWAT session (see Figure 15.3). Figure 15.3. SWAT Password dialog box. You must enter a valid username and password to access the SWAT tool. At this point, you can log in as the root user. Enter the username and password, and then click the OK button (or whatever is applicable for your browser). NOTE Although you can connect to SWAT from a remote machine, this is not recommended because your username and password would be sent in the clear. You can obtain information on executing SWAT with SSL from the http://www.samba.org Web site. When you have been authenticated, you see the home page for SWAT, as shown in Figure 15.4. Figure 15.4. SWAT Home page. page 272 #BREAK# Inside Linux This page contains a number of URL links. The buttons at the top of the page are Home, Globals, Shares, Printers, Status, View, and Password. Each button is associated with a configuration action. As you look down the page, you will notice a number of URL links. These are documentation links, providing a Web interface to Samba’s man pages. Although Figure 15.4 doesn’t show all the choices, the available documentation links are described in the following list: Daemons smbd: The SMB daemon nmbd: The NetBIOS name server Administrative Utilities smbstatus: Monitors Samba SWAT: Web configuration tool smbpasswd: Manages SMB passwords make_smbcodepage: Codepage creation testparm: Validates your config file testprns: Tests printer configuration General Utilities nmblookup: NetBIOS name query tool smbtar: SMB backup tool smbclient: Command-line SMB client Configuration Files smb.conf: Main Samba configuration file lmhosts: NetBIOS hosts file smbpasswd: SMB password file Miscellaneous Samba introduction Joining an NT domain Changing UNIX permissions using NT smbrun: Internal smbd utility To demonstrate the Web interface to the documentation, Figure 15.5 shows the man page for the smbd daemon in HTML format. page 273 #BREAK# Inside Linux Figure 15.5. The smbd (8) man page. Figure 15.5 verifies that the documentation is formatted in the style of a man page. The Name, Description, Synopsis, and Options (among other optional) sections are provided as you would expect. To view and modify the global settings for Samba, click the Globals button. Figure 15.6 shows a portion of the Globals page. Figure 15.6. The Globals SWAT page. page 274 #BREAK# Inside Linux You can see the first three of four options for the Base Options section of the Globals page. This page consists of seven sections: Base Options, Security Options, Logging Options, Tuning Options, Browse Options, WINS Options, and Locking Options. You can obtain help for each individual option found in each section. For example, if you need help with the netbios name option, shown in Figure 15.6, you click the word Help just to the left of the option name. Clicking Help opens a new browser window, displaying the appropriate section from the smb.conf(8) HTML man page. The following is a snippet taken from the displayed Web page after Help for netbios name was clicked: netbios name (G) This sets the NetBIOS name by which a Samba server is known. By default it is the same as the first component of the host’s DNS name. If a machine is a browse server or logon server this name (or the first component of the hosts DNS name) will be the name that these services are advertised under. See also “netbios aliases”. Default: Machine DNS name. Example: netbios name = MYNAME nis homedir (G) Get the home share … … You will notice a Set Default button to the right of each option. This button automatically sets the default value for the associated field. For example, if you click the Set Default button for the workgroup option in the Base Options section, the value WORKGROUP will be inserted into the text box. At the top of the Globals page are three other buttons. The button labeled Commit Changes writes any changes you have made to the smb.conf configuration file. The Reset Values button resets all the fields to the values they had before any changes were made. The button labeled Advanced View expands the available configuration options in two ways. First, it adds a number of new sections to the page. Second, it expands the number of individual options for any existing section. For example, the first section, Base Options, expands to offer the following individual options: workgroup, netbios name, server string, netbios aliases, and interfaces. As an example of a new major section, the Protocol Option section appears under the Advanced View page. The Protocol Option section offers a number of individual options, such as protocol, read bmpx, and read raw. You can return to the Basic View by clicking the View button at the top of the page. The Shares button, when clicked, displays the Shares page, shown in Figure 15.7. Figure 15.7. The Shares SWAT page. As shown in the figure, no shares are currently set up. You can create a new share by clicking the Create Share button. The two other buttons on this page are Choose Share and Delete Share. The third field, a combo box, allows you to choose among any available shares and display the settings. If you click Create Share or select a share from the combo box (and click Choose Share), the page will be expanded to show a number of options for the share. There is a Basic View and an Advanced View. The Commit Changes and Reset Values buttons are also available on the Shares page. page 275 #BREAK# Inside Linux If you want to add a printer to be shared, click the Printers button. Figure 15.8 shows the Printers page, which allows you to add a new printer share, modify an existing printer share, or delete an existing printer share. Figure 15.8. The Printers SWAT page. As shown in the figure, no printer shares are currently selected. All the functionality that is found on the Shares page is available here. If you select a printer from the combo box and click Choose Printer, or if you click Create Printer, the page will be expanded to reveal a number of options. Again, on this page you have the option of committing your changes, resetting the options to default values, and viewing (and modifying) the advanced options. The next available option is the Status button. It is used to show the current status of the Samba system. Figure 15.9 shows the Status page for Samba. Figure 15.9. The Status SWAT page. page 276 #BREAK# Inside Linux In this figure, the Samba system is not running. The Auto Refresh button is used to set a recursive timer that will automatically refresh the Web page with updated information. The default refresh cycle is every 30 seconds, but you can set it to almost any value. You can also set it to stop refreshing. Use the browser’s Refresh button to update the static status page. A number of other command buttons are available. The Start smbd and Restart smbd buttons are used to start the smbd daemon and restart a running smbd daemon, respectively. Figure 15.10 shows that the smbd daemon is running now that the Start smbd button was clicked. Figure 15.10. The Status SWAT page showing the smbd daemon running. This page also shows any shares that are enabled. There are a number of sections. The Active Connections section shows any users who are using a share. Some of the fields for this section are PID, Client, IP address, and Date. The Active Shares section shows any shares that are currently enabled. The fields for this section are Share, User, Group, PID, Client, and Date. The last section, Open Files, shows any files that are currently open. The column fields for this section are PID, Sharing, R/W, Oplock, File, and Date. The View button is used to view the contents of the smbd.conf file. The default view is called Normal View, and it shows a brief version of the file. Figure 15.11 shows the View page. Figure 15.11. The View SWAT page. page 277 #BREAK# Inside Linux You can click the Full View button to expand the listing, which shows the complete contents of the smbd.conf configuration file. Figure 15.11 shows the [global] options and some of the [homes] options. If you click the Full View button, the [global] section expands to show more than 200 options. The other sections also expand, and some new sections appear. The last configuration page is the Password page. You see it when you click the Password button. Figure 15.12 shows a partially obscured Password page. Figure 15.12. The Password SWAT page. The Password page allows you to maintain the usernames that will be accessing any of the Samba shares. Executing Samba Until now, we have been configuring Samba for use. The following sections discuss the execution of the two Samba daemons (which were covered briefly earlier in this chapter). The smbd daemon The smbd daemon provides file and print sharing services. Whenever a client request for a connection comes in, a Samba session is created. This session consists of a copy of the server (smbd). This server copy continues to provide services to the client until that client terminates. The configuration file is reloaded by the server every minute if changes have taken effect. You can force the smbd daemon to reread the file by sending the server a SIGHUP signal. The reloading of the configuration file is not performed by any server copies that exist for client connections. The client must reconnect in order for changes to be applied. The smbd process can accept a number of options on the command line. Table 15.3 describes these options. To shut down a user’s smbd process, you should send the SIGTERM (-15) signal and wait for the process to die on its own. It is not recommended that SIGKILL (-9) be used, except as a last resort. Doing this might leave the shared memory area in an inconsistent state. You can raise the debug log level for smbd by sending the SIGUSR1 signal. The SIGUSR2 signal is used to lower the debug level. page 278 #BREAK# Inside Linux Table 15.3. Command-Line Options for smbd Option Description -D Executes the server as a daemon. In other words, it runs in the background, accepting requests on the appropriate port. This is the recommended way of executing smbd. The default operation is for the server to not operate as a daemon. -a Specifies that each new connection will append log messages to the log file. This is the default behavior. -o Specifies that log files will be overwritten when opened. The default is to append to the log files. -P The passive option, which causes smbd to not send out network traffic. This is useful for developers when debugging. -h Prints help information for smbd and exits. -V Prints the version number for smbd and exits. -d debuglevel Specifies the debug level. The valid range is from 0 to 10; the default is 0. The higher the value, the more detailed the messages. -l log file Specifies that log file is the log filename where informational and debug messages from the server will be logged. -p port number Specifies the port number. The default value is 139. This port number is the port to use for connection requests from Samba clients. -s configuration file Specifies the configuration file. See the smb.conf (5) man page for more information. -i scope Specifies a NetBIOS scope that the server uses to communicate with when generating NetBIOS names. The nmbd daemon The nmbd program (the NetBIOS name server) provides NetBIOS-over-IP naming services to Samba clients. The nmbd server understands and responds to NetBIOS (over IP) name service requests, such as those generated by SMBD/CIFS clients (Windows and LanManager clients). The server also engages in browsing protocols, such as those for the Windows Network Neighborhood view. The nmbd server can respond to an SMB/CIFS client that wants to know the IP number for the SMB/CIFS server. If the NetBIOS name is specified for the nmbd server, it will respond with the host IP number that it is running on. The nmbd server can be used as a Windows Internet Name Server (WINS) server, meaning it will serve as a WINS database server. The nmbd server will create a database from name registration requests from and replies to clients. The nmbd process can accept a number of options on the command line. Table 15.4 describes these options. To shut down the nmbd process, you should send the SIGTERM (-15) signal and wait for the process to die. You should not use the SIGKILL (-9) signal, except as a last resort. Using the SIGKILL signal might leave the shared memory area in an inconsistent state. You can send the SIGHUP signal to nmbd. This causes nmbd to dump the name lists into the file namelist.debug, usually in the var/locks directory. This signal also causes nmbd to dump its server database to the log.nmb file. You can raise the debug log level for nmbd by sending the SIGUSR1 signal. The SIGUSR2 signal is used to lower the debug level. page 279 #BREAK# Inside Linux Table 15.4. Command-Line Options for nmbd Option Description -D Executes the server as a daemon. In other words, it runs in the background, accepting requests on the appropriate port. This is the recommended way of executing nmbd. The default operation is for the server to not operate as a daemon. -a Specifies that each new connection will append log messages to the log file. This is the default behavior. -o Specifies that log files will be overwritten when opened. The default is to append to the log files. -h Prints help information for nmbd and exits. -V Prints the version number for nmbd and exits. -H filename Identifies the NetBIOS lmhosts file, which is a list of NetBIOS names to IP addresses that is loaded by the nmbd server. It is used by the name resolution mechanism to resolve NetBIOS name queries required by the server. -d debuglevel Specifies the debug level. The valid range is from 0 to 10; the default is 0. The higher the value, the more detailed the messages. -l logfile Specifies a filename to which operational data from the nmbd server will be logged. The log filename is created by appending the .nmb extension to the specified base name. Some common defaults are /usr/local/samba/var/log.nmb, /usr/samba/var/log.nmb, and /var/log/log.nmb. -n primary NetBIOS name Overrides the NetBIOS name Samba uses for itself. This overrides the setting in the smb.conf file. -p UDP port number The UDP port number that nmbd responds to name queries on. The default is 137. -s configuration file The configuration filename to read. See the smbd.conf man page for more details. -i scope Specifies a NetBIOS scope that nmbd uses to communicate with when generating NetBIOS names. Using smbclient The smbclient program, providing an FTP-like interface, is a Samba client used to access SMB/CIFS shares on servers. Unlike NFS, smbclient does not provide the ability to mount a share on a local directory. The usage for smbclient is as follows: smbclient servicename
[-s smb.conf] [-O socket options] [-R name resolve order] [-M NetBIOS name] [-i scope] [-N] [-n NetBIOS name] [-d debuglevel] [-P] [-p port] [-l log basename] [-h] [-I dest IP] [-E] [-U username] [-L NetBIOS name] [-t terminal code] [-m max protocol] [-b buffersize] [-W workgroup] [-TIXFqgbNan] [-D directory] [-c command string] The smbclient program accepts a number of command-line options. Table 15.5 describes these options. Table 15.5. Command-Line Options for smbclient Option Description servicename The name of the service you want to use on the server. The service name is of the form //server/service, where server is the NetBIOS name and service is the name of the service offered. password The password required to access the service on the server. There is no default password. If a password is not supplied and the -N option is not specified, the client prompts for a password. page 280 #BREAK# Inside Linux Option Description -s smb.conf Identifies the pathname of the smb.conf file. -O socket options Used to set the TCP socket options for the client. -R name resolve order Allows the user to determine the name resolution services to use when looking up the NetBIOS name of the host to connect to. Available options are lmhosts, host, wins, and bcast. See the smbclient man page for more information. -M NetBIOS name Allows you to send messages with the WinPopup protocol. -i scope Specifies the NetBIOS scope that the smbclient program will use to communicate with when generating NetBIOS names. -N Suppresses the password prompt from the client to the user. -n NetBIOS name Allows you to override the hostname. -d debuglevel debuglevel is an integer from 0 to 10, or the letter A. The default is 0. The higher this value, the more detail that will be logged. -p port The TCP port number to be used when making connections to the server. The default is 139. -l logfilename Specifies the base filename (logfilename) where operational data will be logged. -h Prints a usage message for the smbclient and exits. -I IP address The IP address of the server to connect to. -E Causes smbclient to write messages to the standard error stream rather than to the standard output stream. -U username Specifies the username to be used by the client to make a connection. -L Allows you to look at the available services. -t terminal code Specifies how to interpret filenames coming from the remote server. -b buffersize Changes the size of the transmit and send buffer. The default is 65520 bytes. -W workgroup Defines the workgroup to connect to, overriding the default workgroup specified in the smb.conf file. -T tar options The smbclient program can be used to create tar-compatible files for the files on an SMB/CIFS share. -D initial directory Changes to the current directory before starting. -c command string A semicolon-separated list of commands that are to be executed instead of prompting from stdin. The user is provided with an smbclient prompt upon execution of the program. The smbclient command prompt is similar to the following: smb:> This prompt indicates that the smbclient program is waiting for a command to execute. Each command consists of a command word, optionally followed by command options. Table 15.6 lists the commands available for the smbclient program. page 281 #BREAK# Inside Linux Table 15.6. Commands for the smbclient Program Command Description ? [command] If command is specified, a brief description of the specified command is displayed. ! [shell command] If specified, a shell is executed locally with the specified shell command. cd [directory name] The current working directory on the server is changed to the directory specified. del mask A request is made to the server to delete from the current working directory all files matching mask. dir mask Used to show a list of files matching mask in the current working directory. exit Terminates the server connection and exits. get remote-file-name [local file name] Copies the file called remote-file-name from the server to the client. help [command] The same as the ? command. lcd [directory name] The current working directory on the local machine is changed to the directory specified. lowercase Toggles the lowercasing of filenames. Used with the get and mget commands. ls mask Refers to the dir command in this table. mask mask Allows the user to set a mask to be used during recursive operation of the mget and mput commands. md directory name The same as the mkdir command. mget mask Copies files matching mask from the server to the local machine. mkdir directory name Creates a new directory on the server. mput mask Copies files matching mask on the local machine to the working directory on the server. print file name Prints the file name file from the local machine to a print service on the server. printmode graphics or text Sets print mode for binary data or text. prompt Toggles the prompting for filenames for the mget and mput commands. put local file name [remote file name] Copies the file called local file name from the client to the server. queue Displays the print queue. quit The same as the exit command. rd directory name The same as the rmdir command. recurse Toggles directory recursion for the commands mget and mput. rm mask Removes files matching mask from the server. rmdir directory name Removes the specified directory from the server. tar [IXbgNa] Performs a tar operation. setmode filename
A version of the DOS attrib command to set file permissions. An example would be setmode myfile +r to set myfile to read-only. page 282 #BREAK# Inside Linux Summary In this chapter, we discussed the use of Samba. We began our journey with an overview of Samba. Samba is a suite of applications that can speak the Server Message Block (SMB) protocol. Samba runs on UNIX platforms but can speak to Windows clients natively. Samba is available on the CD-ROM of most Linux distributions. If it is not available on your distribution, you can obtain it from http://www.samba.org. You can obtain the Samba package as a binary or CVS source distribution. Samba is configured by a single configuration file named smb.conf, which completely controls Samba’s behavior. Variable substitution and name mangling were also discussed. You can edit the configuration file manually or use the Samba Web Administration Tool (SWAT). SWAT is a browser- based administration tool used to configure Samba, which ultimately modifies the smb.conf file. Next, we discussed the execution of the Samba daemons, including the smbd and nmbd daemons. The smbd daemon provides file and print services to clients, and nmbd provides NetBIOS name resolution and browsing. Finally, we discussed the smbclient program, which provides an FTP-like interface used to access SMB/CIFS shares on servers. page 283 #BREAK# Inside Linux Chapter 16. Apache Web Server If you want information on the best and most popular Web server on the Internet, you have come to the right place. In this chapter, you take a drive through Apache territory. This chapter is dedicated to understanding, acquiring, configuring, and using the Apache Web server. We will do in one chapter what many say requires a book - that is, provide the information necessary to install and run Apache. Apache Overview Apache has found its place in life as the most popular Web server on the Internet. Apache has held the title since the first part of 1996. Netcraft (http://www.netcraft.com), a networking consulting company in England is known worldwide for its Web Server Survey (http://www.netcraft.com/survey). In late January 2 000, I visited the site to check on the latest results of the survey. The number of developers working on Apache in December 1999 was 5,209,677, which accounted for 54.49 percent of all respondents. Web server usage showed Apache having an installed base of 4,847,992 units, which accounted for 54.81 percent of the respondents. In fact, the Apache Web server is more widely used than all other Web servers combined. Figure 16.1 depicts the statistics graphically. Figure 16.1. The Netcraft Web Server Survey statistics. Apache is an open-source HTTP server that is available for a variety of desktop and server operating systems, including Linux, A/UX (Apple’s UNIX), BSD-based (FreeBSD, and so on), Digital UNIX, HPUX, Solaris, SunOS 4.x, and Windows platforms. The Apache Web server is an efficient and extensible server, providing HTTP services that conform to the current HTTP standards. The Apache Group does not have any outside sponsors or institutional influence and consists of true server users. These server users are people who make their living running Web servers. These user/developers are empathetic to other server users and strive to provide the functionality suggested by other server users. Some prominent organizations use (or have switched to) the Apache Web server. Some of these organizations are Hotwired (http://www.hotwired.com), the MIT AI Laboratory (http://www.ai.mit.edu), and the Internet Movie Database (http://www.imdb.com), among others. If you are interested in discovering who is running Apache, an incomplete list of sites is maintained at http://www.apache.org/info/apache_users.html. You might be interested to know why the name Apache was chosen. Originally, a group of people worked together to provide patches for the NCSA HTTPd Web server version 1.3 (a maintenance release) in early 1995. This group of people became what is known as the Apache Group. After these patches were collected and incorporated, the result was a patchy server -or more appropriately, “A Patchy” server. page 284 #BREAK# Inside Linux Choosing an Apache Package You may be wrestling with the decision as to what platform on which to run the Apache Web server. You might be reading this book because you want to discover the merits of using Linux. You might be reading this chapter because you have to get Apache up and running at your office. Or you might want to run your own personal Web site on your home machine. There is really only one true platform choice for running Apache. Collectively, that platform is Linux/UNIX - and more specifically, Linux. After all, this book is about Linux. Your best bet is to pick up a distribution of Linux, such as Caldera’s OpenLinux, Slackware, Red Hat, SuSE, or TurboLinux, to name a few. Next, incorporate Apache to provide a secure and robust Web server. Most Linux vendors bundle Apache with their distributions, and some vendors provide server-specific products, such as TurboLinux Server or Red Hat Linux Professional (at a nominal increase in price). The alternative is to run Apache on some Win32 platform, which really is not an alternative. You can run Apache on Windows 95, Windows 98, and Windows NT, but some security issues exist regarding each of those operating systems. The Windows 95 and Windows 98 platforms have no real security to speak of, especially from a server perspective. Although Windows NT is thought of as a server platform, a number of security holes are well known. Ironically, one security hole is using Linux to gain access to an NTFS drive! The fact is, Windows NT has not stood the test of time as UNIX has. Using Apache under a Win32 platform might be okay for Web site testing, but if your business relies on reliable and secure Web hosting, put your money on the Linux platform. Obtaining and Installing Apache Check the CD-ROM for your Linux distribution to see whether Apache is included. If not, or if you want to have the latest version of Apache, you can obtain the current release from the Apache Software Foundation at http://www.apache.org. You can download Apache as a binary package or as a build package. The binary distribution of Apache for Linux is available at http://www.apache.org/dist/binaries/linux. The binary distribution contains the required Apache modules as shared objects. This allows you to enable or disable modules using the LoadModule and AddModule directives within the configuration file without having to recompile the Apache source. You can obtain a complete Apache distribution that comes with complete source code at http://www.apache.org/dist. Of course, you will have to build the Apache package. This process is not that difficult, given enough time. As of this writing, the gzipped source package, apache_1.3.9.tar.gz, is 1.4MB. As a contrast, the gzipped binary package for an Intel Pentium machine, apache_1.3.9-i686-whatever-linux2.tar.gz, is 2.3MB. It will take you almost twice as long to download the binary version (about 30 minutes using a 28.8 connection), but you will be ready to roll after you unzip the binary package. In this chapter, I discuss Apache version 1.3, which is the current version as of the writing of this chapter. More specifically, the version detailed here is version 1.3.9 of Apache. It is quite possible that Apache is installed on your machine. You may have installed it at the time you installed your Linux distribution. You can check for Apache’s existence, as shown in the following dialog: stimpy $ httpd -v Server version: Apache/1.3.9 (Unix) (SuSE/Linux) Server built: Nov 9 1999 02:46:17 stimpy $ httpd -V Server version: Apache/1.3.9 (Unix) (SuSE/Linux) Server built: Nov 9 1999 02:46:17 Server’s Module Magic Number: 19990320:6 Server compiled with…. -D EAPI -D HAVE_MMAP -D HAVE_SHMGET -D USE_SHMGET_SCOREBOARD -D USE_MMAP_FILES -D USE_FCNTL_SERIALIZED_ACCEPT -D HTTPD_ROOT=”/usr/local/httpd” -D SUEXEC_BIN=”/usr/sbin/suexec” page 285 #BREAK# Inside Linux -D DEFAULT_PIDLOG=”/var/logs/httpd.pid” -D DEFAULT_SCOREBOARD=”/var/logs/httpd.scoreboard” -D DEFAULT_LOCKFILE=”/var/logs/httpd.lock” -D DEFAULT_XFERLOG=”/var/log/access_log” -D DEFAULT_ERRORLOG=”/var/log/error_log” -D TYPES_CONFIG_FILE=”/etc/httpd/mime.types” -D SERVER_CONFIG_FILE=”/etc/httpd/httpd.conf” -D ACCESS_CONFIG_FILE=”/etc/httpd/access.conf” -D RESOURCE_CONFIG_FILE=”/etc/httpd/srm.conf” stimpy $ httpd -t Syntax OK Notice that there are three invocations (see bolded text in preceding code) of the httpd daemon: two requesting version information and the third performing a syntax test. The first variation, httpd -v, prints the version of the httpd daemon and then exits. The second variation, httpd -V, prints the version and build parameters of the httpd daemon and then exits. The third invocation, httpd -t, tells the httpd daemon to run syntax tests on the configuration files only. The program exits after syntax parsing with either a code of zero (Syntax OK) or not zero (Syntax Error). The following dialog demonstrates this execution: stimpy $ httpd -t Syntax OK The httpd daemon performs a syntax check on the configuration files, provides a report, and then exits. You can see how httpd reports success, but what if a problem exists with the configuration file? The following dialog demonstrates this: stimpy $ httpd -t Syntax error on line 82 of /etc/httpd/httpd.conf: Invalid command ‘PikFile’, perhaps misspelled or defined by a module not included in the server configuration That entry should be Pidfile, and it identifies the filename that the daemon will use to write its process ID number to after it has started. The error reporting only provides FRS (find, report, stop) functionality. The following snippet from the /etc/httpd/httpd.conf file contains three errors, one on each line: TerverRoot “/usr/local/httpd” MockFile /var/lock/subsys/httpd/httpd.accept.lock SidFile /var/run/httpd.pid The entries should be ServerRoot, LockFile, and Pidfile, respectively. The httpd daemon reports only on the first error it encounters; it reports the error and then stops. Thus, you have to fix the TerverRoot entry first, and then rerun the httpd -t command again to see the second error, and so on. Beginning the Apache Installation After you have downloaded the Apache source package, you have to uncompress it and then unarchive it. The compressed file’s extension determines the tool you use for decompression. If the extension is .Z, you use the uncompress command. If the extension is .gz, you use the gzip (or gunzip) command. After the file is decompressed, you need to run the tar command to de-archive the contents. Doing this creates a number of directories and places various files in each of those directories. You can place the apache_1.3.9.tar.gz (or whatever version you have) into the /usr/local/etc/apache or /usr/local/apache directory. From this directory, you decompress and de-archive the contents. The following dialog demonstrates the sequence: stimpy $ gunzip apache_1.3.9.tar.gz stimpy $ ls -al total 6107 drwxr-xr-x 2 root root 1024 Jan 30 10:32 . drwxr-x—7 root root 1024 Jan 30 10:31 .. -rw-r–r–1 root root 6225920 Jan 30 07:38 apache_1.3.9.tar stimpy $ tar xvf apache_1.3.9.tar apache_1.3.9/ apache_1.3.9/src/ apache_1.3.9/src/ap/ apache_1.3.9/src/ap/.indent.pro apache_1.3.9/src/ap/Makefile.tmpl apache_1.3.9/src/ap/ap.dsp apache_1.3.9/src/ap/ap.mak … apache_1.3.9/icons/small/rainbow.gif apache_1.3.9/icons/small/transfer.gif apache_1.3.9/icons/small/unknown.gif apache_1.3.9/icons/small/uu.gif apache_1.3.9/logs/ page 286 #BREAK# Inside Linux Alternatively, you can execute the tar command to perform both the unzipping and de-archiving in one step, as shown in the following dialog: stimpy $ tar apache zxvf 1.3.9.tar.gz apache_1.3.9/ apache_1.3.9/src/ apache_1.3.9/src/ap/ apache_1.3.9/src/ap/ap.dsp apache_1.3.9/src/ap/ap.mak … apache_1.3.9/icons/small/rainbow.gif apache_1.3.9/icons/small/uu.gif apache_1.3.9/logs/ Personally, I prefer the two-step process because there may be documentation to read before running the tar extract. The important commands are in bold text. The tar command displays the name of the directory and file as it is processed. If the filename’s extension is .Z, you execute the uncompress command as shown in the following sample dialog: stimpy $ uncompress apache_1.3.9.tar.Z stimpy $ ls -al total 6107 drwxr-xr-x 2 root root 1024 Jan 30 10:32 . drwxr-x—7 root root 1024 Jan 30 10:31 .. -rw-r–r–1 root root 6225920 Jan 30 07:38 apache_1.3.9.tar Again, you can execute the tar command to fulfill both the unzip and de-archive operations in one step. Building Apache the Easy Way Either way, the next step is to execute the build process. The first step is to execute the configure command supplied in the Apache package. The following dialog demonstrates this: stimpy $ cd apache stimpy $ ./configure Configuring for Apache, Version 1.3.9 + Warning: Configuring Apache with default settings. + This is probably not what you really want. + Please read the README.configure and INSTALL files + first or at least run ‘./configure –help’ for + a compact summary of available options. + using installation path layout: Apache (config.layout) Creating Makefile Creating Configuration.apaci in src Creating Makefile in src + configured for Linux platform + setting C compiler to gcc + setting C pre-processor to gcc -E + checking for system header files + adding selected modules + checking size of various data types + doing sanity check on compiler and options Creating Makefile in src/support Creating Makefile in src/regex Creating Makefile in src/os/unix Creating Makefile in src/ap Creating Makefile in src/main Creating Makefile in src/lib/expat-lite Creating Makefile in src/modules/standard The configure command is executed (shown as bold text in the preceding code listing), which then displays a number of status text lines. A number of makefiles are created, along with a number of options for building the source code. The next command you execute is the make command, as shown in the following sample dialog: stimpy $ make ===> src make[1]: Entering directory `/mnt/tool/root/apache/apache_1.3.9′ make[2]: Entering directory `/mnt/tool/root/apache/apache_1.3.9/src’ ===> src/regex sh ./mkh -p regcomp.c >regcomp.ih gcc -I. -I../os/unix -I../include … -c regcomp.c -o regcomp.o … sed apxs -e ’s%@TARGET@%httpd%g’ -e ’s%@CC@%gcc%g’ -e ’s%@CFLAGS@% -DLINUX=2 … `../apaci`%g’ -e ’s%@CFLAGS_SHLIB@%%g’ -e ’s%@LD_SHLIB@%%g’ -e ’s%@LDFLAGS_MOD_SHLIB@%%g’ -e ’s%@LIBS_SHLIB@%%g’ && chmod a+x apxs page 287 #BREAK# Inside Linux make[2]: Leaving directory `/mnt/tool/root/apache/apache_1.3.9/src/support’ <=== src/support make[1]: Leaving directory `/mnt/tool/root/apache/apache_1.3.9' <=== src Various status messages are displayed as the package is being built. The compiler, the assembler, and the linker, among other tools, are executed to produce the Apache package. The process does not take very long at all; I tested the build on a Pentium 166mHz with 96MB RAM, and the build took about 13 minutes. The complete process, including the configuration and build process, consumed approximately 15 minutes total. I tested the configure and build processes under Slackware 7.0, TurboLinux 4.0, Red Hat 6.1, SuSE 6.3, and OpenLinux 2.3 and experienced no problems. This out-of-the-box procedure is recommended because it is easier and less time consuming than manually configuring and building Apache. Building Apache the Manual Way The second method of building the Apache package is to do it manually. Building Apache manually takes a little longer (than the "easy way") and involves more research on your part. The advantage is that you have more control over the configuration and build process. If you want more control, or if you want to learn about the intricacies of Apache, the manual method is the way to go. To begin the build process, as with any package build, you should examine any README files. The Apache README file suggests that you read the INSTALL file (in the same directory as the README), so let us begin there. Build Requirements A concern for any package is the amount of disk space consumed. For Apache, the disk requirement is approximately 12MB of free disk space, but this requirement is only temporary. After the installation is complete, Apache occupies only about 3MB of disk space. The actual amount depends on the modules that have been compiled in the Apache build. For the compiler, you should be using an ANSI-compliant C compiler. I recommend that you use the GNU C compiler from the Free Software Foundation (FSF). This compiler comes on most distributions of Linux. If you do not have it on your CD-ROM distribution, you can download it for free at http://www.gnu.org. If you do not want to (or cannot) use GCC, be sure that the compiler you use is ANSI compliant. Apache can load modules at runtime using the Dynamic Shared Object (DSO) support feature . Apache performs this functionality using the dlopen() and dlsym() system function calls. The dlopen() call loads a dynamic library from the named file to the function. If the open is successful, a handle for the dynamic library is returned to the caller. The dlsym() call accepts a handle for a dynamic library and a symbol name, and it returns the address where the symbol is loaded. Unfortunately, the DSO feature is not a portable mechanism, so DSO may not be available on all platforms. Currently, the platforms supporting DSO are Linux, AIX, BSDI, DYNIX/ptx, Digital UNIX, FreeBSD, HPUX, IRIX, Mac OS, Mac OS X Server, NetBSD, OpenBSD, OpenStep/Mach, SCO, Solaris, SunOS, UNIXWare, and ReliantUNIX. Ultrix is not supported. It is not required, but I recommend that you have a Perl 5 Interpreter available. If the Perl interpreter is not available, the build and installation will still succeed. Some of the support scripts will not be available, such as the apxs and dbmmanage Perl scripts. Perl 5 is the version you want available; if you are not sure how to switch, use the --with-perl option. Modifying the Configuration File The next step is to make a copy of the Configuration.tmpl file. You can find this file in the src directory. Copy this file to the file named Configuration. The following sample demonstrates this: stimpy $ cp Configuration.tmpl Configuration The file Configuration.tmpl is a template and should never be modified directly, and a script file (named Configure) actually uses the Configuration file. Do not edit the file named Makefile either, because it is auto-generated by Configure. You edit the Configuration file to select the modules to be included. Additionally, you can set various compiler flags in the Configuration file. page 288 #BREAK# Inside Linux The Configuration file has five types of line entries. Like most other Linux configuration files, the comment character is included as a type. The # character is used to denote a comment. The second type of entry designates a Makefile option. The third type of entry is the AddModule entry, which specifies a module to be included. The fourth type is a Rule entry, which directs Configure to create the Makefile file. The fifth entry type is the %Module keyword. This defines a module that is to be compiled in, but disabled. The Configuration file is heavily commented; open it up in your favorite editor and take a look at it. The first section is the Makefile configuration. The options are described in Table 16.1. Table 16.1. Configuration File -Makefile Section Flag Description EXTRA_CFLAGS Added to the standard Makefile flags for the compiler. EXTRA_LDFLAGS Added to the standard Makefile flags for the linker. EXTRA_LIBS Added to the standard Makefile flags as an additional flag for a library. EXTRA_INCLUDES Added to the standard Makefile flags for identification of include file(s). EXTRA_DEPS Added as additional Makefile dependencies to external files, such as third-party libraries. #CC Settings for the C Compiler - the settings here have priority. The default is that this line is disabled (commented out). If not set, Configure attempts to determine the compiler to use. #CPP Settings for the C++ Compiler - the settings here have priority. The default is that this line is disabled (commented out). If not set, Configure attempts to determine the compiler to use. #OPTIM Optimization flags - the optimization settings here take priority. #RANLIB Path to the ranlib program, which generates an index to the contents of an archive and stores it in the archive. (You probably do not need this.) Most users will not have to bother with the Makefile section. Configure will try to determine the operating system and compiler and provide the proper settings based on its findings. If Configure or the compiler gets quirky, you will probably have to define CC, CPP, and OPTIM. The AddModule section can get fairly detailed. Table 16.2 describes the modules that are available at the time of this writing. Table 16.2. Configuration File -AddModule Section Module Description mod_access Host-based access control. mod_auth User authentication using text files. mod_auth_digest MD5 authentication (experimental). mod_browser Apache 1.2.* only. Set environment variables based on User- Agent strings. Replaced by mod_setenvif in Apache 1.3 and up. mod_cgi Invoking CGI scripts. mod_cookies Up to Apache 1.1.1. Support for Netscapelike cookies. Replaced in Apache 1.2 by mod_usertrack. mod_digest MD5 authentication. mod_dir Basic directory handling. page 289 #BREAK# Inside Linux Module Description mod_dld Apache 1.2.* and earlier. Start-time linking with the GNU libdld. Replaced in Apache 1.3 by mod_so. mod_dll Apache 1.3b1 to 1.3b5 only. Replaced in 1.3b6 by mod_so. mod_env Passing of environments to CGI scripts. mod_example Apache 1.2 and up. Demonstrates Apache API. mod_expires Apache 1.2 and up. Apply "Expires:" headers to resources. mod_headers Apache 1.2 and up. Add arbitrary HTTP headers to resources. mod_imap Imagemap file handler. mod_include Server-parsed documents. mod_info Server configuration information. mod_isapi Windows ISAPI extension support. mod_log_agent Logging of user agents. mod_log_common Up to Apache 1.1.1. Standard logging in the common logfile format. Replaced by the mod_log_config module in Apache 1.2 and up. mod_log_config User-configurable logging replacement for mod_log_common. mod_log_referer Logs document references. mod_mime Determines document types using file extensions. mod_mime_magic Determines document types using "magic numbers." mod_mmap_static Maps files into memory for faster serving. mod_negotiation Content negotiation. mod_proxy Caching proxy capabilities mod_rewrite Apache 1.2 and up. Powerful URI-to-filename mapping using regular expressions. mod_setenvif Apache 1.3 and up. Set environment variables based on client information. mod_so Apache 1.3 and up. Experimental support for loading modules (DLLs on Windows) at runtime. mod_spelling Apache 1.3 and up. Automatically correct minor typos in URLs. mod_status Server status display. mod_userdir User home directories. mod_unique_id Apache 1.3 and up. Generate unique request identifier for every request. mod_usertrack Apache 1.2 and up. User tracking using cookies (replacement for mod_cookies.c). mod_vhost_alias Apache 1.3.7 and up. Support for dynamically configured mass virtual hosting. /experimental/mod_mmap_static.o Can make some Web servers faster. However, because it is an experimental module, I recommend that you do not use it. Documentation is not available so as to detract you from enabling it. page 290 #BREAK# Inside Linux Module Description mod_vhost_alias.o Provides support for mass virtual hosting. This is enabled by dynamically changing the document root and CGI directory. mod_env.o Sets up environment variables that are passed to CGI and SSI scripts. mod_log_config.o Determines the logging configuration. mod_log_agent.o Optional module for NCSA user-agent logging compatibility. I recommend that you use access_log. mod_log_referer.o Optional module for NCSA referer logging compatibility. I recommend that you use access_log. mod_mime_magic.o Determines a file's type by examining it and comparing the results against a database of signatures - based on the UNIX file command. mod_mime.o Maps filename extensions to content types, encodings, and "magic" type handlers. mod_negotiation.o Permits content selection based on Accept* headers. mod_status.o Permits the server to display details about its performance and its status. A performance hit is inevitable. mod_info.o Displays the server's configuration information including modules - useful for debugging. mod_include.o Translates server-side include statements in text files. mod_autoindex.o Handles requests for directories that have no index file. mod_dir.o Handles requests on directories and directory index files. mod_cgi.o Handles CGI scripts. mod_asis.o Implements .asis file types, allowing embedded HTTP headers at the beginning of a document. mod_imap.o Handles internal imagemaps. mod_actions.o Specifies that CGI scripts act as "handlers" for specific files. mod_spelling.o Tries to correct URL misspellings that users might have supplied - catches the majority of misspelled requests. mod_userdir.o Selects resource directories using username and a common prefix. mod_alias.o Provides URL translation and redirection. mod_rewrite.o Permits URI-to-URI and URI-to-filename mapping using a regular expression-based rule-controlled engine. mod_auth_anon.o Allows for anonymous-FTP-style username and password authentication. mod_auth_dbm.o Work with Berkeley DB files - make sure there is support for DBM files on your system. You may need to adjust EXTRA_LIBS. Should not be used with the mod_auth_db.o module. mod_auth_db.o Work with Berkeley DB files - make sure there is support for DBM files on your system. You may need to adjust EXTRA_LIBS. Should not be used with the mod_auth_dbm.o module. mod_digest.o Implements HTTP Digest Authentication instead of Basic Auth (less secure). page 291 #BREAK# Inside Linux Module Description /experimental/mod_auth_digest.o Implements HTTP/1.1 Digest Authentication versus Basic Auth (less secure). Although this is a mod_digest update, it is still experimental. /proxy/libproxy.a Allows the server to act as a proxy server for HTTP and FTP. mod_cern_meta.o Utilizes metainformation files compatible with the CERN Web server. mod_expires.o Applies Expires headers to resources. mod_headers.o Sets arbitrary HTTP response headers. mod_usertrack.o Utilizes Netscape cookies to construct and log click-trails from Netscape cookies. For user tracking only. modules/example/mod_example.o Demonstrates the use of the API. Should be used only for testing -never use this on a production server. mod_unique_id.o Generates unique identifiers for each hit. May not work on all systems. mod_so.o Allows adding modules to Apache without recompiling. Currently experimental - supported only on a subset of the platforms. mod_setenvif.o Allows you to set environment variables based on HTTP header fields in the request. Although the modules classified as "experimental" are included in the previous table, I highly recommend that you not include those modules in a production Web server. Next, let's take a look at rules. The syntax for a rule in the Configuration file is shown in the following sample: Rule RULE=value value can be either yes or default. If the value is yes, Configure performs the rule. If the value is default, Configure takes a best guess. Table 16.3 describes the current rules. Table 16.3. Configuration File -Rules Section Rule Description SOCKS4 If yes, add the socks library location to EXTRA_LIBS, otherwise -L/usr/local/lib lsocks is assumed. SOCKS5 If yes, add the socks5 library location to EXTRA_LIBS, otherwise -L/usr/local/lib lsocks5 is assumed. IRIXNIS Effective only if you are running SGI IRIX. IRIXN32 If running a version of IRIX using n32 libraries, Configure will use those instead of the o32 libraries. PARANOID Introduced in version 1.3. Allows modules to control how Configure works. If PARANOID is yes, Configure will print the code that the modules execute. EXPAT Incorporates James Clark's Expat package into Apache. The default is to include it if the lib/expat-lite/ directory exists. DEV_RANDOM Used only when compiling mod_auth_digest. WANTHSREGEX Apache requires a POSIX regex implementation. Henry Spencer's excellent regex package is included with Apache and can be used. page 292 #BREAK# Inside Linux Be sure to check the documentation included with the Apache package for changes to the Rules section. Be sure to examine the Configuration file and set any rules to the appropriate values for your Apache implementation. Building Apache After you have the Configuration file with the proper settings for your Apache implementation, the next step is to build Apache. Before you execute the build, however, you need to be sure the configuration is set properly. You do this with the Configure command. The following dialog demonstrates this: stimpy $ cd src stimpy $ ./Configure Using config file: Configuration Creating Makefile + configured for Linux platform + setting C compiler to gcc + setting C pre-processor to gcc -E + checking for system header files + adding selected modules + checking size of various data types + doing sanity check on compiler and options Creating Makefile in support Creating Makefile in regex Creating Makefile in os/unix Creating Makefile in ap Creating Makefile in main Creating Makefile in lib/expat-lite Creating Makefile in modules/standard stimpy $ Your output should resemble the previous sample. The Configure command is used to create the various Makefiles required to build Apache. Finally, you need to build Apache. The following dialog shows how to start the build process: stimpy $ make ===> regex make[1]: Nothing to be done for `all’. <=== regex ===> os/unix gcc -c -I … … <=== modules/standard <=== modules gcc -c -I./os/unix -I./include -DLINUX=2 -DUSE_HSREGEX -DUSE_EXPAT -I./lib/expat lite modules.c gcc -c -I./os/unix -I./include -DLINUX=2 -DUSE_HSREGEX -DUSE_EXPAT -I./lib/expatlite buildmark.c gcc -DLINUX=2 -DUSE_HSREGEX -DUSE_EXPAT -I./lib/expat-lite -o httpd buildmark.o modules.o libstandard.a main/libmain.a ./os/unix/libos.a ap/libap.a regex/libregex.a lib/expat-lite/libexpat.a -lm -lcrypt stimpy $ Various commands are executed from the Makefile. The command that is being executed and the results are displayed to the standard output. After the make has finished, you should have an executable within the src directory named httpd, as shown in the following sample dialog: stimpy $ ls -al -rwxr-xr-x 1 root root 673 Jan 30 10:44 apaci -rw-r--r--1 161 20 3126 Jan 1 1999 buildmark.c ... -rw-r--r--1 root root 952 Jan 31 00:21 buildmark.o drwxr-xr-x 2 161 20 1024 Jan 31 00:14 helpers -rwxr-xr-x 1 root root 631900 Jan 31 00:22 httpd drwxr-xr-x 2 161 20 1024 Jan 30 10:44 include drwxr-xr-x 3 161 20 1024 Jan 30 10:45 lib drwxr-xr-x 2 161 20 1024 Jan 31 00:21 main stimpy $ As you can see, the build was successful and the Web server is ready to go. It is always an exciting moment to execute an application you have just built, especially an application as important as a Web server! Be forewarned, however, that you could receive an error upon invocation of httpd. The following dialog shows what happened when I executed the httpd server. stimpy $ ./httpd fopen: No such file or directory httpd: could not open document config file /usr/local/apache/conf/httpd.conf stimpy $ Obviously, the configuration file httpd.conf is not found in the identified path. The sections that follow continue the Apache configuration process. page 293 #BREAK# Inside Linux Apache Runtime Configuration As mentioned in the previous section, you will have a binary executable file named httpd, which should be found in the src directory. Optionally, if you downloaded the binary distribution, the Linux httpd binary will already exist. A third option is that Apache is already installed from your Linux distribution. In this section, I assume that you have just built the Apache executable and that you are ready to install and configure it for runtime use. You can, if you wish, run Apache from the same directory tree in which you built it. The configuration is designed to function in this manner. If you want to run Apache from another tree, you need to create a root directory and move the conf, logs, and icons directories there. Runtime Configuration Files Apache utilizes the directives from the three configuration files to initialize and execute. The three configuration files are named access.conf, httpd.conf, and srm.conf; they are found in the conf directory. Three template files match each one of these runtime configuration files: access.conf-dist, httpd.conf-dist, and srm.conf-dist found in the conf directory. I recommend that you execute the cp command, creating the runtime versions of each configuration file. Do not execute the mv command to rename the template files because you will have no default files to return to in the future. The following sample dialog demonstrates this: stimpy $ cp access.conf-dist access.conf stimpy $ cp httpd.conf-dist httpd.conf stimpy $ cp srm.conf-dist srm.conf Directives can appear in any of these three files. The names used for the files are relative to the server's root, which is set using the ServerRoot directive. Optionally, you can set the ServerRoot directive using the -d_serverroot command-line flag to the httpd executable. The Apache configuration files are described in Table 16.4. Table 16.4. Configuration Files for Apache Option Description conf/httpd.conf Contains directives controlling the server daemon's operation. The filename may be overridden with the -f command-line flag. conf/srm.conf Contains the directives controlling the document specifications the server provides to clients. The filename may be overridden with the ResourceConfig directive. conf/access.conf Contains the directives to control access to documents. The filename may be overridden with the AccessConfig directive. In addition to the three configuration files shown in Table 16.4, the server daemon also reads a file containing mime document types. The name of this file is identified by the TypesConfig directive. The default name is conf/mime.types. This file usually does not need editing. Next, you must edit each of the configuration files. These files are heavily commented -be sure to leave the comments intact because you may need them in the future. You should pay attention to these comments. If you do not provide the proper settings, the server may not work correctly or may run insecurely. First edit conf/httpd.conf. This configuration identifies general attributes about the server, such as the port number, the user it runs as, and so on. Next, you should edit the conf/srm.conf file. This file is used to set up the root of the document tree. Some examples are server-parsed HTML and internal imagemap parsing. Finally, edit the conf/access.conf file to at least set the base cases of access. You place directives in this file to control access to documents. The server can be configured at the directory level using the .htaccess files. You can place an .htaccess file in each directory accessed by the server. Using these files allows some flexibility because it enables you to change behavior while the server is running because these files are read at access time, rather than at startup. The downside, as you may have guessed, is a performance hit that is considerable. page 294 #BREAK# Inside Linux Starting and Stopping the Server The server executable is named httpd. To run this command, you simply invoke it at the command line as you would any other binary. The httpd daemon will look for the http.conf configuration file on startup. The default location as compiled is /usr/local/apache/conf/httpd.conf, but you can change it in one of two ways. The simplest is to execute the httpd daemon with the -f switch. The following dialog demonstrates this: /usr/local/apache/httpd -f /usr/local/apache/conf/httpd.conf The config.layout file can be used to identify various directory paths. A complete list of command- line switches is provided in Table 16.5 in the section that follows. The httpd daemon, as with all Linux daemons, is designed to run as a background process. After you have launched the daemon, the command-line prompt should return. Otherwise, if the daemon experiences any problems with initialization, error messages will be displayed to the standard output. Most people do not think about it, but you can execute your browser and connect to your local Web server. I occasionally hear the question, "When I start up Netscape and I am not connected to the Internet, I get Cannot connect messages from the Netscape browser. How can I eliminate the error windows?" This is quite easy. If you want to start your browser and do not open a local file, supply the URL http://localhost to the browser. You might even want to use this URL as your home page setting in Netscape's Preferences/Netscape dialog window. Furthermore, you can associate your Internet home page with the My icon on the Navigation toolbar. That way, you are only one click away from your home page. If you disconnect from your ISP and want to leave Netscape running, you simply click the Home icon to get back to the localhost Web server. This eliminates those annoying error windows that Netscape displays every couple of minutes. As a part of the Web server learning experience, you should record the running processes. Next, execute the server, and then examine the running processes and compare the results with the previous list. In a pinch, you can direct the output from the ps command to a file. In any event, you will notice that the server invokes a number of child processes for request handling. The server will run as the root user and the child processes will run as the user identified by the User directive in the http.conf configuration file. You should ensure that only the Apache server is using the port that you specified it to use. You should also ensure that the httpd daemon is running as the root user if you want to access a port below 1024. The default HTTP port, of course, is port 80. If either of these two is not true, you will probably get an error message that Apache cannot bind to some address. To decrease security risks, you should set up a new group and user in http.conf to run the server. Most administrators specify the nobody user. Additionally, you can check the logs directory for any error log files and review their contents for more details. The file to check is named error_log. Most administrators will want the httpd daemon to execute at system startup (boot). This is quite easy - most distributions will default to this configuration if you choose to install Apache during the Linux installation. If you are adding Apache after installing Linux, it is a simple matter of adding an entry for httpd to the Linux startup files (such as rc.local). At the other end of the spectrum, you need a way to stop the Apache server. Like other Linux processes, you issue a signal to kill the process. With the Apache daemon, you issue a TERM signal using the kill command. You must issue the signal to the parent process, not to a child process. If you kill the child process, the parent merely invokes it again. As previously mentioned, the httpd.pid file contains the process ID for the Apache server process. You can cat the contents of the file to reveal the PID and then issue the kill command. Alternatively, you can use the cat command with the kill command to reduce the two commands to one. Better yet, you can create a shell script containing the commands required to kill the server. The following dialog demonstrates two options: stimpy $ cat /usr/local/apache/logs/httpd.pid 123 stimpy $ kill -TERM 123 stimpy $ stimpy $ kill -TERM `cat /usr/local/apache/logs/httpd.pid` stimpy $ page 295 #BREAK# Inside Linux To simplify matters, you can place the last example in a shell script called killapache and just issue the script in the future. Optionally, you can use the apachectl runtime control script. This file can be used for manual Apache administration. You can also use apachectl to govern the rc.d scripts, which control the Apache httpd daemon. Invoking Apache In this section, the command-line options for the httpd daemon are detailed. With Linux and other flavors of Unix, the Apache server is run as a daemon process. This allows the server to run in the background, servicing requests as they arrive. Alternatively, you can have the inetd (Internet) daemon invoke the httpd process whenever a request for HTTP service arrives. The inetd daemon is executed at boot and listens for connect requests on identified Internet sockets. When a connection is discovered, inetd determines which service the socket is associated with and invokes that service. To do this, you need to set the value for the ServerType directive. Table 16.5 details the command-line options for the http daemon. Table 16.5. Command-Line Options for httpd Option Description -C directive Process the Apache directive as if it existed in the configuration file, before reading the configuration files. -c directive Process the Apache directive after parsing the configuration files. -d serverroot Set the value for the ServerRoot variable to serverroot. It can be overridden in the configuration file with the ServerRoot directive. The default is /usr/local/apache. -D name Define a name for use in IfDefine directives. -f config Execute the commands in the file identified by config at startup. If config is not prefixed with /, it is a relative path to ServerRoot. The default is conf/httpd.conf. -L Print a list of directives combined with expected arguments. -l Give a list of all modules compiled into the server, and then exit. -h Print a list of the httpd options, and then exit. -S Show the settings as parsed from the config file, and then exit. -t Test the configuration file syntax, but do not start the server. All the configuration files are parsed and interpreted for proper syntax. Also checks the DocumentRoot entries. -T Test the configuration file syntax, but do not start the server. All the configuration files are parsed and interpreted for proper syntax. Does not check the DocumentRoot entries. -v Print the httpd version and exit. -V Print the base version of httpd and a list of compile-time settings, and then exit. -X Run as single-process mode. Use for debugging purposes - the daemon does not detach from the terminal or fork any child processes. -? Print a list of the httpd options and exit. Check the documentation for Apache for more information regarding these command-line options. page 296 #BREAK# Inside Linux Stopping and Restarting the Apache Server As mentioned previously, you can issue the TERM signal to the httpd process to terminate it and its child processes. Two other signals can be sent to the server. In addition to TERM, you can issue the HUP and USR1 signals using the kill command. The following dialog shows the invocation of these signals: stimpy $ kill -HUP `cat /usr/local/apache/logs/httpd.pid` stimpy $ kill -TERM `cat /usr/local/apache/logs/httpd.pid` stimpy $ kill -USR1 `cat /usr/local/apache/logs/httpd.pid` The HUP signal is used as a restart command to the server. Use of the HUP signal in this fashion is not specific to Apache - this is typical among other Linux (and UNIX) processes. The parent process will terminate its children, reread the configuration files, and then execute the child process again. The TERM signal is used to shut down the server (parent process) and all its child processes. Be sure to give the server time to shut down because it must wait for the children to terminate. After the child processes have terminated, the parent itself terminates. Finally, the USR1 signal is sent to the server to provide a graceful restart. This signal is similar to the HUP signal. The difference is that the server "informs" the child processes to shut down after requests have been satisfied. After all the child processes have terminated, the server rereads the configuration files and then executes the child processes again. Apache Log Files The Apache server utilizes a number of files for logging purposes. The names of these files can be changed through Apache directives. Apache httpd.pid File When Apache is initializing, it writes its process ID to the logs/httpd.pid file. This process ID is the PID for the parent process. The PID is stored so that an administrator can obtain the PID if the server needs to be terminated or restarted. The filename for PID persistence can be altered with the PidFile directive -you might want to consider this for security reasons. Apache Error Log File The Apache server logs any error messages to a file named error_log in the logs directory. The filename can be altered using the ErrorLog directive. Transfer Log The Apache server logs every request to a transfer file named access_log in the logs directory. The filename can be altered using the TransferLog Apache directive. Additionally, other log files can be created with the CustomLog Apache directive. This enables you to maintain separate transfer logs for different virtual hosts. Special-Purpose Environment Variables Typically, environment variables are used by Linux (and UNIX) applications to control their behavior. For example, an application can obtain the current username by examining the environment variable named USER. Table 16.6 describes the environment variables available to Apache. Table 16.6. Environment Variables Used with Apache Environment Variable Description downgrade-1.0 Treats the request as a HTTP/1.0 request. force-no-vary Causes any vary fields to be removed from the response header before being sent to the client. page 297 #BREAK# Inside Linux Environment Variable Description force-response-1.0 Forces an HTTP/1.0 response. nokeepalive Disables the KeepAlive directive. This addresses a bug found in some versions of Netscape. Apache's Handler Use Whenever a file is called, the Apache server maintains internal handlers to perform some action based on the request. The file type (MIME type) is associated with a handler. Most files are handled implicitly, and yet other file types are handled specifically. Apache can handle files explicitly using filename extensions or location. The advantage is that the handler and type are related with a file. The Action directive can be used to add a handler. Optionally, you build the handler to the server or within a module. Table 16.7 describes the handlers for Apache. Table 16.7. Apache Handlers Handler Description default-handler Send the file using the default_handler(), the default handler for static content. send-as-is Send the file with HTTP headers. cgi-script The file should be treated as a CGI script. imap-file Imagemap rule file. server-info Obtain information about the server's configuration. server-parsed Parse for server-side includes. server-status Obtain a report about the server's status. type-map Parse for content negotiation. The following sections detail the corresponding Apache directives for handlers. AddHandler The AddHandler directive is used to map a filename's extension to a handler name. The directive overrides any mapping that may exist. The following is the syntax for the AddHandler directive: AddHandler handler-name extension extension... For example, to treat files with the extension of .cgi as CGI executable scripts, you use the following: AddHandler cgi-script cgi SetHandler The syntax for the SetHandler directive is SetHandler handler-name Effectively, this directive is the same as the AddHandler directive, except that the specified handler- name is applied to all files within a directory, files, or location section. Optionally, the files can be in the .htaccess directory. For example, if you want a directory to be treated as imagemap rule files, the following entry would be placed in the .htaccess file in the identified directory: SetHandler imap-file All files are treated as imagemap rule files, regardless of their extension. page 298 #BREAK# Inside Linux Summary In this chapter, we explored the use of the Apache Web server. The chapter began with an overview of Apache, discovering that it is the number-one Web server being used on the Internet. You can obtain Apache as one of two packages. You can get the binary package, which provides all the binaries required to execute directly. Optionally, you can get the Apache package as a set of source files, allowing you to build the package yourself. Both methods were detailed. Next, Apache runtime configuration was discussed, covering the various configuration files. The configuration files exist in the conf directory and are named access.conf, httpd.conf, and srm.conf. Sample template files are provided and are named access.conf-dist, httpd.conf-dist, and srm.conf-dist. I recommended that you copy these files and use them as a basis for configuration. The starting and stopping of the Apache server were covered. The Apache server executable is named httpd and can be invoked with a number of command-line options. These command-line options were detailed. The use of the HUP, TERM, and USR1 signals was discussed next. These signals are used to communicate to the httpd daemon while it is running. The HUP signal is used as a restart command to the server. The TERM signal is used to shut down the server (parent process) and all its child processes. The USR1 signal is sent to the server to provide a graceful restart. The Apache log files were covered next, which consist of the httpd.pid, error_log, and access_log files. The httpd.pid file contains the process ID of the currently running daemon. The error_log file is used for logging error messages and the access_log is used to log requests. Finally, the environment variables and Apache handlers were covered. The environment variables are used to control the behavior of Apache. The AddHandler and SetHandler directives are detailed, in addition to the Apache handlers such as default_handler and server-info. page 299 #BREAK# Inside Linux Chapter 17. Internet News Service The Network News Transfer Protocol (NNTP) is designed to transport news articles between collaborating news hosts. NNTP uses TCP and defines an application protocol that is the transport vehicle for Usenet traffic. This chapter discusses various aspects of Usenet - specifically, the NNTP client and NNTP server. Overview Usenet, in a nutshell, is a forum for online discussions. It is a combination of a chat system and an email system. You can connect to a news server, join one or more discussion groups, read new articles, send new articles, and respond to articles. It is similar to chat in that there are threads of discussion. It is similar to email in that you read articles, send articles, and reply to articles using a program similar to a mail client. With chat, the discussion is in real time, whereas a news discussion is in near-real-time. Although your article might arrive at the news server within seconds, other participants will not see your articles immediately. Mailing lists predated Usenet as a form of cooperative discussions on the ARPANET. You might be familiar with mailing lists - they still exist today. Usenet is far more popular than mailing lists, at least as indicated by the sheer volume of postings. When considering article volume, Usenet volume is probably equivalent to Internet email volume. Usenet is a logical network, not a physical one. There is no central governing body that manages Usenet. Usenet is supported by millions of machines on millions of networks across the globe, supporting the hundreds of millions of participant users. In the simplest explanation, a news server executes on an organization's host, maintaining news articles stored on disk. This news server collaborates with another news server on the Internet, which collaborates with another news server on the Internet, and so on. All of these news servers continually feed each other, radiating articles across the globe. There is no special requirement to become a part of Usenet. All you need is the hardware, Linux, and the Usenet software required to exchange Usenet news. You have to collaborate with another Usenet site for the exchange of articles. This is as simple as striking an agreement with the site authority to exchange news traffic. The software that is used for the exchange of Usenet articles is built using the application protocol defined by NNTP. Almost all distributions of Linux include the NNTP software required to both read and distribute Usenet articles. Usenet software has two parts: the client and the server (surprised?). The client software is the user portion that is used to read and post articles to a Usenet newsgroup. The server software is responsible for transferring Usenet news (articles) between news servers. Historically, Usenet traffic was propagated using UUCP as the transport protocol. As the popularity of Usenet increased, the amount of traffic increased, which exposed the inefficiency of UUCP as the transport protocol. NNTP utilizes TCP/IP and is defined in RFC 977. Usenet started its life in 1979. Tom Truscott and Jim Ellis , graduate students at Duke University, wanted to craft a way to exchange messages between UNIX computers. It was decided that UUCP would be the transport mechanism. They created a network consisting of three machines. Initially, the traffic was handled by "software," which consisted of a number of shell scripts. This software was eventually rewritten in the C language and made publicly available. This package became what is known as A News. As with most software, A News was written with the intent of handling only a few articles a day. A News became increasingly popular and immediately grew beyond its capabilities. A couple of programmers at the University of California at Berkeley, Mark Horton and Matt Glickman, rewrote A News. As you might expect, this new version became B News and was released in 1982. In 1987, a new version of B News was written by Geoff Collyer and Henry Spencer. This new release would become (you guessed it) C News. Over the years, C News has had a number of patches -the most current incarnation being the C-News Performance Release. page 300 #BREAK# Inside Linux The Network News Transfer Protocol (NNTP) was introduced in 1986 and is based on network connections. It includes specifications for commands to interactively transfer and retrieve articles. Many Usenet software packages are based on NNTP. One popular package, from Brian Barber and Phil Lapsley, is nntpd. Another very popular package, Internet News (INN), was developed by Rich Salz. The nntpd package was designed to deliver NNTP capabilities to B News and C News. INN is not just a supplement, but a complete news package. The INN relay daemon can maintain multiple concurrent NNTP links, making this package the popular choice for Usenet hosting. Basic Usenet Mechanics In a sense, the components that make up Usenet follow a hierarchical structure. At the lowest level, but probably by far the most important, is the article. Without articles, there would be no Usenet. An article is similar in concept to an email document. A number of fields are defined. Each field can (or must) contain data. An article is what is posted to one or more newsgroups. The basic unit of Usenet news is the article. This is a message a user writes and posts to the Internet. In order to enable news systems to deal with it, it is prepended with administrative information called the article header. It is very similar to the mail header format laid down in the Internet mail standard RFC 822 in that it consists of several lines of text, each beginning with a field name terminated by a colon, followed by the field's value. Going up the hierarchical chain, we come to the newsgroup. A newsgroup is a forum for online communication with a specified focus or subject matter (topic). A newsgroup has a name associated with it, which (hopefully) identifies the subject matter. The name is a group of individual words, each delineated by a period (.). Each word identifies the newsgroup's hierarchical structure. Let's look at an example to see how the newsgroup name breaks down. A typical example is comp.os.linux.setup. The name is broken down from left to right, in contrast to an HTTP URL name. The first name, comp, identifies the high-level category computer. Next is os, which designates the subcategory operating system. The third component in the name is linux, which identifies the operating system named Linux. The last subname is setup, which identifies the exact topic of discussion - setting up Linux. Here are the top-level categories in Usenet: alt. Alternative topics. Some alt.* groups exist because they are controversial, and others exist because it is easy to create a newsgroup in alt. comp. Computer-related topics. humanities. Topics relating to humanity, such as philosophy, art, literature, and so on. misc. A variety of topics that do not fit into one of the other categories. news. Topics relating to Usenet itself. rec. Topics relating to hobbies and recreation. sci. Topics relating to scientific subject matter. soc. Topics relating to social issues. talk. Topics designed for ongoing conversations. page 301 #BREAK# Inside Linux This list is not exhaustive by any means. You will realize this if you connect to a news server and download the available newsgroups. You can also go to http://www.deja.com to see a list of available newsgroups. At the third level is the news server, which is responsible for the reception and transmission of articles between servers. As mentioned earlier, Usenet site owners agree to exchange news; they can exchange whichever newsgroups they want. A site may have a number of local newsgroups that can also be distributed. Each site is free to carry whatever newsgroups it wants. The act of transferring news from one machine to another is known as flooding. Whenever an article is posted to the local news server, it is forwarded to the other Usenet sites on the local host's newsfeed list. An article continues to flow from one Usenet host to the next. A special field in a Usenet article called the Path: is used to show the list of hosts that the article has passed through. A news host can examine this field to see if the article has been seen by a host on its newsfeed list. When the article moves through a news host, the host appends its identification to the Path: field. Every Usenet article must have a message identifier. This identifier is used to distinguish the article from others, providing a mechanism for duplicate recognition by the servers and client software. A news server logs the article in a history file for future reference. The Distribution field for an article can be used to restrict an article's transmission. You can specify that an article remain within the local domain. A news server checks this field. If it discovers the restriction to remain within the domain, the article is not transmitted. Two schemes are used to move Usenet traffic: batching and ihave/sendme articles. Both have their strengths and weaknesses. With the batching of articles, which is typical among UUCP Usenet systems, articles are collected over time and placed in a single file for transmission. When the time comes to transmit, the file is compressed and sent to its destination. The receiving host is responsible for verifying the articles that is, it checks for duplicates and so on. Transmission is quicker, but the receiving station has the overhead of processing many articles. The other method is the ihave/sendme protocol. The originator (or source) host gathers a list of available articles and transmits the list to the destination, which is the ihave of the protocol. The destination host accepts the list and processes it. The destination host then transmits a sendme message, identifying the message IDs to the originator. The downside of this protocol is the amount of overhead for the conversation between the originator and the destination hosts. The NNTP protocol offers up to three ways to get articles from one machine to another: the active, passive, and interactive modes. Active mode, commonly referred to as pushing the news, is similar to the ihave/sendme protocol. In push (active) mode, the sender relays an article, and the receiver either accepts or rejects the article. The downside of this is that the receiver must check each article presented to it. Using passive mode, which is sometimes called pulling the news, the destination host requests from the source host articles from identified newsgroups after a specified date. Once the receiver has all the articles, it checks them against its history file, checking for and discarding duplicate articles. Interactive mode allows a newsreader (client application) to specify the articles that exist on identified newsgroups. Using a Usenet Newsreader Usenet newsreaders come in all shapes and sizes. A good newsreader allows the user to read, post, reply to, save, and print articles. The more sophisticated newsreaders go far beyond these basic activities. page 302 #BREAK# Inside Linux Here are some of the newsreaders that are included with most distributions of Linux: pine. A screen-oriented message-handling tool that works with Internet News and email. tin, rtin. A full-screen Usenet newsreader. It can read news locally (from /var/spool/news) or remotely (rtin). krn. KDE graphical newsreader. Netscape. Provides an integrated newsreader and email client. At a minimum, you want a newsreader that can connect to the remote news server, subscribe to one or more newsgroups, and then manipulate articles (read, post, and so on) in a selected newsgroup. The next two sections look at two popular newsreaders: krn and Netscape. Using krn, the KDE Newsreader This section looks at krn, the graphical newsreader packaged in the K Desktop Environment. KDE is shipped with most distributions of Linux. If you have KDE installed, you can find krn by selecting the Internet, News client menu item. Figure 17.1 shows krn after it is executed from the K menu. Figure 17.1. KDE's krn newsreader application. When you execute krn, you will see the groups window, as shown in Figure 17.1. The krn application has a second window, the articles window, which is displayed when you choose a newsgroup from the groups window. We will see an example of the articles window later in this chapter. You can see that there is a tree view in the main window of the application and that the Subscribed Newsgroups branch is currently expanded. The krn application sports menus and an icon toolbar, providing two ways to execute commands. The File, Connect to Server menu option has been selected. The toolbar reflects this fact because the red plug icon can be selected. page 303 #BREAK# Inside Linux Figure 17.2 shows the krn Group List window with the All Newsgroups tree expanded. The newsgroup comp.os.linux.networking is subscribed to - the check mark reflects the subscription status. Figure 17.2. The krn newsreader with newsgroup subscribed. At this point, you could continue subscribing to newsgroups by selecting them in the Group List window. When you have finished, you can collapse the All Newsgroups branch. If you open the Subscribed Newsgroups branch, you should see the newsgroups that you have subscribed to. To work with articles within a newsgroup, you can double-click the name of the newsgroup in the Subscribed Newsgroups tree. Optionally, you can right-click the newsgroup and select the Open option from the pop-up menu. The articles window will open, and the krn Confirmation dialog box will appear, asking how many articles you want to download. You can request that the download begin from either the oldest or newest articles. Figure 17.3 shows the articles window and the confirmation dialog box. Figure 17.3. krn's articles window and confirmation dialog box. page 304 #BREAK# Inside Linux Specify the number of articles to download, and click the OK button to continue. The krn articles window will capture the articles and display them in the window. Figure 17.4 shows the articles after they have been downloaded. Figure 17.4. krn's articles window populated with articles. Notice that there are replies to the original article and a reply to the reply. This is shown as an indented hierarchy. To read an article, click the article in the top pane. The article's body will be displayed in the lower pane. To reply to an article, select the File, Post Followup menu option. Figure 17.5 shows the article composition window, ready to accept a reply. When you are ready to send the reply, click the send icon on the toolbar. Figure 17.5. krn's article composition window. page 305 #BREAK# Inside Linux You can also post and mail a response to an article. This means that you will draft a response and then post a copy to the newsgroup, and a copy will be emailed to the article's author. You also have the option of forwarding an article using email. Other options include printing and saving (to disk) the selected article. Using krn is as easy as using an email client, and you can be "heard" by millions of people! Using Netscape's Newsreader Just about every distribution of Linux comes with Netscape's Communicator product. Within the Communicator suite is an application called Messenger, an email client that doubles as a newsreader. Messenger is quite easy to use. If you happen to be using it for your email client, you will be quite comfortable using it as your newsreader. You can start Messenger using a desktop icon or at a command prompt. The following dialog shows two ways you can execute Messenger at the command line to bring up the newsreader. The first invocation brings up Netscape's Messenger, and the second brings up Netscape's Message Center. stimpy $ netscape -mail & stimpy $ netscape -news & stimpy $ Optionally, if the Netscape browser (Navigator) is currently executing, you can open Messenger by selecting the Communicator, Messenger menu option. Figure 17.6 shows the Messenger window. Figure 17.6. Netscape's Messenger (email and newsreader) window. If you are using Messenger as your email client, Figure 17.6 will look familiar to you. The left pane is the tree view, offering various folders for email, news servers, and their associated newsgroups. Although it's partially obscured, the newsgroup selected in the figure is comp.os.linux.networking. As a matter of fact, the selected message thread is the same as in Figure 17.4. The upper-right pane is the article thread pane. You scroll through the list of articles, selecting articles of interest. In the figure, notice that the selected article contains replies, shown as a hierarchical tree view. You can expand the article's tree by clicking the + icon. Conversely, you can collapse the article tree by clicking the - icon. The lower-right pane is the article view pane. This is where the body of the article is displayed. You can scroll this area to view the article if necessary. page 306 #BREAK# Inside Linux To subscribe to a newsgroup, right-click the news server listed in the folder tree view and choose the Subscribe to Newsgroups option from the pop-up menu. The newsgroup selection window appears, as shown in Figure 17.7. Figure 17.7. Messenger's newsgroup subscription window. As you can see, comp.os.linux.networking is currently selected. A check mark signifies that you have subscribed to the newsgroup. You can select more than one newsgroup in the selection window. When you have selected all the newsgroups you want to join, click the OK button and the selection window will close. You can now return to the Messenger window. The newsgroups you selected are listed in the folder tree view. Click a newsgroup that you want to participate in. The Download headers window appears, prompting you for the number of articles to download, as shown in Figure 17.8. Figure 17.8. Messenger's Download headers window. You can choose to download all headers or indicate the quantity you want to download. Click the OK button to continue. When all the articles have been downloaded, the article thread pane is populated with the new articles. Figure 17.9 shows the Messenger window, waiting for action. At this point, you can select other newsgroups (if you chose more than one), read all unread articles, post new articles, or reply to articles. page 307 #BREAK# Inside Linux Figure 17.9. Messenger with articles selected for viewing. To post a new article, select the File, New, New Message menu option. Alternatively, you can click the New message to this newsgroup toolbar icon (a pen on paper). You can also respond to an article. Select the desired article and select the Message, Reply, To Newsgroup menu option. Alternatively, you can select the Reply to the message toolbar icon. The article composition window will be displayed, as shown in Figure 17.10. Figure 17.10. Messenger's article composition window. The name of the newsgroup is shown in the Newsgroup field, which is similar to the To (or cc:) field when you're composing an email. The Subject field is filled in, and the text of the original article appears. You can choose to write your reply before the original text or after it. Some people inject replies directly into the original text. You might do this if you want to address each point individually. page 308 #BREAK# Inside Linux Common Usenet Terms Usenet is a world unto itself. You must learn to live within that world if you want to (truly) participate within the newsgroup communities. Methods of communication vary, which is typical when you're conversing with a group of people. An interesting point about Usenet is that anyone in the world can participate. Keep this in mind when you're actively participating. The person you respond to might not be from your culture or even speak your native tongue. Table 17.1 lists the common Usenet expressions you might require in your terminology arsenal. Table 17.1. Common Usenet Terms Term Description Aahz's Law The best way to get information on Usenet is not to ask a question, but to post the wrong information. Boigy's Law The theory that certain topics in every newsgroup are discussed repeatedly (cyclically), such as every month. Often, the period of the cycle, and the length of the resulting discussion, can be accurately estimated by those who have been around long enough. Flame or flame war 1. To post an article with the intent to insult and provoke. 2. To speak incessantly and/or rabidly on a relatively uninteresting subject or with a patently ridiculous attitude. 3. Either #1 or #2, directed with hostility at a particular person or people. Flames are often found in large numbers (known as a flame war) during holy wars (discussed later in this table). The newsgroup alt.flame is dedicated to perfecting the art of flaming. Flame bait A posting that is intended to trigger a flame war, or one that invites flames in reply. For example, posting an article on how to run dogs over in rec.pets.dogs is sure to draw scathing flames from the readers of that group. Kibo Also known as "He who greps" (grep is a UNIX text-searching tool). Kibo was the first person to grep (search) the entire news stream for his name, generating a reply if the string kibo was found. Eventually (we think), he modified his search pattern to find various modifications of kibo, such as Kibo and KIBO. Kibo is the closest thing to a god on Usenet. We worship you, almighty Kibo! See alt.religion.kibology for more information. Kook A term used for many things, but mostly for the weirdos who randomly appear in different groups and who cause no end of trouble. Often placed in kill files, they usually disappear only after everyone has finally stopped responding to their ridiculous or improperly posted articles. Lurk To read a newsgroup but not post articles. It is often hypothesized that upwards of 99 percent of the people reading a group do not post, or post very rarely. Of course, this hypothesis could be incorrect. Religious issue Questions that seemingly cannot be raised without touching off holy wars (a flame war about a religious issue), such as "What is the best operating system (or editor, language, architecture, shell, mail reader, newsreader, and so on)?" Almost every group has a religious issue of some kind. Anybody who was around the last time the issue exploded is careful not to provoke another war. Religious issues are universally guaranteed to start a long-running, tiresome, bandwidth-wasting flame war - with no truces. September The time when college students return to school and start to post silly questions, repost MAKE MONEY FAST, break rules of netiquette, and just generally make life on Usenet more difficult than at other times of the year. You can really tell when homework is due, because the "How do I..." articles begin to surface. Unfortunately, it has been September since 1993. Signal-to-noise ratio (snr) A subjective quantity (the snr has no units - it is usually just some obvious quantifier) describing someone's idea of just how much content a group has relative to its junk. The snr is very subjective. Generally, every person who reads news has a certain threshold for snr. If any group falls below that threshold, the reader will unsubscribe rather than wade through all the junk. Sturgeon's Law 90 percent of everything is crud. What that 90 percent is depends on who you are, but this law is often the cause of strenuous debate about a thread's being either on or off topic. Note that this does not imply that the remaining 10 percent is not crud. Troll A posting designed specifically to generate follow-ups about something trivial, but not in the sense of a flame. Also a post designed to instruct readers to ignore obvious drivel by making the repliers feel utterly stupid. There are many other terms. I suggest picking up a copy of The New Hacker's Dictionary by Eric S. Raymond (MIT Press, 1996). Keep this book by your side as you engage in Usenet. page 309 #BREAK# Inside Linux NNTP Protocol We now begin our journey to the server side of Usenet. Beginning with this section, we will explore the NNTP protocol and then move on to installing and configuring the nntp server. The Network News Transfer Protocol (NNTP) utilizes the facilities of the Transmission Control Protocol (TCP) as the underlying connectivity medium (stream connection). An NNTP conversation between an NNTP client and server occurs at the well-known port number 119. Typically, an NNTP server runs as a daemon, accepting connections from other hosts and clients. An NNTP conversation is similar to other TCP/IP protocols, such as HTTP, FTP, and so on. The client and server speak a language consisting of commands and their associated arguments or data (if applicable). The language is readable ASCII text. You can converse manually with an NNTP server as long as you know the commands and required data. The conversation consists of the NNTP client submitting commands to the server and the server responding with a numeric response code. The code may be followed by data. The NNTP protocol is described in RFC 977, which identifies the requirements and the language or commands that are available. The Usenet system provides a central repository containing news articles. Also, there are programs allowing a subscriber to select and manipulate news articles. The NNTP server is merely a gateway between the NNTP client and the NNTP databases that contain the articles. The NNTP server makes no assumptions about the client and provides no functionality for user interaction, including the presentation of articles. NNTP Commands As mentioned previously, an NNTP command is comprised of a textual command preceding some number of arguments. Commands and their associated argument(s) are delimited by a space or tab character. Each command line submitted can consist of only one command; multiple commands are not permitted. Each command line is terminated by a CR/LF character sequence. A restriction is posed against the length of the command line. The complete line submitted to the server must not exceed 512 characters. If a command requires an argument (or data), the delimiter characters (spaces or tabs) are counted. Additionally, the terminating CR/LF pair is included in the count. Table 17.2 summarizes the NNTP commands. Table 17.2. NNTP Commands Command Description ARTICLE Used to request an article by its message identifier or numeric identifier. If available, the header and body of the article are returned. BODY Similar to the ARTICLE command, except that only the article's body is returned. The request is by the article's message ID or numerical identifier. GROUP group Used to join a newsgroup identified by the argument group. HEAD messageID Similar to the ARTICLE command, except that only the article's header is returned. The request is by the article's message ID or numerical identifier. HELP Used to obtain a list of applicable commands. IHAVE The client uses this command to inform the server it has the article identified by a message identifier. If the server wants the article, it tells the client to send the article. Otherwise, the server responds that it does not want the article. LAST The current article pointer is set to the previous article (not the last article available). LIST Used to obtain a list of newsgroups offered by the news server. NEWGROUPS Requests a list of new newsgroups created since a specified date and time. Some people think this command is NEWSGROUPS; however, it is not requesting a list of newsgroups, only groups that are new. See LIST for comparison. page 310 #BREAK# Inside Linux Command Description NEWNEWS Used to request a list of articles that have been posted since a specified date. NEXT Used to set the current article pointer to the next article. POST A request to submit (or post) an article (posting must be allowed). The article should be sent if the response code is 340. QUIT Tells the server to end the session and close the connection. SLAVE Tells the server that this client is a slave server. STAT Similar to the ARTICLE command, STAT is used to set the current article pointer. Data is not returned. The following dialog shows a manual connection using the telnet program: stimpy $ telnet news1.attglobal.net nntp Trying 943.432.123.342... Connected to news1.server.net. Escape character is '^]'. 200 news1.server.net DNEWS Version 5.2c, S3, posting OK HELPO 500 command not recognized HELP 100 Legal commands authinfo user Name|pass Password article [MessageID|Number] body [MessageID|Number] check MessageID date group newsgroup head [MessageID|Number] help ihave last list [active|active.times|newsgroups|subscriptions] listgroup newsgroup mode stream mode reader newgroups yymmdd hhmmss [GMT] [] newnews newsgroups yymmdd hhmmss [GMT] [] next post slave stat [MessageID|Number] takethis MessageID xgtitle [group_pattern] xhdr header [range|MessageID] xover [range] xpat header range|MessageID pat [morepat…] . The HELP command is submitted, and a list of legal commands is returned. Notice that, initially and intentionally, the command submitted is HELPO. This command is invalid, and the server responded appropriately. Commands are submitted from the client to the NNTP server. If the server does not respond, the command may be re-sent. The next section discusses server responses. page 311 #BREAK# Inside Linux NNTP Server Responses Responses can be one of two types -status or text. A status message from the server identifies the response associated with the last command received. The status code consists of a three-digit code. Table 17.3 describes the first-digit portion of the response code. Table 17.3. NNTP Status Responses, First-Digit Description First Status Code Description 1xx Identifies informative messages 2xx Indicates success 3xx Indicates that the command is okay so far, so continue with the next 4xx Denotes that the command is correct but cannot be executed 5xx Indicates that the command is not (yet) implemented, the command is incorrect, or some other error occurred The second digit in the code identifies the functional response category. These functional codes are listed in Table 17.4. Table 17.4. NNTP Status Responses, Second-Digit Description Second Status Code Description x0x Messages about the connection, setup, and other miscellaneous things x1x Used to designate a newsgroup selection x2x Used to designate an article selection x3x Identifies various distribution functions x4x Used to refer to posting x8x Indicates any nonstandard extensions x9x Provided for debugging output Each command in the RFC 977 document identifies the codes that are expected responses from the server. Some status messages also contain data as an argument. The number and type of arguments are fixed. A single space character is used as a delimiter to separate the code from the argument(s) (if applicable). Overall, the NNTP client can choose to ignore codes in the 1xx range. A code of 200 or 201 is a response code when a connection is initially established. The following dialog demonstrates this output: stimpy $ telnet news1.attglobal.net nntp Trying 32.97.166.128… Connected to news1.prserv.net. Escape character is ‘^]’. 200 news1.prserv.net DNEWS Version 5.2c, S2, posting OK QUIT 205 closing connection - goodbye! Connection closed by foreign host. stimpy $ A status code of 400 is sent by the NNTP server when it must discontinue the news service. The 5xx family of status codes indicates that the command could not be executed for some reason. Table 17.5 describes the response codes that can be sent by the NNTP server. These are general responses. page 312 #BREAK# Inside Linux Table 17.5. NNTP Status Categories Status Code Description 100 Help text is returned. 190 through 199 Identified for debug output. 200 The server is ready. Posting is allowed. 201 The server is ready. No posting is allowed. 400 Specifies that the nntp service is being terminated. 500 Specifies that the submitted command is not recognized. 501 Specifies that there is a syntax error in the supplied command. 502 Identifies an access restriction or specifies that permission is denied. 503 Identifies a program fault and specifies that the command is not executed. The second type of response is the text response. It is sent after a numeric status response line has been sent, indicating that text follows. The format of the text is one or more lines, terminated with a CR/LF character pair. A single period (.), on a line by itself, is sent to indicate the end of text. The following dialog demonstrates this: 03# telnet news1.attglobal.net nntp Trying 32.97.166.128… Connected to news1.prserv.net. Escape character is ‘^]’. 200 news1.prserv.net DNEWS Version 5.2c, S1, posting OK HELP 100 Legal commands authinfo user Name|pass Password article [MessageID|Number] body [MessageID|Number] check MessageID date group newsgroup head [MessageID|Number] help ihave last list [active|active.times|newsgroups|subscriptions] listgroup newsgroup mode stream mode reader newgroups yymmdd hhmmss [GMT] [] newnews newsgroups yymmdd hhmmss [GMT] [] next post slave stat [MessageID|Number] takethis MessageID xgtitle [group_pattern] xhdr header [range|MessageID] xover [range] xpat header range|MessageID pat [morepat…] . QUIT 205 closing connection - goodbye! Connection closed by foreign host. stimpy $ Notice that after the HELP command is submitted, the server responds with a list of commands. The list is terminated by a single period (.) on a line by itself. If the text contains a period as the first character, the line will contain two periods (..). The client program must validate each line, checking for a lone period or double period, and responding accordingly. Text messages are normally used as display to the user. The status codes are normally interpreted and shielded from the user, because the code itself is not informative. page 313 #BREAK# Inside Linux Command and Response Details The NNTP commands and the responses associated with them are detailed in this section. Refer to RFC 977 for more details. The ARTICLE Command The syntax of the ARTICLE command is as follows: ARTICLE message-id Upon receipt of this command, the server displays the header, a blank line, and the body (text) of the identified article. The identifying message-id is the message ID of an article in its header. The internally maintained “current article pointer” is left unchanged. Here is an optional usage of the ARTICLE command: ARTICLE [nnn] As in the previous usage of the ARTICLE command, the header, a blank line, and the body (text) of the current or specified article are displayed. The parameter nnn, which is optional, is the numeric ID of an article in the current newsgroup. If the parameter is not given, the current article is displayed. If a valid article number is used, the current article pointer is set. The response indicates the current article number. The message-id field can be used to purge duplicate articles, because this ID is unique for every article. The following list shows the responses associated with the ARTICLE command. n represents the article number, and a represents the message ID for an article. 220 n a. The article is retrieved, and the head and body follow. 221 n a. The article is retrieved, and the head follows. 222 n a. The article is retrieved, and the body follows. 223 n a. The article is retrieved; the text must be requested separately. 412. A newsgroup has not been selected. 420. A current article has not been selected. 423. The article number specified does not exist in this group. 430. The identified article was not found. The GROUP Command The syntax of the GROUP command is as follows: GROUP ggg The name of the newsgroup is supplied as the parameter ggg. This is the newsgroup to join (or select). Use the LIST command to acquire a list of valid newsgroups offered. If the command is successful, the first and last articles in the selected newsgroup are returned. Also, a total count of all articles available is given, but this count is only an estimate. The method by which the count is derived is implementation specific. page 314 #BREAK# Inside Linux Once a newsgroup has been selected using this command, the current article pointer is set to the first article. If it’s unsuccessful, the previous newsgroup and current article pointer are maintained. The following list shows the responses that can be expected from submission of the GROUP command. n is the count of articles for the newsgroup. f designates the number of the first article. l designates the last article in the newsgroup. s indicates the name of the newsgroup. 211 n f l s. Identifies the newsgroup selected. 411. Specifies that the newsgroup does not exist. The HELP Command The syntax of the HELP command is as follows: HELP Upon receipt of this command, the server responds with a list of available commands supported by the server. A sole period on a line by itself identifies the end of the list. The following response is applicable for the HELP command: 100. The help text follows. The IHAVE Command The syntax of the IHAVE command is as follows: IHAVE messageid An NNTP client sends this command, with the argument, to the server, effectively telling the server, “I have this article named by the message identifier.” The server can instruct the client to send the article. Otherwise, the server tells the client it does not want the article. If the server requests the article, the client responds by sending the article’s header and body. A response code is returned, indicating success or failure. The IHAVE command is used to transfer an existing article. Use the POST command to submit a new article. Generally, the IHAVE command is not executed by a newsreader program; it is executed only by server processes. A server may reject an article for a number of reasons, such as an invalid newsgroup (for the article), hardware issues, or a corrupted article. The decision is implementation specific and is not specified by the NNTP protocol. The following are the responses for the IHAVE command: 235. The article transfer was successful. 335. The article is to be transferred. The termination sequence for the transmission is .. 435. Do not send the identified article because it is not desired. 436. The transfer failed. Attempt to retransmit at a later time. 437. The article was rejected. Do not send it again. page 315 #BREAK# Inside Linux The LAST Command The syntax of the LAST command is as follows: LAST This command is used to set the current article pointer to the previous article in the newsgroup. If the pointer is at the first article in the list, an error is returned, and the pointer continues to point to the first article. The current article number and message identifier are returned. The following are the responses for the LAST command. n designates the article number. a designates the unique article identifier. 223 n a. The article has been retrieved. The text must be requested separately. 412. A newsgroup has not been selected. 420. An article has been selected as current. 422. There is no previous article in this group. The LIST Command The syntax of the LIST command is as follows: LIST The server returns a list of available newsgroups in reaction to this command. Each newsgroup entry exists on a separate line and is formatted as follows: group last first posting The name of the newsgroup is identified by group. The last article number for the newsgroup is identified by last and is numeric. The first field indicates the first article for the newsgroup and is a numeric value. Finally, the posting field indicates whether posting is allowed. The value of posting can be either y or n. An empty list, identified by a lone period on a line, is considered a legitimate response. This response specifies that there are no newsgroups. The following is the response for the LIST command: 215. A list of newsgroups follows. The NEWGROUPS Command The syntax of the NEWGROUPS command is as follows: NEWGROUPS date time [GMT] [distributions] The server displays a list of newsgroups that have been created since the specified date and time. The date must be formatted as six digits, as in YYMMDD. Because the year is identified with two digits, the closest century is used. The time field is required and is also formatted to six digits, as in HHMMSS. If GMT is not present, the local time is assumed. The parameter distributions is optional. It identifies a list of distribution groups. As with the LIST command, an empty list is considered a legitimate response. This response specifies that there are no new newsgroups. The following is the response for the NEWGROUPS command: 231. A list of new newsgroups follows. page 316 #BREAK# Inside Linux The NEWNEWS Command The syntax of the NEWNEWS command is as follows: NEWNEWS newsgroups date time [GMT] [distribution] The server displays a list of article message identifiers that have been posted or received since the specified date and time. The date and time parameters follow the same format as the NEWGROUPS command. Each entry occupies a single line, and the list is terminated by a sole period on a line by itself. An asterisk (*) can be used for the newsgroup field to act as a wildcard. For example, comp.lang.* will return entries such as comp.lang.c, comp.lang.c++, and so on. The following is the response for the NEWNEWS command: 230. A list of new articles by message ID follows. The NEXT Command The syntax of the NEXT command is as follows: NEXT This command is used to set the current article pointer to the next article in the newsgroup. If the pointer is at the last article, an error is returned, and the last article remains current. The article number and message identifier are returned as a result of this command. The following are valid responses for the NEXT command. n designates the article number, and a designates the unique article identifier. 223 n a. The article is retrieved. You must request the text separately. 412. A newsgroup has not been selected. 420. An article has not been selected as current. 421. There is no next article in this newsgroup. The POST Command The syntax of the POST command is as follows: POST This command is used to submit a new article to the server. If posting is allowed, a 340 code is returned. Upon receipt of this code, the article should be transmitted. Otherwise, a code of 440 indicates that posting is not allowed. After the article has been transmitted, the server returns a response code indicating success or failure. The format of the article should correspond to the specification established in RFC 850. A sole period on a line by itself indicates the end of the article’s text. The following are valid responses for the POST command: 240. The article has been posted successfully. 340. Transmit the article to be posted, and terminate with .. 440. Article posting is not allowed. page 317 #BREAK# Inside Linux 441. Posting has failed. 201. The server is ready, and posting is not allowed. The QUIT Command The syntax of the QUIT command is as follows: QUIT The QUIT command is used to tell the server to terminate the session and close the connection. It is generally accepted practice for the client to submit this command to close the connection. The following is the response for the QUIT command: 205. Close the connection. The SLAVE Command The syntax of the SLAVE command is as follows: SLAVE This command effectively tells the server that the client is to be treated as a slave server. This helps ensure that priority should be given to a slave server versus an NNTP client, because a slave server normally serves many NNTP clients. The following is the response for the SLAVE command: 202. Slave status is acknowledged. Configuring the NNTP Server The name of the NNTP server follows the pattern of other server daemons -the server’s name is nntpd. The server can be configured to execute in one of two methods, which applies to other Linux Internet servers as well. The nntpd server can be started at bootup from an rc startup script, or it can be executed on demand by the inetd daemon. If you’re using inetd, an entry should exist in the /etc/inetd.conf file. The following shows a sample entry for the nntpd daemon: # inetd.conf file … # service_name sock_type proto flags user server_path args nntp stream tcp nowait news /usr/etc/in.nntpd nntpd … # To re-read this file after changes, just do a ‘killall -HUP inetd’ # end of file If you choose the first option, running nntpd as stand-alone, you should make sure you comment out any line referencing nntpd in the /etc/inetd.conf file. Regardless of the mode of execution, you should be sure that an nntp entry exists in the /etc/services file, as shown in the following snippet: # /etc/services … … auth 113/tcp authentication tap ident sftp 115/tcp uucp-path 117/tcp nntp 119/tcp readnews untp # USENET News Transfer Protocol ntp 123/tcp ntp 123/udp # Network Time Protocol netbios-ns 137/tcp # NETBIOS Name Service netbios-ns 137/udp netbios-dgm 138/tcp # NETBIOS Datagram Service … # page 318 #BREAK# Inside Linux To store news articles, the nntpd daemon requires a temporary directory. The following dialog demonstrates the creation of this directory: stimpy $ mkdir /var/spool/news/.tmp stimpy $ chown news.news /var/spool/news/.tmp stimpy $ Restricting NNTP Access The /usr/lib/news/nntp_access file determines the accesses to NNTP resources. The format for an entry is as follows: site read|xfer|both|no post|no [!exceptgroups] When a client establishes a connection, the server queries for the fully qualified domain name of the host client using a reverse lookup. Table 17.6 describes the procedure, based on the match made by the server. A match can be either partial or exact. Table 17.6. nntpd Hostname Matching Matched By Description Hostname The fully qualified domain name of the host. If the match is literal, the entry applies. IP address The IP address (dotted quad notation). The entry applies. All other entries are ignored. Domain name A match if the client’s hostname matches the domain name, as in *.domain. Network name The name of a network identified in the /etc/networks file. Default Matches any client. The access rights for a client are governed by an entry’s second and third fields. A value of read specifies news article retrieval. xfer specifies the transmission of news articles. The both value permits read and xfer.no denies all access. The third field is used to govern the client’s rights to post articles without header information. This information is completed by the news server. The third field is ignored if the value of the second field is no. The fourth field is optional. If it’s specified, it contains a list of groups that the client is not allowed to access. Summary This chapter covered most of the functionality of Usenet. We began with an overview of Usenet and its community. Next, the overall mechanics, or concepts, of Usenet were covered. This included descriptions of terminology such as articles, newsgroups, and newsreaders. An overview of article processing was also given. The next section described the client side of Usenet, covering the use of two newsreaders. You use a newsreader to access newsgroups and manipulate articles contained within a newsgroup. An overview of the krn newsreader, provided as part of the KDE package, was given. Netscape’s newsreader, Messenger, was also covered. Next, we covered some common Usenet terms, such as flame and flame bait. Any Usenet participant worth his salt will have The New Hacker’s Dictionary by his side. The next section dealt with the NNTP commands that are sent to a server. Also, the response codes were described in detail. Some of the commands discussed were ARTICLE, BODY, and GROUP, to name just a few. Finally, we closed the chapter with a section concerning the configuration of the nntpd server daemon. page 319 #BREAK# Inside Linux Chapter 18. Print Services We can do a lot with our computers. We can crunch numbers using spreadsheets and produce documents using word processors. It would be great if all documents we produced could be sent directly to the parties concerned, enabling them to view the documents on their computer. Unfortunately, the reality is that we often have to produce paper copies of our documents. In this chapter, we see what it takes to get paper output from the documents we produce. Print Overview Linux, like other UNIX systems, performs the process of printing using the concept of spooling. Printers are slow mechanical devices, and even the printing of the smallest document can hold up a process. However, we do not want other processes (such as a word processor) to wait for a print job to finish. Linux includes various software applications to implement and manage a print queue. When we send a file to the printer under Linux, that file does not immediately go to the printer. Instead, the file is sent to a temporary area, logically known as the print queue, to wait its turn to be printed. If the file to be printed is the only file in the queue, it is processed immediately. If one or more files are in the queue, those files are printed first. Later in the chapter you will see how you can send a file directly to the printer. However, this is not an optimal method. Because Linux is a multiuser operating system, the concept of the print queue is very effective for multiple users printing to a single printer. Users simply send their print jobs off and the print queue manages the task of printing each user’s documents in the correct sequence. The printer services under Linux remove the burden of printer management and control from users on the network. The overall process to print a document from software (or command line) to the printer is straightforward and simple. Let us use the example of a word processor. You tell the program that you want to print the current document. The program gathers the text, along with any special formatting characters, and sends a data stream to the print queue software. The print queue software stores the print data to a temporary file on the disk. This relieves the word processor from waiting for the file to be printed; the print queue software is now the owner of the file to be printed. Of course, the word processor program thinks that the file has been printed because the streaming of data has completed. If you have ever printed a document under a single-user operating system such as DOS, you may remember that the program (printing the document) remains unavailable until the print job is complete. Now that the print queue software has spooled the print job to disk, it is simply a matter of the print queue manager determining the next file to print. If no other files are in the queue, the newly spooled file is opened and sent to the printer. If other files are in the queue, they are opened one at a time and sent to the printer. This process continues until all files have been sent to the printer. This all seems simplistic, but there is more detail to printing under Linux than can be captured in a few paragraphs. Let us continue our journey into the world of printing under Linux. Printer Preliminaries Most all distributions of Linux ask if you want to configure a printer during the installation process. The more robust distributions even have a list of printers to choose from; these distributions take away much of the anguish of setting up a printer under Linux. Still, it is a good idea to know what is happening, especially if problems arise. Table 18.1 lists the most popular printers supported by Linux. The printer capabilities are fully supported under Linux. page 320 #BREAK# Inside Linux Table 18.1. Printers Fully Supported by Linux Manufacturer Model(s) Apple LaserWriter 16/600, LaserWriter IINTX, LaserWriter Select 360 Brother HL-1070, HL-10V, HL-10h, HL-1260, HL-2060, HL-4Ve, HL-630, HL-660, HL-720, HL730, HL-760, HL-8 Canon BJC-210, BJC-250, BJC-4000, BJC-4100, BJC-4200, BJC-4300, BJC-4400, BJC-600, BJC6000, BJC-610, BJC-620, BJC-70, BJC-800, BJ-10e, BJ-20, BJ-200, BJ-330, BJ-5, LBP1260, LBP-1760, LBP-4+, LBP-4U, LBP-8A1, LBP-8II, LIPS-III Citizen ProJet II, ProJet IIc Digital DECwriter 520ic, DECwriter 500i, DECwriter 110I, LN03 Epson SQ 1170, Stylus Color, Stylus Color 400, Stylus Color 440, Stylus Color 640, Stylus Color 660, Stylus Color 800, Stylus Color 850, Stylus Color II, Stylus Color IIs, Stylus Pro XL, ActionLaser 1100, LP 8000 Fujitsu PrintPartner 10V, PrintPartner 16DV, PrintPartner 20W, PrintPartner 8000 Hewlett Packard DeskJet 500, DeskJet 510, DeskJet 520, 2000C, 2500C, DeskJet 1200C, DeskJet 1200C/PS, DeskJet 1600C, DeskJet 1600Cm, DeskJet 310, DeskJet 400, DeskJet 420C, DeskJet 500C, DeskJet 540, DeskJet 550C, DeskJet 600, DeskJet610C, DeskJet 610CL, DeskJet 612C, DeskJet 660C, DeskJet 670C, DeskJet 672C, DeskJet 682C, DeskJet 690C, DeskJet 694C, DeskJet 697C, DeskJet 810C, DeskJet 812C, DeskJet 850C, DeskJet 855C, DeskJet 882C, DeskJet 890C, PaintJet XL300, Color LaserJet 4500, LaserJet 1100, LaserJet 1100A, LaserJet 2 w/PS, LaserJet 2100M, LaserJet 2P, LaserJet 3, LaserJet 3P w/PS, LaserJet 4, LaserJet 4 Plus, LaserJet 4050N, LaserJet 4L, LaserJet 4M, LaserJet 4P, LaserJet 5, LaserJet 5000, LaserJet 5L, LaserJet 5M, LaserJet 5MP, LaserJet 5P, LaserJet 6L, LaserJet 6MP, LaserJet 8000, LaserJet 8100, Mopier 320 Kyocera F-3300, FS-1700+, FS-3750, FS-600, FS-800, P-2000 Lexmark (/IBM) Optra Color 40, Optra Color 45, 4303 Network Color Printer, Optra Color 1200, Optra Color 1275, 4019, 4029 10P, Page Printer 3112, 4039 10plus, Optra E, Optra E+, Optra E310, Optra Ep, Optra K 1220, Optra R+, Optra S 1250, Optra S 1855, Valuewriter 300 Minolta PagePro 6, PagePro 6e, PagePro 6ex, PagePro 8 NEC SilentWriter LC 890, Silentwriter2 S60P, Silentwriter2 model 290, SuperScript 660i Oce 3165 Okidata Okipage 8c, 8p, OL 410e, OL 600e, OL 610e/PS, OL 800, OL 810e/PS, OL400ex, OL810ex, OL830Plus, Okipage 10e, Okipage 12i, Okipage 20DXn, Okipage 4w, Okipage 6e, Okipage 6ex Olivetti JP350S, JP450, PG 306 Panasonic KX-P8420, KX-P8475, KX-P4410, KX-P4450, KX-P5400 QMS 2425 Turbo EX Ricoh 4801, 6000 Samsung ML-5000a Sharp AR-161 Tally MT908 Seiko SpeedJET 200 Tektronix 4696, 4697, Phaser 780 Xerox DocuPrint C55, DocuPrint 4508, DocuPrint N17, DocuPrint N32 page 321 #BREAK# Inside Linux Printer Type You need to consider several things when you set up your Linux system for printer support. One item is the printer itself. Is the printer a dot matrix, an inkjet, or a laser printer? Although most software can send files to any printer, it is always a good idea to take advantage of a printer’s feature set. What am I talking about here? Well, you can send documents as flat ASCII text files to a laser printer, but why not take advantage of the formatting features that the laser printer offers? Each type of printer does particular things well. A mechanical dot matrix printer is good for printing multipart forms. Laser printers are good at scaling fonts to various sizes and are quite adept at applying font styles, such as bold and italics; and effects, such as outline and shadow. Inkjet printers are really geared for individual use. Inkjet printers are quite flexible, providing the option to print in black and white or in color. Printer Language You can choose from two printer languages: PostScript and Printer Control Language (PCL). PostScript was popularized by Apple, specifically by the introduction of its LaserWriter printer. As can be expected, each language has its advantages and disadvantages. The best choice, if you can opt for it, is to go with a PostScript printer. I say “if you can opt for it” because PostScript is specifically supported by laser printers. Another reason is that the PostScript option is, as a rule, more expensive than PCL. The benefits of PostScript, in the long run, should outweigh the extra cost. Most UNIX software speaks PostScript because, historically, PostScript is the native printer language of the UNIX community. PostScript is also the native tongue used within the publishing industry. PostScript is also independent of device. In other words, PostScript is not specific to printers; some programs display PostScript to computer screens and can send PostScript files to fax machines. PCL is a page-description language developed by Hewlett Packard. The PCL language is implemented in many HP (and other vendor) laser and inkjet printers. PCL version 5 and later versions support Intellifont, which is a scalable font. A PCL command is identified using Escape character (ASCII value 27) as the first command character. The remaining characters, which identify the command, are usually printable characters. The printer ignores PCL syntax errors without warning. You should always ensure that your printer is using the latest PCL language version. The most current version (at the time of this writing) is PCL 5e. Most (current) inkjet and laser printers are PCL compatible. PCL version 5e supports 600dpi, whereas previous versions support only 300dpi. Printer Interface The next obvious thing to consider is the interface to the printer. Is the interface serial or parallel? Some printers offer both options, providing flexibility of service. The most common, of course, is the parallel interface. Do not discount the use of a serial printer, because this interface provides some flexibility. A serial interface printer can be set up at a remote location; you can dial it up and then transmit data to it. A case in point: Not too long ago, I developed a system for a client that is in the business of preparing loan packages for home mortgages. A package is a set of documents for a single mortgage; it can consist of 100 pages or more. The client would print the packages and then courier those packages to the various mortgage companies. I suggested that the client put a single printer with a modem at the (remote) client site and then transmit the packages on demand. Initially, the packages were transmitted manually by an operator at the server site. Eventually, this manual process was automated by software that automatically dialed a remote site, established a connection, and then transmitted the package. Figure 18.1 graphically depicts the process. page 322 #BREAK# Inside Linux Figure 18.1. Transmitting to a remote serial printer. Another advantage of using serial is the length of cable. You can easily run a 50-foot length of serial cable between the computer and a serial printer (for RS 232). You can jump a greater distance if you opt for the RS 422 interface. Using eight-pin wire, I have placed printers more than 100 feet from the computer, with no degradation in delivery of data. There are advantages to the parallel interface. For one, the parallel interface is faster than the serial interface, although I have seen some serial printers coaxed into accepting data at 115,200 baud. Some interesting hacking took place on the part of the hardware and software engineers to achieve this baud rate. Regardless, parallel ports can achieve speeds of 150Kbps with ease. The downside to the parallel interface is the length of the delivery cable. Delivery of data through a parallel cable is good up to about 20 feet. Degradation of data delivery increases as the length of the parallel cable increases (beyond 20 feet). Signal fade occurs on the wire and data is lost. A third interface for data delivery is Ethernet. As a rule, only high-end printers have the capability to use an Ethernet interface. In general, it makes sense to use Ethernet in conjunction with a high-speed laser printer - print data is delivered faster and the data is printed faster. Keep in mind, however, that depending on the amount of print traffic, the Ethernet bandwidth is reduced. This is because the print data must first travel from the (source) workstation to the print server and finally to the printer; the data travels from source to final destination via Ethernet wire. Another downside to a network printer becomes apparent when the network goes down. Dependency on network printing decreases flexibility with respect to printer usage. Configuring Print Services Linux has adopted the BSD-style printer services, and the services are sometimes referred to as lpr. Be warned, however, that some distributions of Linux use the lpsched system. Some distributions offer (or will offer) LPRng, which reduces the administration load for systems that have more than one printer on the network. In addition, LPRng is a good fit if you are using serial printers or other unique printers. Another advantage is that LPRng is freely available. In a pinch, you can send data directly to the printer from the command line, as in the following dialog: stimpy $ ls -al > /dev/lp0 Be sure to check the exact device for your system using the dmesg command. Running dmesg should reveal the device that Linux has detected. page 323 #BREAK# Inside Linux Print Commands Several commands are used to support printer services under Linux. Table 18.2 briefly describes these commands. You should note that the commands begin with a lowercase L -not the numeral 1. Table 18.2. Linux Printer Commands Command Description lpc This command is used to control the printing system. You use lpc to start, stop, and otherwise manipulate the print queue. lpd This is the spool daemon. There is an lpd daemon running for every (running) printer known to the system. There is also one “master” lpd for the system as a whole. The lpd daemon will fork a child to handle any incoming request. lpq This command lists the current jobs found in a print queue. lpr This is the user-centric spool command. The lpr command, when executed, communicates to the lpd command submitting print jobs into the spool. lprm This command is used to remove a print job from the print spool. In a nutshell, when your Linux system boots up, the lpd daemon is executed. The lpd daemon reads the /etc/printcap to obtain configuration information. The /etc/printcap file contains entries for each printer and identifies options for each of the printer entries. Whenever a user submits a file to print using the lpr command, lpr submits the file, the print options, and user information to the lpd daemon. The lpd daemon then uses this information to print the file. Let us examine each of the commands in a little more detail. Then, we take a look at the /etc/printcap file. lpc The lpc command is the line printer control program and is used by a system administrator to control the line printer system. You can use the lpc command to disable/enable a printer, disable/enable a printer’s spooling queue, or rearrange print jobs that are in a spooling queue. You can also use lpc to check the status of printers and their associated queues and daemons. The usage for lpc follows: lpc [command] Table 18.3 describes the available command options for lpc. Table 18.3. The lpc Options Option Description ? [ command … ] Print a description of each command specified in the argument list or a list of the commands if no argument is given. help [ command … ] Print a description of each command specified in the argument list or a list of the commands if no argument is given. abort No all | printer Terminate an active daemon on the host and disable printing for the identified printers. clean No all | printer Remove control, data, and temporary files that cannot be printed for the specified queue. disable No all | printer Turn the identified queues off. This is used to prevent any new print jobs from being submitted into the queue using lpr. down No all | printer message Turn the specified queue off, disable printing, and submit a message into the (identified) printer status file. page 324 #BREAK# Inside Linux Option Description enable No all | printer Enable spooling on the queue for identified printers. exit Exit from the lpc command. quit Exit from the lpc command. restart all | printer Start a new printer daemon. If a daemon is running, kill and restart the daemon. start all | printer Enable printing and start the daemon for the printers listed. status No all | printer Display a status for the daemons and queues. stop all | printer Stop a daemon after the current print job completes, then disable printing. topq printer [jobnum…][user …] Reorganize the jobs listed to the top of the queue. up all | printer Enable printing and start a printer daemon. The commands may be abbreviated, provided no ambiguity occurs. lpd The lpd command is the line printer spooler daemon. The lpd command is usually executed when the Linux system is booted. The lpd command reads the /etc/printcap file to discover available printers and their options. The daemon prints any files lingering in the queue. At the lowest level, lpd uses the listen-and-accept system calls to process requests. As mentioned previously, one master lpd is running - this master lpd will fork a child process to perform any type of queue request. The lpd command can be invoked with a number of options. The following is the usage for lpd: lpd [option] [port] One option is -l (lowercase L). This option tells lpd to log any requests received. This can be quite helpful when debugging printing problems. Another option is specified by port#, which identifies the Internet port number to use whenever the system call getservbyname is invoked. The lpd command attempts to open a file to be printed. If lpd cannot open the file, a message to that effect is submitted to syslog. If the lpd command cannot open the file after 20 tries, it skips that file and moves on. lpq The lpq command is used to list the current jobs found in the print queue. Information reported includes the username that submitted the print job, the job’s position in the queue, the job number, and the total file size. The usage for lpq is as follows: lpq [options] [name] If name is supplied, only information pertaining to the specified username is reported. The -P option identifies the printer to obtain status for. The default is to report on the system printer or the printer identified by the environment variable PRINTER. The -l option to lpq is used to report information about each file owned by a job. The third option available is #jobnum, allowing you to obtain information about a specific job number. lpr The lpr command is used to submit print jobs. The lpr command uses the spooling daemon to print the indicated files. The following shows the usage for lpr: lpr [-Pprinter] [-#num] [-C class] [-J job] [-T title][-U user] [-i [numcols]] [-1234 font] [-wnum] [-cdfghlnmprstv] [name …] page 325 #BREAK# Inside Linux The lpr command will complain about printing binary files. Also, any files that are too large will be truncated. If lpr cannot connect to the lpd daemon, lpr prints a message stating that the spooler cannot be started. If the spooler is disabled and a nonroot user attempts to print a file, a message is displayed and no files are queued. A number of options can be provided to the lpr command. You will see references to the burst page - sometimes called the cover or banner page. The burst page is similar to a fax cover sheet. It contains information such as the user, the job number, and the file that is being printed. The burst page always precedes the file that is printed. In a small network with five or fewer people, you probably do not need to print a burst page. If you have more than five users and a fair amount of printing is being done, a burst page should be required. Table 18.4 lists some of the more common options. Table 18.4. Some Common lpr Options Option Description -P Directs the output to the specified printer. The default printer is usually used or the environment variable PRINTER is queried for the printer. -h Does not print the burst page. -m Sends mail on completion of the print job. -r Deletes the file after spooling or printing (if -s is used) is complete. -s Forces the use of symbolic links. Normally, files are copied to the spool directory. This option forces the use of the symlink call to link to the actual file; thus, the files are not copied. This allows large files to be printed. This also implies that the files to be printed should not be deleted or modified in any way until after they are printed. -#num Uses the value identified by num as the number of copies of the file to print. -T title The title to be used. Normally, the filename is used for the title. -U user Prints the specified username on the burst page. -i [numcols] Indents the output. The numcols argument specifies the number of spaces (or blanks) to be output before the text of the line. Otherwise, eight characters are printed. If numcols is not specified, eight spaces are printed. -wnum Uses the value identified by num as the page width. Several other options can be specified. These options are used to signal that the files are not standard text files. The spool daemon uses the appropriate filter before printing the files, based on the option. lprm The lprm command is used to remove print jobs from the queue. The usage for lprm is as follows: lprm [-Pprinter] [-] [job # …] [user …] Table 18.5 lists the available options and their descriptions. If files are removed from the queue, the lprm command displays the files removed. If no print jobs exist, lrpm does not display a message. If a user invokes the lprm command without any options, all files owned by the user are purged from the queue. If a spool daemon is running, lrpm kills the daemon before purging any files; lrpm then launches a new daemon after the files are purged. page 326 #BREAK# Inside Linux Table 18.5. The lprm Options Option Description -Pprinter This option is used to designate the queue for a specific printer; otherwise, the default printer is used. -This option tells the lprm command to remove all jobs owned by the user. If the user submitting this option is the superuser, the queue will be completely cleared. user This option tells the lprm command to delete jobs (that are queued) that belong to the identified user. Only the superuser can use this option. job # This option allows a user to remove a job number from the queue. The /etc/printcap File The /etc/printcap file is referred to as the printer capability database. Although identified as a database file, it is not one in the strictest sense. The /etc/printcap file is a text file that contains configuration information for printers on the network. The following is a snippet from a fairly comprehensive /etc/printcap file: # # the definition that follows is # for a DecWriter printer #lp|ap|arpa|LA-180 DecWriter III: # :br#1200:fs#06320:tr=f: # of=/usr/lib/lpf:lf=/usr/adm/lpd-errs: #lp:lp=/dev/lp0:sd=/usr/spool/lpd/lp0: # of=/usr/lib/lpf: lf=/usr/adm/lpd-errs # # Generic lp:lp=/dev/lp1:sd=/var/spool/lpd/lp1:sh # The /etc/printcap file is similar in structure to the /etc/termcap file. Whereas the /etc/termcap file is used to describe terminals, the /etc/printcap file is used to describe printers. Any time that the printing system is activated to print a file (or files), the /etc/printcap is accessed and read to retrieve printer information. This allows you to modify the /etc/printcap file to add a printer, to delete a printer, or to change the settings for a printer. This makes the /etc/printcap file’s information dynamic in nature. Each line (entry) in the /etc/printcap file, like other Linux configuration files, describes only one printer. You can break a printcap entry across several lines by using the character, the line- continuation character. This can help with readability for any lines that span beyond the rightmost column of the display or text editor. Each entry is broken into distinct fields. The first field is the name of the printer. Beyond this requirement, all other fields can be placed in any order on the line. The following snippet is the Generic entry shown in the previous example: # Generic lp:lp=/dev/lp1:sd=/var/spool/lpd/lp1:sh # Each field is delimited by a colon character. A comment line begins with the # character. I highly recommend that you sprinkle comments generously within your /etc/printcap file; the file is cryptic enough. Be sure you are consistent with the layout and content for each entry in the file. In other words, place the option fields at the same point for each entry. For example, the sd option field should always be the third field for an entry. You can also make a rule that says, “There should be no more than four fields on a physical line (for each entry).” Be sure to break each entry that spans multiple lines with a character. Consistency provides for more readability and ease of editing. Again, the snippet for the Generic entry follows: # Generic lp:lp=/dev/lp1:sd=/usr/spool/lp1:sh # page 327 #BREAK# Inside Linux The first field is lp and identifies the printer name. A colon ends that field and the next field is lp, not to be confused with the printer name. This field is the device name for output. The value for the lp field is /dev/lp1. A value is defined for a field using the = character. The third field is sd and identifies the spool directory. This field identifies where files are sent and stored to be spooled. In this snippet, files are stored in the /var/spool/lpd/lp1 directory. The last field, sh, is used to suppress the printing of burst pages. Recall that a burst page is a cover page that precedes a print job and provides information about that print job. Each field option is a two-letter designation. Each field can be one of three types: Boolean, numeric, and string. Table 18.6 lists the available field names, their type, the default value, and a brief description. Table 18.6. Field Options for /etc/printcap Option Type Default Description af str NULL Name of the accounting file. br num none If lp is a tty device, set the baud rate for it. cf str NULL The cifplot data filter. df str NULL Identifies the tex data filter. fc num 0 If lp is a tty device, clear flag bits. ff str `f’ The string to send for a form feed. fo bool false Used to send a form feed when the device is first opened. fs num 0 Similar to fc field, but sets the bits. gf str NULL Identifies the graph data filter format. hl bool false Identifies that the burst header page is to be printed last. ic bool false Identifies that the driver supports ioctl to indent the printout; using ioctl is a nonstandard method. if str NULL Identifies the name of the text filter that does accounting. lf str /dev/console for some distributions; NULL for others Identifies the filename for errorlogging. lo str Lock Identifies the filename for the lock file. lp str /dev/lp Identifies the device name to open for output. mx num 1000 Identifies the maximum file size, using BUFSIZ blocks. If the value is zero (0), it is an unlimited size. nd str NULL Identifies the next directory for the list of queues. (May not yet be implemented.) nf str NULL Identifies the ditroff data filter, for device- independent troff. of str NULL Identifies the name of the program for output filtering. pc num 200 Identifies the price per foot (or page) in hundredths of cents. pl num 66 Identifies the page length in lines. pw num 132 This field identifies the page width in characters. page 328 #BREAK# Inside Linux Option Type Default Description px num 0 Identifies the page width in pixels. py num 0 Identifies the page length in pixels. rf str NULL Identifies the filter used for printing FORTRAN text files. rg str NULL Identifies the restricted group; only members of the group are allowed access. rm str NULL Identifies the machine name for the remote printer. rp str lp The name of the remote printer. rs bool false Identifies that remote users are restricted to those with local accounts. rw bool false Identifies that the printer device should be open for reading and writing. sb bool false Identifies that short banner, one line only, should be used. sc bool false Identifies that multiple copies are to be suppressed. sd str /var/spool/lpd Identifies the spool directory. sf bool false Identifies that form feeds are to be suppressed. sh bool false Identifies that the burst page header is to be suppressed. st str status Identifies the name of the status file. tf str NULL Identifies the troff data filter. tr str NULL Identifies the trailer string to print when the queue empties. vf str NULL Identifies the raster image filter. Although the previous table is comprehensive, you should check the printcap man page on your Linux distribution. It is not uncommon for a Linux distribution to not include the man page for printcap. If so, you can find the Linux man pages at http://metalab.unc.edu/mdw/index.html, which is the home page for the Linux Documentation Project. The PRINTER Environment Variable As mentioned previously in this chapter, the PRINTER environment variable identifies the default printer. If you use a specific printer a majority of the time, you can set the PRINTER environment variable in your login shell script. The following shows a sample entry for the bash shell: export PRINTER=laserjet5 You can do this to avoid having to specify the -P option to the various printer commands. Printer Configuration Under SuSE Under SuSE Linux, configuration of a printer can be handled using the YaST utility. In this section, we show the steps involved in getting a printer up and running quickly. You can run the YaST utility from the (text) command line or from within the graphical environment. Figure 18.2 shows the YaST main menu running in the KDE terminal emulation console named Konsole. page 329 #BREAK# Inside Linux Figure 18.2. YaST running in Konsole. From the main menu, select the System Administration option. At the next menu window, select the Integrate Hardware into System menu option. Finally, at the third menu window, select the Configure Printers option. Figure 18.3 shows YaST at the Configure Printers option. Figure 18.3. YaST at Configure printers menu option. Next, you see the Installation of Apsfilter window. This provides an easy way to configure apsfilter which is a universal printer filter. A number of fields are required at this window; most options are specified using menu-based lists. After you have identified all the fields required for this window, select the Install button. Figure 18.4 shows the window prior to selecting the Install button. Figure 18.4. YaST at Installation of Apsfilter window. page 330 #BREAK# Inside Linux The YaST utility runs a script file to assist in creating the printer. When it is complete, a message box is displayed. Figure 18.5 shows a sample of the message window. Figure 18.5. Message Confirmation dialog window. At this point, simply select the Continue button on the Confirmation window and you will be returned to the last YaST menu window selected. You can now exit YaST. Changes are made to the /etc/printcap file. The following is a snippet from the file, showing only the apsfilter entries: ? # BEGIN apsfilter: ? # PS_300dpi letter color 300 ? # # Warning: Configured for apsfilter, do not edit the labels! # apsfilter setup Tue Dec 14 05:40:01 CST 1999 # ascii|lp1|PS_300dpi-letter-ascii-mono-300|PS_300dpi letter ascii mono 300: :lp=/dev/lp0: :sd=/var/spool/lpd/PS_300dpi-letter-ascii-mono-300: :lf=/var/spool/lpd/PS_300dpi-letter-ascii-mono-300/log: :af=/var/spool/lpd/PS_300dpi-letter-ascii-mono-300/acct: :if=/var/lib/apsfilter/bin/PS_300dpi-letter-ascii-mono-300: :la@:mx#0: :tr=:cl:sh:sf: # lp|lp2|PS_300dpi-letter-auto-color-300|PS_300dpi letter auto color 300: :lp=/dev/lp0: :sd=/var/spool/lpd/PS_300dpi-letter-auto-color-300: :lf=/var/spool/lpd/PS_300dpi-letter-auto-color-300/log: :af=/var/spool/lpd/PS_300dpi-letter-auto-color-300/acct: :if=/var/lib/apsfilter/bin/PS_300dpi-letter-auto-color-300: :la@:mx#0: :tr=:cl:sh:sf: # lp-mono|lp3|PS_300dpi-letter-auto-mono-300|PS_300dpi letter auto mono 300: :lp=/dev/lp0: :sd=/var/spool/lpd/PS_300dpi-letter-auto-mono-300: :lf=/var/spool/lpd/PS_300dpi-letter-auto-mono-300/log: :af=/var/spool/lpd/PS_300dpi-letter-auto-mono-300/acct: :if=/var/lib/apsfilter/bin/PS_300dpi-letter-auto-mono-300: :la@:mx#0: :tr=:cl:sh:sf: # raw|lp4|PS_300dpi-letter-raw|PS_300dpi letter raw: :lp=/dev/lp0: :sd=/var/spool/lpd/PS_300dpi-letter-raw: :lf=/var/spool/lpd/PS_300dpi-letter-raw/log: :af=/var/spool/lpd/PS_300dpi-letter-raw/acct: :if=/var/lib/apsfilter/bin/PS_300dpi-letter-raw: :la@:mx#0: :tr=:cl:sh:sf: ? # END apsfilter: ? # PS_300dpi letter color 300 ? # Your /etc/printcap entries will most likely look different from what is shown here. page 331 #BREAK# Inside Linux You can also use YaST to configure remote printers. If you need to configure a remote printer, start YaST. When the main menu is displayed, select the System Administration option. At the next menu window, select the Network Configuration menu option. Finally, at the third menu window, select the Administer Remote Printers option. Figure 18.6 shows YaST at this stage. Figure 18.6. Administer remote printers menu option. A new window is displayed, showing a number of fields. The first field, Name of Remote Printer, is highlighted. At the bottom of the window, you will see various command buttons. Some of the fields on this screen can present options by selection. You do this using the F3=Selection command button. Figure 18.7 shows the Printer Selection window displayed, after the F3 keyboard key is selected. Figure 18.7. Printer Selection window. After you have supplied values for the fields, press the F4 keyboard key. This writes the changes and applies them to the /etc/printcap file. The following shows (only) the changes that are applied. ? # BEGIN apsfilter: ? # PS_300dpi letter color 300 ? # # Warning: Configured for apsfilter, do not edit the labels! # apsfilter setup Tue Dec 14 05:40:01 CST 1999 # :rm=remote.server.com: :rp=lp: :sd=/var/spool/lpd/PS_300dpi-letter-ascii-mono-300: # lp-mono|lp3 … You need to be cautious about using this option under YaST. If you define the same remote printer, it will be added to the /etc/printcap file and you will have duplicate entries for that remote printer. After running YaST, you should check the /etc/printcap file in your editor and make any appropriate modifications. After YaST has applied the required changes, you are returned to the main menu. page 332 #BREAK# Inside Linux Printer Configuration Under Red Hat Under Red Hat Linux, configuration of a printer can be handled using the Printer Configuration utility in the Control Panel. This utility provides a user-friendly graphical front end to configure all types of printers. It is assumed that you are running the GNOME environment. Before we add a new printer, let us take a look at the /etc/printcap file. The following shows the contents of the file on my machine. The contents of your /etc/printcap file will be different. # # Please don’t edit this file directly unless you know what you are doing! # Be warned that the control-panel printtool requires a very strict format! # Look at the printcap(5) man page for more info. # # This file can be edited with the printtool in the control-panel. ? PRINTTOOL3? LOCAL cdj550 300×300 letter {} DeskJet550 3 1 lp: :sd=/var/spool/lpd/lp: :mx#0: :sh: :lp=/dev/lp0: :if=/var/spool/lpd/lp/filter: #end If the Control Panel is not currently running, from the GNOME main menu, select System, Control- Panel. Figure 18.8 shows the control-panel with the Printer Configuration utility icon highlighted. Figure 18.8. Printer Configuration in Red Hat’s control-panel. Click the Printer Configuration icon in the control-panel to execute the utility. Figure 18.9 shows the Red Hat Linux Print System Manager window. Notice that the configuration shows a printer installed. Existing entries can be modified or a new entry defined. Three command buttons are located at the bottom of the window. The Edit button enables you to modify an existing printer entry, the Add button enables you to define a new printer entry, and the Delete button removes an existing printer entry. Figure 18.9. Red Hat Linux Print System Manager. page 333 #BREAK# Inside Linux Because we want to add a new printer definition, click the Add button. Figure 18.10 shows the Add a Printer Entry window. On this window, we can define the new printer to be a Local Printer, Remote UNIX Queue, SMB/Windows printer, or a NetWare Printer. For now, click the Local Printer option button and then click OK. Figure 18.10. Add a Printer Entry dialog window. Next, the Edit Local Printer Entry window is displayed, as shown in Figure 18.11. Several fields need to be filled. For the Input Filter field, you can click the Select button to bring up a list of printers. Figure 18.11. Edit Local Printer Entry dialog window. Go ahead and click the Select button located to the right of the Input Filter field. The Configure Filter window is displayed, as shown in Figure 18.12. From this list, you can select various popular printers. Simply scroll down the list of available printers and select your printer. As you select a printer, the other fields on the Configure Filter window change automatically. You can accept the default values or make changes as you see appropriate. After you have completed the settings on the Configure Filter window, click OK. This dismisses the dialog window. Figure 18.12. Configure Filter dialog window. page 334 #BREAK# Inside Linux Finally, you should see the Red Hat Linux Print System Manager displayed with the new printer entry you have chosen (Figure 18.13). Figure 18.13. Red Hat Linux Print System Manager. To exit this dialog window, click the Close button on the title bar, or from the menu, select PrintTool and then Quit. Before exiting, you may need to restart the lpd daemon. If so, select the lpd menu option and then select the Restart option. Changes are automatically made to the /etc/printcap file. The following is the contents of the file. Compare this with the output shown earlier. # # Please don’t edit this file directly unless you know what you are doing! # Be warned that the control-panel printtool requires a very strict format! # Look at the printcap(5) man page for more info. # # This file can be edited with the printtool in the control-panel. ? PRINTTOOL3? LOCAL cdj550 300×300 letter {} DeskJet550 3 1 lp: :sd=/var/spool/lpd/lp: :mx#0: :sh: :lp=/dev/lp0: :if=/var/spool/lpd/lp/filter: ? PRINTTOOL3? LOCAL cdj550 300×300 letter {} DeskJet550 3 {} myLP: :sd=/var/spool/lpd/lp0: :mx#0: :sh: :lp=/dev/lp0: :if=/var/spool/lpd/lp0/filter: #end Notice that the printer entry named myLP has been added to the file. The entry is also preceded with a comment stating that the PrintTool utility created the new printer entry. Summary We started this chapter with an overview of the Linux print services. We learned that when we send a file to the printer, the file does not immediately go to the printer. Rather, the file is sent to a temporary area known as the print queue to await its turn to be printed. Various popular printers supported by Linux are shown in Table 18.1. If your printer is not supported, it might be time for an upgrade. Even if your printer is not directly supported, you might be able to choose a different printer that your printer will mimic. We discussed some items that need to be considered when selecting and configuring a printer. Printer type should be considered. Do you need a dot-matrix, laser, or inkjet printer? Printer language also needs to be considered. Linux supports both PostScript and PCL-style printers. The PostScript is a more flexible printer, but with this flexibility comes higher costs. page 335 #BREAK# Inside Linux The printer interface is another consideration when configuring a printer. Printers are offered with either a parallel or a serial interface. Some high-end printers provide both interfaces. Parallel cables have a length limit of about 20 feet; beyond this distance, data can be lost on the way to the printer. A serial interface is preferred if the distance from print server to printer is beyond 20 feet. Next, the print commands and daemons were covered. The lpc command is used to start, stop, and otherwise manipulate the print queue. The lpd daemon is the spool daemon and controls the printing of files. The lpq command is used to list jobs in the print queue. The lpr command communicates to the lpd command, submitting print jobs. Finally, the lprm command is used to remove print jobs from the queue. The /etc/printcap file was covered next. Each line in the file is a printer entry. There should be an entry in the /etc/printcap file for each printer on the system. Each entry in the /etc/printcap file consists of individual fields describing attributes about the printer and how to operate it. Each field is separated by a colon character. We closed the chapter with two sections specific to two Linux distributions. First, printer configuration under SuSE Linux was covered using the YaST configuration utility. Finally, we covered printer configuration under Red Hat, using the PrintTool utility. page 336 #BREAK# Inside Linux Part IV: System Administration 19. The Tools 20. Booting and Shutdown 21. Security 22. Managing Accounts 23. Other Administrative Tasks page 337 #BREAK# Inside Linux Chapter 19. The Tools Now there is a chapter title that sounds all-encompassing! What does “The Tools” refer to? Good question. This chapter is about some of the more interesting tools that are used with various Linux distributions. Many of the “generic” tools have been covered in other chapters of this book. Some of the generic tools covered are Samba, Apache, and system administration tools including user management (such as adduser), file management (such as mkdir), process management (such as ps and kill), and printing. Most of those tools are quite commonplace and are fairly well documented in this book and in the public domain. What we will do here is examine some of the more popular distributions of Linux and the tools they offer. Some of the tools are distribution-agnostic -in other words, if we are discussing the StarOffice suite, we do not need to address a specific Linux distribution. But if we want to discuss YaST (SuSE) or Linuxconf (Red Hat) or TurboWMCfg (TurboLinux), the discussion will be vendor-specific. Overview It seems like quite an endeavor to try to address the many tools available for different distributions of Linux. Although I would like to talk about all the possible tools, I cannot. A whole book would have to be dedicated to that chore. In this chapter, we will discuss only the tools that would be used most often by the average Linux user. Some books are distribution specific (or vendor specific) and are good if you are staying with one distribution. The truth of the matter is that many Linux users like to experiment with different Linux distributions. This could be because of pure curiosity and interest in researching them, or it could be that you need to evaluate several distributions to find the best fit. Some people argue that a single-distribution operating system is the best answer to an organization’s needs. Some companies would like you to think their operating system is the all-encompassing and all-enduring solution. The problem with that belief is that you must (strictly) adhere to their standards. You must be satisfied with their user interface. You must be satisfied with their filesystem. You must be happy with their -well, you better be happy with them as a company. Many of these companies are just happy to pocket your money and continue to do what they want. It doesn’t have to be that way - that is a pledge from the world of Linux. You are free to choose the distribution of Linux you want, based on your needs and the features and benefits offered by a particular Linux distribution. Are you unhappy with your Linux vendor and can’t get resolution? Fine; switch to another vendor. You say you are dissatisfied with the window manager? Switch to one of several that are available for Linux. I think you get the idea. We will begin our journey through the tools landscape by investigating some of the more general tools and then moving on to the distribution-specific tools. Then we will address so-called productivity tools - programs that are used for everyday office tasks such as word processing. Follow along as we unravel some of the more popular tools in use today. Configuration, Maintenance, and Management Tools This section covers various tools that you can use to configure, maintain, or manage Linux and Linux programs. Red Hat Package Manager (RPM) RPM, although considered vendor-specific, has found its way onto the CD-ROMs of many Linux (and UNIX) distributions. RPM is a powerful package manager that is used to build, install, query, uninstall, update, and verify individual software packages. Many Linux vendors have recognized the power of RPM and use it for their distribution. Some vendors furnish a front end to RPM, relieving the user of having to decide which RPM option(s) to use. RPM is open software, distributable under the GNU Public License (GPL). Here is the command-line usage for RPM: rpm [options] page 338 #BREAK# Inside Linux An RPM package consists of an archive of files, plus package information including name, version, and description. The features provided by RPM are many, making software maintenance easier than what is possible with tar/zip packages. RPM has five basic modes of operation: install, query, uninstall, update, and verify. The next five sections address each of these. Let’s see how to become productive with RPM. Installing an RPM Package This has to be the most popular mode of operation for RPM. The main reason we use RPM is to install software. You have probably seen an RPM package filename. Here is a real-world example of an RPM filename: xfree86-doc-3.3.5-3.i386.rpm The filename can be broken down into its individual identifiers. xfree86 is the software identifier. doc- further identifies the software as containing documentation for XFree86. 3.3.5 designates the version of the software, and -3 is the software release. The last identifier is i386, which identifies the architecture. Other architectures might be sparc or alpha. The key to installing an RPM package lies with the letters ivh. These letters, as you might guess, are options to the rpm command. The following dialog demonstrates how to install the XFree86 package just mentioned: stimpy $ rpm -ivh xfree86-doc-3.3.5-3.i386.rpm XFree86 ???????????????# stimpy $ Upon execution of the rpm command, the package name is displayed, and then a series of hash marks (#). The hash marks provide a visual clue, like a progress meter. A number of errors can appear. If the package already exists, or there are conflicting files or unresolved dependencies, you will see an error message reflecting the problem. If the package already exists or there are conflicting files, you can force the installation using the replacefiles option to the rpm command. For an unresolved dependency, it is recommended that you install the package that is required. Obviously, the package you want to install requires some other software to run and cannot be found. If you absolutely insist on installing the package, you can force the installation using the - nodeps option to the rpm command. Querying with RPM When you query a package or RPM database, nothing really happens to your system. In other words, nothing is installed, removed, or updated. The intent is to just check out the contents of the package or installed packages. The following usage shows the easiest way to query a package: stimpy $ rpm -q [option / packageName] You can specify an option to the query switch. You can also specify the package name to query. The following dialog demonstrates the query option: stimpy $ rpm -qa aaa_base-99.11.9-0 aaa_dir-99.11.1-0 aaa_skel-99.10.31-0 at-3.1.8-95 base-99.9.13-11 … ypserv-1.3.9-4 bind8-8.2.2-41 samba-2.0.6-16 stimpy $ page 339 #BREAK# Inside Linux This dialog lists the installed packages on the system. Of course, this list does not represent all packages installed. The following dialog demonstrates the results of two different queries (each in bold text) to the bind8 package: stimpy $ rpm -qi bind8 Name : bind8 Relocations: (not relocateable) Version : 8.2.2 Vendor: SuSE GmbH, Nuernberg, Germany Release : 41 Build Date: Thu Feb 3 02:51:09 2000 Install date: Fri Feb 4 02:05:39 2000 Build Host: waerden.suse.de Group : unsorted Source RPM: bind8-8.2.2-41.src.rpm Size : 2353522 License: 1989 The Regents of the University of California. Packager : feedback@suse.de Summary : BIND v8 -Name Server (new version) Description : The new named daemon with examples. The support utilities nslookup, dig, dnsquery and host are found in the package bindutil. Documentation on setting up a name server can be found in /usr/doc/packages/bind . Authors: ISC Software Paul Vixie SuSE series: n stimpy $ rpm -qc bind8 /etc/named.conf /sbin/init.d/named /var/named/127.0.0.zone /var/named/localhost.zone /var/named/root.hint stimpy $ The first option displays general package information and the second query displays the files marked as configuration files. Uninstalling an RPM Package Uninstalling an RPM package is as simple as installing a package. There is a slight difference, though, because you identify the package name and not the (original) package filename. The following dialog demonstrates the execution of RPM with the uninstall option: stimpy $ rpm -e bind8 … stimpy $ This dialog uninstalls the package from the system. The following dialog demonstrates the use of the test option. Nothing is removed, but RPM goes through the functional procedure as if to remove the named package. Be sure to use the -vv option to see the output. stimpy $ rpm -e - test -vv bind8 D: opening database mode 0×0 in //var/lib/rpm/ D: will remove files test = 1 D: file: /var/named/slave action: remove D: file: /var/named/root.hint action: remove D: file: /var/named/localhost.zone action: remove D: file: /var/named/127.0.0.zone action: remove D: file: /var/named action: skip D: file: /var/adm/fillup-templates/rc.config.bind action: remove … D: file: /sbin/init.d/rc2.d/S11named action: remove D: file: /sbin/init.d/rc2.d/K34named action: remove D: file: /sbin/init.d/named action: remove D: file: /etc/named.conf action: remove D: removing database entry stimpy $ You might receive a dependency error. This will occur if some other package on the system depends on the package you want to remove. If you want to remove the package anyway, simply supply the nodeps option. Updating an RPM Package There are two ways to update a package on your system: an upgrade and a freshen. An upgrade installs a package; a freshen doesn’t install a package if the package doesn’t currently exist. The following dialog demonstrates an upgrade and a freshen. The commands are in bold: stimpy $ rpm -Uvh xfree86-doc-3.3.5-3.i386.rpm XFree86 ???????????????# stimpy $ rpm -Fvh xfree86-doc-3.3.5-3.i386.rpm XFree86 ???????????????# stimpy $ page 340 #BREAK# Inside Linux The difference between the invocations, as you can see, is in the options used. To upgrade, -Uvh is used. The option -Fvh is used to freshen a package. If you want to freshen a group of packages in one shot, simply issue the rpm command like this: stimpy $ rpm -Fvh *.rpm This allows you go about your business while RPM takes care of freshening multiple packages. Verifying an RPM Package If you need to compare the contents of a package with what is installed, use the verify feature of RPM. You can verify one or more individual files within a package, check the complete package, or check all installed packages. The following dialog demonstrates the use of each invocation: stimpy $ rpm -Vf /usr/bin/addr … stimpy $rpm -Va … stimpy $rpm -Vp xfree86-doc-3.3.5-3.i386.rpm … stimpy $ The first invocation of RPM verifies the file named /usr/bin/addr. To further the example, the following dialog is presented. The switch -vv is added to show more verbose output from the rpm command. stimpy $ rpm -vv -Vf /usr/bin/addr D: opening database mode 0×0 in //var/lib/rpm/ D: record number 6660248 D: dependencies: looking for bindutil D: dependencies: looking for /bin/sh D: dependencies: looking for /bin/sh D: dependencies: looking for ld-linux.so.2 D: dependencies: looking for libc.so.6 D: dependencies: looking for libc.so.6(GLIBC_2.0) D: dependencies: looking for libc.so.6(GLIBC_2.1) D: dependencies: looking for bind stimpy $ The second execution verifies all installed packages on the system. The following dialog shows more detail for this execution (without showing every package installed): stimpy $ rpm -Va S.5….T c /etc/modules.conf S.5….T c /etc/motd .M…… c /etc/permissions .M…… c /etc/permissions.easy .M…… c /etc/permissions.paranoid .M…… c /etc/permissions.secure … …….T /usr/doc/packages/alsa/README.alsaconf …….T /usr/doc/packages/alsa/README.driver …….T /usr/doc/packages/alsa/SOUNDCARDS …….T /usr/doc/packages/alsa/TODO.driver S.5….T c /etc/smb.conf stimpy $ With the “verify all” option, expect the rpm command to run quite a while, especially if you have a legion of installed packages. The third invocation verifies the installed package with the package file. The following dialog shows more detail: stimpy $ rpm -vv -Vp ./root/DOWNLOADs/bind8.rpm D: opening database mode 0×0 in //var/lib/rpm/ D: New Header signature D: Signature size: 68 D: Signature pad : 4 D: sigsize : 72 D: Header + Archive: 1046019 D: expected size : 1046019 D: dependencies: looking for bindutil D: dependencies: looking for /bin/sh D: dependencies: looking for /bin/sh D: dependencies: looking for ld-linux.so.2 D: dependencies: looking for libc.so.6 D: dependencies: looking for libc.so.6(GLIBC_2.0) D: dependencies: looking for libc.so.6(GLIBC_2.1) D: dependencies: looking for bind stimpy $ The following shows the output from RPM when discrepancies are discovered: stimpy $ rpm -Vp samba.rpm S.5….T c /etc/smb.conf stimpy $ page 341 #BREAK# Inside Linux RPM will be quiet (nothing will be output) if all is verified. If there are discrepancies, RPM will let you know, as it did in the previous dialog. What RPM has told us is that the /etc/smb.conf file is a configuration file (c) and that the size, MD5 checksum, and file modification time have failed verification. This stands to reason, because the file has been modified since the package was installed. The following is a list of identifiers that signify a specific test: 5: MD5 checksum S: File size L: Symbolic link T: File modification time D: Device U: User G: Group M: Mode (includes permissions and file type) The output is in the form of a string of eight characters. If the character c is present, it identifies the file as a configuration file. Finally, the filename is printed. A single . (period) means that the test passed. The following is the list of identifying characters for each test: stimpy $ rpm -Va S.5….T c /etc/modules.conf S.5….T c /etc/motd .M…… c /etc/permissions .M…… c /etc/permissions.easy .M…… c /etc/permissions.paranoid .M…… c /etc/permissions.secure …….T /usr/doc/packages/aaa_base/fillup.txt …….T /usr/doc/support/suppengl.txt …….T /usr/doc/support/suppform.txt .M…… /sbin/init.d .M…… /sbin/init.d/boot.d .M…… /sbin/init.d/rc0.d .M…… /sbin/init.d/rc1.d .M…… /sbin/init.d/rc2.d .M…… /sbin/init.d/rc3.d .M…… /sbin/init.d/rc6.d .M…… /sbin/init.d/rcS.d ….L… /usr/doc missing /var/catman …..U.. /var/named missing /var/tmp/vi.recover …….T /usr/doc/packages/bash/COMPAT …….T /usr/doc/packages/bash/FAQ …….T /usr/doc/packages/bash/INTRO …….T /usr/doc/packages/bash/NEWS …….T /usr/doc/packages/bash/bashref.html … stimpy $ This dialog demonstrates the verification of all packages on the system. The output was truncated because the list grew to 4,482 lines. page 342 #BREAK# Inside Linux Graphical RPM: Gnome-RPM Gnome-RPM provides a graphical interface to the RPM system for those running the X Windows system. Basically, everything you can do with command-line RPM, you can do with Gnome-RPM. As the name suggests, Gnome-RPM integrates with the GNOME desktop environment. The program is a full-featured graphical application, replete with pull-down menus, a toolbar, a tree view window, and a display window. Figure 19.1 shows Gnome-RPM after it is invoked from the desktop environment. Figure 19.1. Gnome-RPM, a graphical RPM application. If you are familiar with GNOME, you probably noticed that Figure 19.1 does not visually represent a GNOME application. To be fair, the application is running under the KDE desktop environment on SuSE 6.3 Linux. Additionally, the Photon theme is running. Under the Packages menu, the options available are Query, Uninstall, Verify, and Create Desktop Entry. Under the Operations menu, the available options are Find, Web Find, Install, and Preferences. Toolbar icons match most of the menu options listed. The basic operation of Gnome-RPM is straightforward. You browse around and select a package (or packages), and then you apply one of the commands using the menus or toolbar. The Web find option is unique in that it offers you the chance to search the Internet for packages you want to install or update. The interface for Gnome-RPM should be familiar to you. You select from categories of packages in the tree view pane, and then select packages that appear in the display pane (on the right side). Figure 19.2 shows the unsorted category selected and the corresponding packages in the right pane. A number of packages are displayed, such as aaa_base.99.11.9-0, aaa_dir.99.11.1-0, aaa_skel.99.10.31-0, and so on. As mentioned previously, you select a package and then apply the desired operation. Figure 19.3 shows the Query window after the modules-2.3.6-3 package was selected from the Kernel subcategory under the Base category (in the tree view). page 343 #BREAK# Inside Linux Figure 19.2. Gnome-RPM showing package icons in the display panel. Figure 19.3. Gnome-RPM Query window. The Query window shows vital information about the package, including a scrollable text area displaying the package description and a second scrollable text area showing the contents of the package. This window also has command buttons for Verify, Uninstall, and Close. The Verify window, shown in Figure 19.4, shows the result of package verification. For every problem found, a message is displayed in the columnar list area. page 344 #BREAK# Inside Linux Figure 19.4. Gnome-RPM Verify window. Notice that a verification failed concerning the modification time for the /usr/doc/packages/isax/rc.sax file in the isax-1.2-3 package, which is in the configuration category. If you want to add a new package to Gnome-RPM, select the Install option from the Operations menu. You see the Install window, as shown in Figure 19.5. Figure 19.5. Gnome-RPM Install (Add/Install) window. The intent here is to add new packages that are coming from the “outside” world. In other words, you might want to add and install packages from a CD-ROM, or maybe you downloaded some packages from the Internet. Using the Install window allows you to add packages to the database and then install them. Let’s assume that we want to add and install the Samba package. First, click the Add button in the Install window. The Add Packages window appears, as shown in Figure 19.6. page 345 #BREAK# Inside Linux Figure 19.6. Gnome-RPM Add Packages window. Notice that there are a number of ways to identify a package with this window. There is a tree view pane on the extreme left, showing the directory tree. You use this pane, along with the selection pane to the right of the tree view pane. There is a text box at the bottom of the window, allowing you to type the pathname manually. In Figure 19.7, the Samba package is selected, and the Add button has been clicked. Figure 19.7. Gnome-RPM Add Packages window with Samba selected. Next, click the Close button. Focus is returned to the Install window. At this point, you might not see the package, so select All Packages from the Filter combo box. Figure 19.8 shows the Samba package added to the unsorted category. page 346 #BREAK# Inside Linux Figure 19.8. Gnome-RPM Install window with Samba selected. From here, you can check the signature, perform a query, upgrade or install the package, or do nothing and close the window. Do you need to find a package on the Internet? The easy way is to select the Web Find button or menu option. Figure 19.9 shows the Rpmfind window after the RPM list was downloaded. Figure 19.9. Gnome-RPM Rpmfind window with Apache for SuSE 6.3 selected. At this point, you can decide to download and install the package (or packages) or close the window. Armed with the well-respected RPM and Gnome-RPM package manager applications, you will discover that installing, updating, verifying, and removing packages is a breeze. Here’s one last note about installing software packages under Linux: The best part is that you do not have to reboot the system in order to use the software. page 347 #BREAK# Inside Linux Using YaST Under SuSE (6.3) Yet another Setup Tool (YaST) is designed to be, well, another setup tool. YaST improves the installation process and helps relieve the user of some heartache. We will be looking at the YaST that is shipped in version 6.3 of SuSE Linux. Before we get started, Table 19.1 describes the options to YaST. Table 19.1. Options for YaST Option Description -m Does not use colors. -v Prints the compile time for YaST and exits. -h Prints this info. - help Prints this info. - tTerminal Uses the identified Terminal instead of stdout. -dDebug Writes debug output to the identified Debug. - nomenu Does not go into the main menu loop. - plain Removes the /var/lib/YaST/install.inf file before startup. - version Prints the YaST version number and exits. - autoexit Exits automatically after the end of the first screen. - mask name Executes the screen name automatically. Possible values for name are help, install, update, readme, copyright, language, keymap, medium, fdisk, filesys, login, user, group, backup, consolefont, timezone, xfree, gpm, security, rcconfig, mouse, modem, cdrom, printer, isdn-hw, scanner, netcard, kernel, bootdisk, rescue, lilo, network, name, services, nameserver, ypclient, sendmail, netprinter, isdn-num, ppp, live-con, and live-discon. I would like to mention one other thing. This section deals with YaST-1, not Yast-2. For one thing, Yast-2 had some problems with the shipping product, so I chose to discuss YaST-1, because it is stable and the “least common denominator” of the two tools. Oddly enough, too, is the fact that I have more control over setup using YaST-1. Let’s start with a screen shot of the top-level menu, shown in Figure 19.10. Figure 19.10. YaST-1 at the top-level menu. page 348 #BREAK# Inside Linux Some of the menu options are just one-time items, such as General Help for Installation, Copyright, and Show README File for Installation Media. Let’s jump right into the first (real) menu option, Adjustments of Installation. Figure 19.11 shows the resulting menu. Figure 19.11. YaST-1 at the Adjustments of Installation pop-up menu. You can perform a number of operations here. You can set your language, such as English or Russian, using the Select Language option. The Select Keymap option allows you to choose from among different keyboard types, such as QWERTY, DVORAK, AMIGA, and others. You can also select the keyboard’s language. The Select Installation Medium menu option allows you to select the origin of the installation medium. The options available are installation via NFS or from a CD-ROM, directory, hard drive partition, or FTP site. The Configure Hard Disk Partitions option lets you partition one or more hard drives. You can do a lot with this tool. It is easy to use and gets the job done. Figure 19.12 shows this tool in action. The second hard drive is currently selected, waiting to be massaged. Figure 19.12. Editing the Partition Table screen. page 349 #BREAK# Inside Linux Personally, I prefer a tool that is focused on the partitioning challenge. PartitionMagic (currently 5.0) from PowerQuest is a top choice and has been around longer than most other tools in its class. Other honorable mentions are Partition Commander from V Communications and Quarterdeck’s Partition- It. You can go to http://www.pcmag.com to read the reviews and decide which tool you prefer. The next menu option is Set Target Partitions/Filesystems. It allows you to set mount points, select an inode density, format a partition, and so on. Figure 19.13 shows the Creating Filesystems screen. Figure 19.13. Creating Filesystems. This screen is intuitive and easy to use. You should create more than one partition. Normally, you would create a partition for root, /usr, /tmp, and /var. Be aware, though, that you should keep /bin, /dev, /etc, /lib, and /sbin on the root filesystem. The Configure the Logical Volume Manager option is used to set up the LVM (logical volume manager) for Linux. It allows you to concatenate several physical volumes (such as hard disks) to a volume group, forming a storage pool (such as a virtual disk). Figure 19.14 shows the screen that is displayed if you select this menu option. Figure 19.14. LVM Confirmation screen. You should read the warning very carefully. This option is not detailed, for obvious reasons. page 350 #BREAK# Inside Linux The last option on the current submenu is Installation to a Directory. It is used to install the whole Linux system into a directory. Why would you want to do this? You might need to update another machine using NFS. This method provides an easy and painless way to update other machines. You can press the Esc key to return to the top-level menu. The next option of interest is System administration. This menu has 15 choices, as shown in Figure 19.15. Figure 19.15. System Administration submenu. Selecting the Integrate Hardware into System option takes you to another menu. Here, you can modify settings for the mouse, modem, CD-ROM, printers, ISDN hardware, scanner, and networking device. The next menu option, Kernel and Bootconfiguration, provides you with three options. You can select a boot kernel, create a rescue disk, or configure LILO. These options are fairly straightforward - most of them were set during installation. Use these if you have an update kernel or your system has changed and you want to update your rescue disk. You do have a rescue disk, right? Next on the menu list is Network Configuration. Be cautious with the Configure Network Services option. Even if you choose to use the Esc key to back out, you will be carried through all the choices, and the SuSE configuration scripts will be executed. Some of the options prompted for here are Start inetd?, Start portmapper?, and Start NFS server?, among others. You should also be cautious about wandering off into the Configuration Nameserver menu option. You could end up overwriting your DNS configuration files with empty data. If you are connected to the Internet at the time, you will begin getting errors about unresolved addresses. I know, because it happened to me! The next menu option is Configure YP Client. The SuSE people really should change this to NIS (Network Information System). The whole reason behind the name change is because “Yellow Pages” is a registered trademark. This option lets you set up an NIS client, allowing you to access NIS map file information. Refer to Chapter 11, “Network Information Service (NIS),” for more information. The Configure Sendmail Option is used to configure sendmail, which is an electronic mail transport agent. It is not supposed to be a user interface for Internet mail. sendmail’s responsibility is to deliver preformatted email messages. If you are using ISDN, Configure ISDN Parameters is the place to go if you need to alter the ISDN settings. The Configure a PPP Network menu option is worth a trip too because many people utilize dial-up networking. When you select this menu option, the SuSE WvDial Configuration tool is executed, and you are presented with the screen shown in Figure 19.16. page 351 #BREAK# Inside Linux Figure 19.16. SuSE WvDial Configuration screen. A number of options are available on this screen. Be sure that you are not currently online before continuing with this tool. The most important option here is the Configure the Current Profile menu option. Selecting this choice offers up the Profile screen, as shown in Figure 19.17. Figure 19.17. SuSE WvDial Profile screen. At this screen, you simply supply the ISP’s phone number, your account name, and password. You can also specify whether automatic DNS is enabled, the dial method, and the authentication mode. Automatic DNS must be supported by your ISP. If it isn’t, you should obtain the DNS server configuration and set it with YaST. When you have completed the required entries, select the Exit option. You see a “Do you wish to save …” screen. If you want to commit your changes, select Yes; otherwise, select No. If you want to add a remote printer, select the Administer Remote Printers menu option. These are printers that exist remotely from your machine. You will have to supply a server and printer name. If you want to add a remote printer using Samba, select the Administer Remote Printers menu option. On the APSFilter For Samba screen, you must supply the printer type, name, paper format, and DPI settings. Additionally, you must provide the Samba server name, the printer service, a username, and finally a password. Refer to Chapter 15, “Samba: Merging Linux and Windows,” for more information on Samba. Press Esc to return to the previous menu. page 352 #BREAK# Inside Linux Next on the menu list is Configure Live-System, allowing you to integrate a live filesystem from a CDROM or disconnect from one. Doing this allows you to use the programs directly from a CD-ROM. You do not have to install the packages to your hard disk partition(s). If you mount the live filesystem, you must keep the CD-ROM in the drive at all times. Note that although disk space is conserved, performance will be slower. The next menu option is Settings of susewm. This option allows you to set up the default window manager and the configuration files required by the window managers. If you add or remove software packages, you come here to update the menus. Once you have set everything the way you want, select the option; otherwise, select . The User Administration menu option lets you add, modify , and remove users. Selecting this option displays the screen shown in Figure 19.18. Figure 19.18. User Administration screen. As you can see, a new user is being added to the system. All the pertinent information is on the screen; the next step is to press the F4 key to create the user. A processing window pops up momentarily as the user information is added to the system. The user information remains on the screen; you need to press the F10 key to leave the screen and return to the menu. The Group Administration menu option permits you to add, modify, or delete group information. This is very similar to adding users. Next on the list is the Create Backups menu option, which allows you to back up all or a portion of your system. Figure 19.19 shows the screen that is displayed. Figure 19.19. Backup screen. page 353 #BREAK# Inside Linux This greatly reduces the fatigue experienced from doing backups at the command line. To add a directory, press the + key. To remove a directory, press the -key. When you are satisfied with the selections, press the F10 key to continue with the process. As we progress down the menu options, we come to the Security Settings option. Two options are available: General Information on Security and Configuration of the /etc/login.defs File. In the general security screen, you can control the level of system security. For the /etc/login.defs configuration screen, you set the login failed attempts, password expiration, and group ID information, among others. You can set the default console font using the Set the Console Font menu option. To set the time zone information, select the Set Time Zone menu option. The Configure XFree86 menu option permits you to configure your XFree86 Windows system. All this menu option does is start the xf86config command-line script. Running YaST just to execute this is redundant and time consuming. The Configure GPM menu option allows you to determine whether gpm is executed at boot time or not. gpm permits you to use the mouse to cut and paste text among virtual consoles. Change Configuration File is the last menu option on this submenu. This option allows you to set the environment variables that are used to configure a SuSE Linux system. These environment variables are found in the /etc/rc.config file. When the SuSE system configuration scripts are executed, this file is parsed, and the settings there determine which configuration options to employ. Let’s return to the top-level menu. The Choose/Install Packages menu option is our last endeavor within YaST (see Figure 19.20). Figure 19.20. YaST Choose/Install packages screen. A number of menu options are available on this screen; some might be disabled. The Install Packages menu option provides you with a visual interface for installing packages on the system. Selecting this option displays the screen shown in Figure 19.21. Figure 19.21. Install Patches screen. page 354 #BREAK# Inside Linux The browse method selected was directory; notice that a directory path is selected. In the display pane, you see a number of entries, mostly directories. The currently selected item, bind8.rpm, shows its status as installed. Pressing the Spacebar toggles this entry from installed to upgrade. To continue with the installation, press the F10 key. To delete a package that is currently installed, select the Delete Packages menu option. Scroll through the list, using the Spacebar to select packages to be deleted. When you have completed the selections, press the F10 key to remove the software packages. The Change/Create Configuration option allows you to select packages to be added, updated, or removed from the system. The packages are grouped into functional categories such as networking and games, among many others. Be sure you have identified the source medium for the installation. For example, if you’re installing from a CD-ROM, be sure you have identified it and that the CD-ROM medium is in the drive before continuing. Running Linuxconf Under Red Hat 6.1 Linuxconf is a graphical, interactive tool used to perform various maintenance activities, plus it dynamically activates any changes so that those changes are immediately realized. So, Linuxconf provides two benefits to its user: It helps you properly configure the item at hand, and it writes and activates the changes immediately. Let’s start with a screen shot of Linuxconf after startup (see Figure 19.22). Figure 19.22. Linuxconf upon execution. Notice that Linuxconf has two top-level categories, and within those categories are various topics. You see categories named Config and Control. Within the Config tree, the topics are Networking, Users Accounts, File Systems, Miscellaneous Services, and Boot Mode. Within the Control tree, the topics are Control Panel, Control Files and Systems, Logs, Date & Time, and Features. Each of these topics, with the exception of Date & Time and Features, can be expanded to reveal subtopics. As an example, we will open the File systems topic and then select the Access Local Drive subtopic. Figure 19.23 shows the Local Volume tab page. page 355 #BREAK# Inside Linux Figure 19.23. Local Volume tab. On the Local Volume tab, you can add, delete, and edit mount points. As you can see, the status of the mount point is given, in addition to the partition type, size, mount point, filesystem type, and source. If you need to create a new mount, you click the Add button. This takes you to the Volume Specification tab page, shown in Figure 19.24, which consists of four tab pages named Base, Options, Dos options, and Misc. Figure 19.24. Volume Specification tab. Notice the Partition combo box on the Base tab. It would be nice if Linuxconf could fill that combo box with valid partitions. Linux, when booting up, detects all partitions that exist on the computer; Linuxconf could derive this information and make the partitions available for the choosing. It might even be able to make a best guess as to the filesystem type. The next option we will examine is the Networking topic. There are three subtopics to choose from: Client Tasks, Server Tasks, and Misc. Each of these subtopics has a tree that can be expanded further. Figure 19.25 shows the Networking subtopic tree expanded. page 356 #BREAK# Inside Linux Figure 19.25. Networking branch. Here, the Client tasks topic tree is expanded and the Basic Host Information subtopic is selected. Notice that this page consists of four tabs: Host Name, Adapter 1, 2, and 3. Each tab page maintains information specific to the topic tab. On each tab, you can view and change (if applicable) the data on the tab page. After you have made the appropriate changes, be sure to click the Accept button. In the previous section on SuSE’s YaST tool, we showed the procedure to set up PPP dial-up configuration. To provide some contrast, we will follow the same procedure using Linuxconf. To get to the PPP dial-up configuration, open the Networking topic and then the Client Tasks subtopic. Finally, click the PPP/SLIP/PLIP subtopic. Figure 19.26 shows the result of these selections. Figure 19.26. PPP/Slip/Plip Configurations tab. This tab page shows the available devices for use with PPP/SLIP/PLIP - specifically, the ppp0 device is shown. To continue the configuration, click the device you want. If there is no device, click the Add button. Figure 19.27 shows the result of selecting the ppp0 entry. page 357 #BREAK# Inside Linux Figure 19.27. PPP Interface ppp0 Hardware tab. This is the Hardware tab page, the first of four tab pages for the ppp0 interface. A number of properties can be modified, such as line speed and modem port. When you have made the appropriate changes, select the next tab, named Communication. Figure 19.28 shows this tab page. Figure 19.28. PPP Interface ppp0 Communication tab. This page maintains information relating to the modem device. You can change properties such as the modem initialization string and phone number. You can also create a chat script, consisting of expect- send string pairs. Clicking the next tab reveals the Networking tab page, shown in Figure 19.29. page 358 #BREAK# Inside Linux Figure 19.29. PPP Interface ppp0 Networking tab. This tab page maintains settings for an established connection. Some of the settings you can set are timeout values and the MRU and MTU values. Finally, select the PAP tab page, shown in Figure 19.30. Figure 19.30. PPP Interface ppp0 PAP tab. This page allows you to change the Username and Secret (password) fields. Oddly enough (and I have never understood this), the Secret field is not so secret - your password is revealed as plain text. If you walk away from your workstation, anyone can walk up and check out your login sequence, so be cautious! To test your settings, you click the Connect button at the bottom of the tab page. Personally, I have found using Linuxconf to connect to the Internet to be a rather quirky affair. Other people obviously have this same opinion, because Red Hat has introduced RP3, the Red Hat PPP Dialer utility. Figure 19.31 shows two of the tools involved with RP3. page 359 #BREAK# Inside Linux Figure 19.31. Red Hat’s RP3 PPP tools. The window titled usernet is the RP3 dialer. The window titled Internet Connections is the configuration program that is used to add, edit, and delete Internet connections. The third window shown, Edit Internet Connection, is a child window of the Internet Connections window. This is where you apply the changes required for an Internet account. In this instance, the AT&T account is being modified. The Internet Connections application can be executed by selecting Internet, Dialup Configuration Tool. The second application, RP3, can be found under Internet, RH PPP Dialer. As soon as you have a valid Internet account set up, you use the RP3 application to dial up and connect to the service provider. These tools are found under Internet, GNOME (if they are installed). This section provided an overview of the use of the Red Hat Linuxconf tool. Feel free to explore its other configuration possibilities. Running Configuration Tools Under TurboLinux 4.0 TurboLinux comes with a number of tools to configure the system. Not all of them offer a graphical interface. TurboLinux does not offer a one-stop shopping configuration tool, such as SuSE’s YaST or Red Hat’s Linuxconf. Instead, TurboLinux offers individual tools to tackle configuration categories. The following list describes the TurboLinux configuration tools. If the tool is offered in an X Windows interface (its name begins with an X), it is also listed. TurboFSCfg/XturboFSCfg. Used to configure and manage filesystems (create, mount, unmount). TurboHW. Used to determine hardware devices. Turbonetcfg/Xturbonetcfg. Used to configure the network. TurboPkg/XturboPkg. Used to manage RPM (Red Hat Package Manager) packages. page 360 #BREAK# Inside Linux TurboPNPCfg. Used to configure PNP (Plug and Play) devices. TurboPrintCfg. Used to configure local and remote printers. Turboservice/Xturboservice. Used as a real-time service manager. TurboSoundCfg. Used to configure sound card information. TurboTimeCfg. Used to configure time zone information. TurboUserCfg/XturboUserCfg. Used to configure users and groups. TurboWMCfg. Used for selecting which window manager to use. XturboFind. Used to find and locate commands and files. For the sake of consistency, we will examine the tool for PPP dial-up connectivity. This will give us a comparison to the tools offered by SuSE (YaST) and Red Hat (Linuxconf). First, however, you might need to set up your network configuration. In this section, we will check the network settings and then move on to the PPP configuration tool. From the Wharf toolbar, open the Managers tray. The Wharf is the strip of icon buttons that run down the right side of the screen. Next, click the Net Mngr icon button. This invokes the Xturbonetcfg configuration application, shown in Figure 19.32. Figure 19.32. The TurboLinux network configuration tool, Xturbonetcfg. page 361 #BREAK# Inside Linux Xturbonetcfg consists of a menu of seven options and four command buttons. You use the up and down arrow keys to select a menu option, and then you press the Enter key. For example, to modify the host table entries, select the Hosts Table menu option and press Enter. Figure 19.33 shows the Hosts Table configuration screen. Figure 19.33. The Xturbonetcfg Hosts Table configuration screen. This screen displays the entries found in the /etc/hosts file. You see that you can add, edit, and remove entries using this screen. The Cancel button discards any changes you have made, and the Done button saves the changes and returns you to the main menu. The Basic Settings menu option (refer to Figure 19.32) allows you to change global network settings. These options include the hostname, domain name, search domains, DNS name servers, gateway IP, and gateway device. The menu options offering you the opportunity to apply changes are Basic Settings, Hosts Table, Network Interfaces, and Apache Webserver Configuration. Visit each of these, excluding the Apache option for now, and apply the settings that are appropriate for your network. When you are done, click the Save/Exit command button. Next, it is time to launch the TurboPPPCfg application. From the Wharf toolbar, open the Tools tray and click the PPP/Dialup icon button. This launches the TurboPPPCfg configuration tool, shown in Figure 19.34. Figure 19.34. The TurboPPPCfg application window. page 362 #BREAK# Inside Linux Click the Add button to create a new entry. Highlight the entry you need to modify, and click the Edit command button. You see the Configuring pppX (X is the PPP number) screen, shown in Figure 19.35. Figure 19.35. The TurboPPPCfg Configuring pppX screen. A number of items can be modified on this screen. You should provide the required information for your dial-up connection. The Serial Port command button allows you to modify the modem’s serial port. The More Options command button displays a screen, allowing you to configure such things as the MRU, MTU, and timeout values, among other items. If your ISP does not support PAP, you should use the Expect/Send command button to provide a log script. When you have finished with all the appropriate settings for your ISP, click the OK command button. This tells TurboPPPCfg to write the changes and returns you to the main menu. Click the Quit command button in the main menu to quit the application. You are now ready to test your connection to your ISP. At the bottom-left side of the screen, click the modem icon. This initiates the PPP script. Alternatively, you can click the background, select Network, PPP Menu, PPP Start. Once the connection is established, you can execute the Netscape application and go surfing. Before we finish with TurboLinux, let’s look at the TurboFSCfg tool. From the Wharf toolbar, open the Manager tray and select the File Systems icon button. This launches the TurboFSCfg configuration tool, shown in Figure 19.36. Figure 19.36. The TurboFSCfg application. page 363 #BREAK# Inside Linux The opening screen offers four choices. For this exercise, click the Filesystems command button. The Configure Filesystems screen is displayed (see Figure 19.37), allowing you to perform actions on the filesystems. For example, you can mount, unmount, and check filesystems. Figure 19.37. The TurboFSCfg Configure Filesystems screen. For this exercise, we will add and mount a new filesystem. Click the Add command button. The Filesystem Type pop-up window appears. Select the Local Filesystem option. The Edit Filesystem screen is displayed, as shown in Figure 19.38. Figure 19.38. The TurboFSCfg Edit Filesystem screen. In this figure, the settings are already filled in. For this system, the /dev/hda6 partition holds the Red Hat distribution, so the mount point is at /mnt/rh (you can choose another name). You will, of course, provide different settings for the partition and mount point. When you are finished with the settings, click the OK command button. You are returned to the Configure Filesystems screen, as shown in Figure 19.39. The new filesystem should show up as a new entry on this screen. Indeed, the second entry in Figure 19.39 shows that the /dev/hda6 partition is mounted at the /mnt/rh directory. When you are finished with filesystem maintenance, return to the main menu and click the Quit command button. page 364 #BREAK# Inside Linux Figure 19.39. The TurboFSCfg Configure Filesystems screen. Productivity Tools There are increasing numbers of applications for Linux. We will focus here on the most well-known general office-type application, StarOffice. Running StarOffice This section takes a brief look at version 5.1 of StarOffice. StarOffice is an integrated office suite that runs on a variety of platforms, providing seamless access to files and applications. It provides a consistent interface that is quite easy to use. StarOffice provides one window to all the suite products: files, email, spreadsheets, graphics, and presentations, just to name a few. Plus, other applications can be invoked from within the StarOffice workplace. Figure 19.40 shows StarOffice after it is invoked. Figure 19.40. StarOffice 5.1 desktop. The opening screen of StarOffice offers a window with a number of icons. Each of these represents a different file type in StarOffice. page 365 #BREAK# Inside Linux As mentioned, you can use StarOffice to create word processing documents, surf the Web, create HTML documents, process your email, create graphics images, run spreadsheets, and create presentations. You do not have to execute a separate application for each product type. Figure 19.41 shows the StarOffice Browser in action at the http://www.sun.com Web site. Figure 19.41. StarOffice 5.1 at the Sun Microsystems Web site. It’s nice to be able to jump between windows within a tool, rather than having to search for an individual application window on the desktop. StarOffice is a truly integrated office suite. You can create a word processing document and instantly turn it into an HTML document, and vice versa. Look at the bottom toolbar in Figure 19.41. You see two icons, each representing a file type. One is titled Chapter 19 (what you are reading), and the other is titled Sun Micro…. Each icon represents an individual window with its specified type. These buttons allow you to quickly switch to the desired window. You might have noticed that the Chapter 19 icon looks like a Microsoft Word document icon. That is because StarOffice knows how to read and write Word 95 and 97 file types. (I used StarOffice to write the manuscript for this book.) I leave you to try out the StarOffice suite. Most popular distributions of Linux include it (among other software products). If StarOffice is not included, you can download it from http://www.sun.com. Summary This chapter covered a few of the important tools that are used to install Linux software, configure an installed Linux system, and provide office productivity. We first looked at the Red Hat Package Manager (RPM) tool. Although Red Hat is in the name, RPM is an open source application designed to build, install, query, uninstall, update, and verify individual software packages. Most Linux distributions are now using RPM to install and maintain software packages. We also looked at Gnome-RPM, which provides a graphical interface to the RPM system. Next, we went through an overview of the Yet another Setup Tool (YaST), which is included in the SuSE Linux distribution. It improves the installation process and provides maintenance of the system after installation. The Linuxconf tool, distributed with Red Hat, is a graphical tool used to perform various maintenance activities. It also activates any changes so that they are immediately realized. We also took a look at some of the tools offered under the TurboLinux distribution. Specifically, we examined the Xturbonetcfg, TurboPPPCfg, and TurboFSCfg configuration tools. TurboLinux does not provide an integrated setup and maintenance tool, but does offer individual tools. page 366 #BREAK# Inside Linux Finally, we quickly examined StarOffice and its capabilities. It provides a truly integrated suite of office applications. This chapter is not meant to be an exhaustive resource for all the tools you will use while running Linux. Many other quality applications and tools are available for Linux. Covering them all would become a book in itself. Check Appendix A, “Other Sources of Information,” and Appendix B, “Common Questions,” for more information regarding Linux applications and where to find them. Cheers! page 367 #BREAK# Inside Linux Chapter 20. Booting and Shutdown In this chapter, we explore the Linux boot process. If you want to use Linux, booting is unavoidable, so it is important to understand the boot process. The average person running an operating system views the boot process as a black box. As a rule, he does not think much about what is happening -he just sits and waits until the logon prompt is available. But most Linux users are a little more adventurous and curious than the average user. It is not uncommon to want to know more about Linux and its inner workings. In this chapter, we see what is happening before we can use Linux. Many Linux users have more than one operating system on their machines. This provides many challenges for booting. For example, my machine contains four distributions of Linux, IBM’s OS/2, IBM DOS 6.2 with the Microsoft Windows 3.11 shell, and Microsoft Windows NT. Linux is my operating system of choice; the others exist because I am forced to use them. Overview The complete boot process, called bootstrapping, is a natural progression that starts when you turn the power switch on. The bootstrap process is straightforward. After you have turned on the power, the computer’s BIOS (Basic Input Output System) goes to a well-known address on the hard disk (or floppy disk) and loads a small executable known as the bootstrap loader. The bootstrap loader is then responsible for loading and starting the operating system. This process is common to personal computers; other computer architectures may use a different sequence for bootstrapping. For the PC, the bootstrap loader can be found in the first sector of the hard drive or floppy disk. The two-step process is required to maintain flexibility. The bootstrap loader is small in size and very focused with respect to functionality. The only role that the bootstrap loader plays is starting the operating system -no other functionality is included. This results in a very small executable, only hundreds of bytes. An added bonus is that the bootstrap loader does not care which operating system it is starting; this allows you to install any operating system or boot manager you want. After Linux is loaded, various hardware items are initialized and device drivers are loaded. Next, the init process is started by the kernel; init is given the process ID of 1. Init is the parent of all future processes within the Linux system. You can find the init executable in the /sbin directory. Opposite Linux startup is shut down. You cannot simply turn the power off to the computer. You must first bring Linux down from its running status. Linux is not alone in this requirement -other operating systems require proper shutdown before a system reset or power down. Linux uses memory buffers to store information about the file system and its state. This information is cached for performance reasons. Occasionally, Linux will flush the cached information out to disk. If you power the system down before Linux has flushed the data, the file system will be suspect and, in most instances, will be corrupted. This is why it is imperative that Linux is properly shut down. When your Linux system is starting up, you will see numerous messages displayed to the console - so many messages, in fact, that the screen is inevitably scrolled. There are times when you need to examine these messages. Constantly rebooting the system to try to catch any message(s) is not an option. So, how can you examine these messages after the system has started and you are logged on? Easy - you use the dmesg command. The dmesg command is used to examine the kernel ring buffer or, more specifically, for you to show the boot messages. In a pinch, you can invoke dmesg as in the following dialog: stimpy $ dmesg > booting.txt This will invoke dmesg and write its output to the file named booting.txt. The following is a sample dialog to examine boot messages. stimpy $ cat booting.txt Linux version 2.2.10 (root@Mandelbrot.suse.de) (gcc version 2.7.2.3) Detected 166196481 Hz processor. Console: colour VGA+ 80×25 Calibrating delay loop… 66.36 BogoMIPS Memory: 95456k/98304k available (1172k kernel code, 416k reserved (endbase 0×9e000), VFS: Diskquotas version dquot_6.4.0 initialized CPU: Intel Pentium 75 - 200 stepping 0c Checking 386/387 coupling… OK, FPU using exception 16 error reporting. page 368 #BREAK# Inside Linux Checking ‘hlt’ instruction… OK. Checking for popad bug… OK. Intel Pentium with F0 0F bug - workaround enabled. POSIX conformance testing by UNIFIX PCI: PCI BIOS revision 2.10 entry at 0xfc7c1 PCI: Using configuration type 1 PCI: Probing PCI hardware Linux NET4.0 for Linux 2.2 Based upon Swansea University Computer Society NET3.039 NET4: Unix domain sockets 1.0 for Linux NET4.0. NET4: Linux TCP/IP 1.0 for NET4.0 IP Protocols: ICMP, UDP, TCP, IGMP Initializing RT netlink socket Starting kswapd v 1.5 Detected PS/2 Mouse Port. pty: 256 Unix98 ptys configured Real Time Clock Driver v1.09 RAM disk driver initialized: 16 RAM disks of 20480K size PIIX: IDE controller on PCI bus 00 dev 38 PIIX: not 100% native mode: will probe irqs later PIIX: neither IDE port enabled (BIOS) PIIX: IDE controller on PCI bus 00 dev 39 PIIX: not 100% native mode: will probe irqs later ide1: BM-DMA at 0xffa8-0xffaf, BIOS settings: hdc:pio, hdd:pio hda: ST32140A, ATA DISK drive hdb: Maxtor 87000A8, ATA DISK drive hdc: DC5-E6, ATAPI CDROM drive ide0 at 0×1f0-0×1f7,0×3f6 on irq 14 ide1 at 0×170-0×177,0×376 on irq 15 hda: ST32140A, 2015MB w/128kB Cache, CHS=1023/64/63 hdb: Maxtor 87000A8, 6679MB w/256kB Cache, CHS=14475/15/63 hdc: ATAPI 6X CD-ROM drive, 256kB Cache Uniform CDROM driver Revision: 2.55 Floppy drive(s): fd0 is 1.44M … The contents of this file continue, as can be expected. Using the dmesg command can be quite useful for debugging a booting system. Usage for the dmesg command is as follows: dmesg [-c] [-n level] The -c switch is used to clear the contents of the ring buffer after printing the messages. The -n level switch is used to set the level of messages that are printed to the console. For example, -n 1 shows only panic messages. The init Process As mentioned previously, the init process is the parent of all processes within a running Linux system. The init process refers to its configuration file named /etc/inittab. The /etc/inittab file contains information that init uses to bring the system up into a specific run level. The following is a sample /etc/inittab file: # /etc/inittab # This is the main configuration file of /sbin/init # All scripts for runlevel changes are in /sbin/init.d/ and the main # file for changes is /etc/rc.config. # default runlevel id:2:initdefault: # check system on startup si:I:bootwait:/sbin/init.d/boot # /sbin/init.d/rc takes care of runlevel handling # # runlevel 0 is halt # runlevel S is single user # runlevel 1 is multiuser without network # runlevel 2 is multiuser with network # runlevel 3 is multiuser with network and xdm # runlevel 6 is reboot l0:0:wait:/sbin/init.d/rc 0 l1:1:wait:/sbin/init.d/rc 1 l2:2:wait:/sbin/init.d/rc 2 l3:3:wait:/sbin/init.d/rc 3 #l4:4:wait:/sbin/init.d/rc 4 #l5:5:wait:/sbin/init.d/rc 5 l6:6:wait:/sbin/init.d/rc 6 # what to do in single-user mode ls:S:wait:/sbin/init.d/rc S ~~:S:respawn:/sbin/sulogin # what to do when CTRL-ALT-DEL is pressed ca::ctrlaltdel:/sbin/shutdown -r -t 4 now # special keyboard request (Alt-UpArrow) # look into the kbd-0.90 docs for this kb::kbrequest:/bin/echo “Keyboard Request — edit /etc/inittab to let this work.” # what to do when power fails/returns page 369 #BREAK# Inside Linux pf::powerwait:/sbin/init.d/powerfail start pn::powerfailnow:/sbin/init.d/powerfail now #pn::powerfail:/sbin/init.d/powerfail now po::powerokwait:/sbin/init.d/powerfail stop # for ARGO UPS sh:12345:powerfail:/sbin/shutdown -h now THE POWER IS FAILING # getty-programs for the normal runlevels # :::
# The “id” field MUST be the same as the last # characters of the device (after “tty”). 1:123:respawn:/sbin/mingetty –noclear tty1 2:123:respawn:/sbin/mingetty tty2 3:123:respawn:/sbin/mingetty tty3 4:123:respawn:/sbin/mingetty tty4 5:123:respawn:/sbin/mingetty tty5 6:123:respawn:/sbin/mingetty tty6 # Note: Do not use tty7 in runlevel 3, this virtual line # is occupied by the program xdm. # # This is for the package xdmsc, after installing and # and configuration you should remove the comment character # from the following line: #7:2:respawn:+/sbin/init.d/rx tty7 # modem getty. # mo:23:respawn:/usr/sbin/mgetty -s 38400 modem # fax getty (hylafax) # mo:23:respawn:/usr/lib/fax/faxgetty /dev/modem # vbox (voice box) getty # I6:23:respawn:/usr/sbin/vboxgetty -d /dev/ttyI6 # I7:23:respawn:/usr/sbin/vboxgetty -d /dev/ttyI7 # end of /etc/inittab The scripts that are used to bring Linux into a specific run level are found in the /sbin/init.d directory. Note that some distributions of Linux locate the startup directories in the /etc/rc.d directory. For example, under SuSE Linux (6.2), the /etc/rc.d directory is a link to the /sbin/init.d directory. The following dialog confirms this: stimpy $ ls -al | grep rc.d lrwxrwxrwx 1 root root 14 Oct 13 13:09 rc.d -> ../sbin/init.d The following is a partial listing of the /sbin/init.d directory. drwxr-xr-x 2 root root 1024 Oct 13 13:09 rc0.d drwxr-xr-x 2 root root 1024 Oct 13 13:14 rc1.d drwxr-xr-x 2 root root 2048 Oct 13 13:17 rc2.d drwxr-xr-x 2 root root 2048 Oct 13 13:17 rc3.d drwxr-xr-x 2 root root 1024 Oct 13 13:09 rc4.d drwxr-xr-x 2 root root 1024 Oct 13 13:09 rc5.d drwxr-xr-x 2 root root 1024 Oct 13 13:09 rc6.d drwxr-xr-x 2 root root 1024 Oct 13 13:09 rcS.d Eight run levels are identified; the range of run levels is 0 6 inclusive. The eighth run level is known as “S” or “s.” Table 20.1 details the various run levels. Table 20.1. Summary of Run Levels Run Level Description 0 Halt. This level halts the system. The halt script, found in /sbin/init.d/rc0.d, is used to satisfy the halt functionality. The halt script may invoke the script halt.local found in the /sbin/init.d directory. This file is user editable so that you can include any special shutdown operations. 1 Single-user mode. This level is for single-user mode without a network. You can have more than one virtual console under this run level. 2 Multiuser, no NFS or X. This level sets multiuser mode with a network. This is primarily used for servers not running X. 3 Multiuser. This level sets multiuser mode with a network and runs xdm, the X Display Manager. Be sure you have set up X for this level. 4 Reserved, not used yet. 5 X11. 6 Reboot. This level reboots the system. The reboot script, found in /sbin/init.d/rc6.d, is used to satisfy reboot functionality. As in run level 0, the reboot script invokes the script halt.local found in the /sbin/init.d directory. This file is user editable so that you can include any special reboot operations. page 370 #BREAK# Inside Linux Run Level Description S, s Single-user mode. This level brings the system into single-user mode. The script single, found in the /sbin/init.d/rcS.d directory, is executed. Only one console is available in this run level. If you recall, the /sbin/init.d directory contains a directory that is associated with each run level. The format for the directory is /sbin/init.d/rc#.d, where the # is replaced with a run level. Thus, the directory named /sbin/init.d/rc3.d is dedicated to run level 3 script files. The following is a snippet of a directory listing for the /sbin/init.d/rc3.d directory. drwxr-xr-x 2 root root 2048 Oct 13 13:17 . drwxr-xr-x 11 root root 1024 Oct 13 13:17 .. lrwxrwxrwx 1 root root 6 Oct 13 13:09 K10xdm -> ../xdm lrwxrwxrwx 1 root root 7 Oct 13 13:09 K19cron -> ../cron lrwxrwxrwx 1 root root 7 Oct 13 13:09 K19nscd -> ../nscd lrwxrwxrwx 1 root root 8 Oct 13 13:17 K19smbfs -> ../smbfs lrwxrwxrwx 1 root root 9 Oct 13 13:16 K20apache -> ../apache lrwxrwxrwx 1 root root 11 Oct 13 13:17 S20sendmail -> ../sendmail lrwxrwxrwx 1 root root 6 Oct 13 13:17 S20smb -> ../smb lrwxrwxrwx 1 root root 8 Oct 13 13:17 S20squid -> ../squid lrwxrwxrwx 1 root root 7 Oct 13 13:09 S21cron -> ../cron lrwxrwxrwx 1 root root 7 Oct 13 13:09 S21nscd -> ../nscd lrwxrwxrwx 1 root root 8 Oct 13 13:17 S21smbfs -> ../smbfs lrwxrwxrwx 1 root root 6 Oct 13 13:09 S30xdm -> ../xdm lrwxrwxrwx 1 root root 5 Oct 13 13:09 K20at -> ../at lrwxrwxrwx 1 root root 8 Oct 13 13:09 K20inetd -> ../inetd lrwxrwxrwx 1 root root 6 Oct 13 13:16 K20lpd -> ../lpd lrwxrwxrwx 1 root root 8 Oct 13 13:09 K20rwhod -> ../rwhod lrwxrwxrwx 1 root root 11 Oct 13 13:17 K20sendmail -> ../sendmail lrwxrwxrwx 1 root root 6 Oct 13 13:17 K20smb -> ../smb Notice that the file names are coded in a special format. A script file begins with either the letter K or S. A script that begins with an S is used to start a service. A script that begins with a K is used to kill (or stop) a service. The number that is between the S or K and the filename is used for sequencing of the scripts. For example, for a service such as lpd running under a network, the sequence number should be greater than the sequence number for the network service. Conversely, the sequence number for shutting down a service, lpd for example, should be less than the sequence number for the network service. This ensures that the daemon service, lpd for example, is stopped before the network is brought down. You will also note from the previous directory listing that each file is actually a link to a file in the /sbin/init.d directory. You can manually restart a service, if required, by invoking the associated script to stop the service and then start the service. For example, to manually restart the apache service, you would do so as shown in the following dialog: stimpy $ /sbin/init.d/apache stop stimpy $ /sbin/init.d/apache start Some administrators invoke the “stop” a second time, before invoking the “start” line. Doing this provides some assurance that the service is indeed stopped. You will recall that the init process examines the /etc/inittab file upon invocation. The init process first looks for an entry matching initdefault -this entry specifies the default (or initial) run level of the system. The following is an extract from an /etc/inittab file, showing the initdefault entry: id:3:initdefault: It is quite possible that the initdefault entry does not exist, or worse yet, the /etc/inittab file is nonexistent. If either is the case, you must manually enter the run level at the console. The files rc.sysinit, rc, and rc.local are found in the /etc/rc.d directory. Each of these scripts is used for a specific purpose, such as during boot or for changing run levels. The rc.sysinit script is the first script that the init process executes. This script provides functionality such as checking the file systems and setting system variables. The rc script is used to bring the system into a run level or when changing run levels. The rc script accepts a single argument representing the run level desired. page 371 #BREAK# Inside Linux The rc.local script is run after all other startup scripts have been executed. This script is user editable, allowing you to add your own customizations for startup. The following shows a sample rc.local script file. stimpy $ cat rc.local #!/bin/sh # This script will execute after other init scripts. if [ -f /etc/redhat-release ]; then R=$(cat /etc/redhat-release) arch=$(uname -m) a=”a” case “_$arch” in _a*) a=”an”;; _i*) a=”an”;; esac echo “” > /etc/issue echo “$R” >> /etc/issue echo “Kernel $(uname -r) on $a $(uname -m)” >> /etc/issue cp -f /etc/issue /etc/issue.net echo >> /etc/issue fi For some distributions, such as SuSE Linux, the startup files are located in the /sbin/init.d directory. Additionally, the files (for this distribution) are named differently. The boot-level master script is named /sbin/init.d/boot and is comparable to the /etc/rc.d/rc.sysinit file. The /sbin/init.d/boot file also executes various hardware initialization scripts found in the /sbin/init.d/boot.d directory. Next, the /sbin/init.d/boot script file calls on the /sbin/init.d/boot.local file to execute local commands, similar to the /etc/rc.d/rc.local file. After system startup is complete, /sbin/init will switch to the default run level identified in /etc/inittab. Finally, it calls /sbin/init.d/rc to start or stop services (using scripts) under the /sbin/init.d directory. As mentioned previously, the initdefault entry in the /etc/inittab file identifies the default run level. In Table 20.1, the various run levels were detailed. Recall that run level 0 sets the system to halt and run level 6 sets the system to reboot. Do not change the initdefault entry to one of these two run levels. Obviously, you will never be able to use your system if initdefault is set to 0 or 6. Using LILO, the Linux Loader LILO, which is short for LInux LOader, is a boot manager that allows you to choose an operating system to start whenever you power up your computer. LILO is installed to and runs from your hard disk and is used to automatically boot your Linux system from a kernel image stored on the hard disk. LILO can be installed to the master boot record on the hard disk or to a floppy disk. Even if you install LILO to your hard disk, you should also install one to a floppy to act as an emergency disk in the event of hard-disk failure. LILO boots the default operating system defined in the /etc/lilo.conf file. After LILO is invoked, a timeout sequence is started; if this timer expires, the default operating system will be booted. You can manually override this feature by pressing the Shift key during the boot sequence. Alternatively, you can provide the prompt option in the /etc/lilo.conf file. If either method is employed, LILO will sit patiently until you select an operating system to boot. You select an operating system by typing its name, which could be msdos or, of course, linux. At the LILO prompt, you can touch the Tab key to bring up a list of available operating system that LILO can boot. Configuring LILO LILO is configured through its configuration file named lilo.conf, which is found in the /etc directory. As with other Linux configuration files, /etc/lilo.conf is a text file that can be modified in your favorite editor. Some of the information found in /etc/lilo.conf provides guidance to LILO for its operation. Other data in the file contains information specific to each operating system that LILO will boot. The following dialog shows a real-world sample of an /etc/lilo.conf file on a SuSE 6.2 system. stimpy $ more /etc/lilo.conf # LILO configuration file # begin LILO global Section boot=/dev/hda6 page 372 #BREAK# Inside Linux #compact # faster, but won’t work on all systems. vga = normal # force sane state read-only prompt timeout=20 # End LILO global Section # begin operating system specific section(s) image = /boot/vmlinuz root = /dev/hda6 label = SuSE stimpy $ As a point of contrast, the following is an /etc/lilo.conf for RedHat 6.0 on the same computer. stimpy $ more /mnt/redhat/etc/lilo.conf boot=/dev/hda5 map=/boot/map install=/boot/boot.b prompt timeout=50 # os specific image=/boot/vmlinuz-2.2.5-15 label=linux root=/dev/hda5 read-only other=/dev/hda1 label=dos table=/dev/hda stimpy $ The label line refers to the text that is displayed in the LILO boot menu list. This is the text identifier that you type to boot the associated operating system. As mentioned previously, the first few lines pertain to LILO’s general operation and the operating system specific entries follow. Notice in the previous /etc/lilo.conf examples that the boot entry identifies a logical partition where the Linux system is installed. If LILO were configured as the primary boot loader, the boot entry would be boot=/dev/hda. This particular machine uses System Commander as the primary boot manager. Based on the Linux operating system chosen, System Commander loads the appropriate LILO boot loader, which is installed on the (associated) Linux logical partition. A number of options to LILO are available. Table 20.2 shows the options. Table 20.2. Summary of Options to LILO Option Description backup=backup-file Copies the original boot sector to the named backup-file. boot=boot-device Sets the name of the device (or partition) containing the boot sector. If boot is omitted, the boot sector is read from the device mounted as root. change-rules Defines boot-time changes to partition-type numbers. compact Tries to merge read requests for adjacent sectors into a single read request. You should use this option when booting from a floppy disk. default=name Uses the named image as the default boot image. delay=tsecs Identifies the number of tenths of a second the boot loader waits before booting the default image. disk=device-name Defines nonstandard parameters for the specified disk. See the man page for more details. disktab=disktab-file Identifies the name for the disk parameter table. This option is not recommended. fix-table Allows LILO to adjust 3D addresses in partition tables. See the man page for more details. force-backup=backupfile Similar to the backup option, but will overwrite the backup copy. ignore-table Informs LILO to ignore any corrupt partition tables. install=boot-sector Installs the named file as the new boot sector. The /boot/boot.b file is the default if install is not used. page 373 #BREAK# Inside Linux Option Description linear Generates linear sector addresses instead of sector/head/cylinder addresses. See the man page for more information. lock Enables the automatic recording of boot command lines as default for the boot that follows. map=map-file Specifies the location of the map file. The file /boot/map is the default. message=message-file Identifies a file containing a message to be displayed before the boot prompt. nowarn Disables any warnings about eventual future problems. prompt Forces a boot prompt without requiring a keypress. restricted The per-image option restricted applies to all images. serial=parameters Enables control from a serial line. See the man page for more information. timeout=tsecs Sets a timeout, in tenths of a second, for keyboard input; if timeout occurs, the first image is automatically booted. verbose=level Enables progress messages. Higher numbers provide more verbose output. When your system boots with LILO as the boot manager, you will see a LILO O prompt. If you accepted the defaults during installation, you have a couple of options at the LILO prompt. You can let LILO time out and allow it to boot the default operating system, or you can type the name of the desired operating system at the LILO prompt to boot it. If you cannot remember the available choices, you can press the Tab key to obtain a list of available operating systems that LILO can boot. Using LOADLIN, another Linux Loader If you are running DOS in addition to Linux, you should consider using the LOADLIN boot loader. LOADLIN is a viable alternative to LILO because LOADLIN is easier to use. The nice thing about LOADLIN is that it does not require specialized installation. In addition, the Linux kernel images can exist on any DOS medium. You can even boot Linux from a CD-ROM without using a (floppy) boot disk. So, how does LOADLIN perform its magic? What LOADLIN does is execute the Linux kernel, completely replacing the DOS operating system that is currently executing. Be forewarned, however, you cannot exit Linux when you are done and return to DOS. You will have to reboot the system to get back to DOS. LOADLIN Requirements The requirements for LOADLIN are quite minimal. Obviously, you will need the DOS operating system. Optionally, you can be running Windows 95. At a minimum, your machine must be sporting an 80386 processor. You will also need a Linux kernel image, such zImage, bzImage, or /vmlinuz. Finally, you must have the LOADLIN package named LODLIN16.TGZ. This package contains various DOS-specific files, such as LOADLIN.EXE, MANUAL.TXT, TEST.PAR, PARAMS.DOC, and other files. The last two files, TEST.PAR and PARAMS.DOC, are sample parameter files. You can find a copy of LODLIN16.TGZ at the following URLs: ftp://ftp.cdrom.com/pub/linux/sunsite/system/boot/dualboot http://metalab.unc.edu/pub/Linux/system/boot/dualboot page 374 #BREAK# Inside Linux Easy LOADLIN Setup You should create a directory named LOADLIN on the C: drive (let us assume C: drive for the sample). Copy the LODLIN16.TGZ file into the directory and use a decompression (unzipper) utility to extract the contents. The following dialog shows the files that were extracted onto my system: C:LOADLIN> dir /S /X Directory of C:LOADLIN 12/29/99 10:22a

. 12/29/99 10:22a .. 12/29/99 10:22a 87,210 lodlin16.tgz 04/30/96 06:30p 2,830 readme.1st 04/30/96 05:44p 32,208 loadlin.exe 03/22/94 03:29a 18,324 copying 04/30/96 03:51p 2,420 test.par 05/16/94 08:31a 220 linux.bat 03/18/96 02:16a 1,376 initrd.tgz 05/04/96 08:14a 327 files 12/29/99 10:24a doc 12/29/99 10:24a src Directory of C:LOADLINdoc 12/29/99 10:24a . 12/29/99 10:24a .. 03/31/96 06:34p 7,241 announce.txt 04/30/96 04:01p 8,508 changes 04/30/96 07:15p 32,719 manual.txt 05/04/96 08:31a 1,303 lodlin16.lsm 04/30/96 06:28p 1,808 quicksta.rt 04/30/96 06:53p 12,511 params.doc 04/30/96 08:23a 12,004 initrd.txt Directory of C:LOADLINsrc 12/29/99 10:24a . 12/29/99 10:24a .. 04/28/96 03:13p 59,643 loadlin.asm 04/28/96 10:23a 140 loadlina.asm 04/28/96 03:17p 28,025 loadlini.asm 04/28/96 05:25p 35,983 loadlinj.asm 03/30/96 05:41p 23,528 loadlinm.asm 04/30/96 09:16a 860 makefile 03/16/96 06:28p 3,721 pgadjust.asm 04/30/96 07:49a 4,020 srclinux.tgz C:LOADLIN> I suggest that you read the various text and documentation files so that you get the latest and greatest information. After unzipping the LODLIN16.TGZ file, you are almost ready to fly. Next, copy the image file (zImage, bzImage, or /vmlinuz) to the root DOS partition, such as C:. That is really all there is to it. Booting Linux Using LOADLIN This is the easy part. The following dialog demonstrates the use of LOADLIN to boot Linux (for most installations): C:> cd LOADLIN C:LOADLIN> loadlin c:vmlinuz root=/dev/hdb2 ro If you have many parameters that span beyond the DOS limit of a 128-byte DOS command line, you can use a parameter file, as demonstrated in the following dialog. The Linux partition specified in the previous dialog is /dev/hdb2 -this is only for demonstration purposes. Be sure to specify the Linux partition that exists on your system. C:> cd LOADLIN C:LOADLIN> loadlin @param.fil Check out the TEST.PAR file found in the C:LOADLIN directory; it is a sample parameter file. Also, check out the PARAMS.DOC file in the C:LOADLINDOC directory. It contains a list of Linux parameters. You might also check out the parameters list found at the following URL: http://sunsite.unc.edu/mdw/HOWTO/BootPrompt-HOWTO.html page 375 #BREAK# Inside Linux In a pinch, you can get help from the LOADLIN executable by typing its name alone on the DOS command line, as shown in the following dialog: C:LOADLIN> loadlin LOADLIN v1.6 (C) 1994..1996 Hans Lermen USAGE: LOADLIN @params LOADLIN [zimage_file] [options] [boot_params] without any params, LOADLIN displays this help message. @params: params is a DOS file containing all other options zimage_file: DOS file name of compressed Linux kernel image options: -v verbose, show information on params and configuration -t test mode, do all but starting Linux, also sets -v -d file debug mode, same as -t, but duplicates output to “file” -clone ( Please read MANUAL.TXT before using this switch! ) -n no translation for root=/dev/… -txmode switch to textmode 80×25 on startup -noheap disable use of setup heap -wait=nn after loading wait nn (DOS)ticks before booting Linux -dskreset after loading reset all disks before booting Linux boot_params: root=xxx filesystem to be mounted by Linux as “/” (string passed unchanged to the kernel) xxx = hex number (e.g. root=201 for /dev/fd1) = /dev/mmmn (e.g. root=/dev/hda2) mmm = fd,hda,hdb,sda,sdb… n = 1..10.. decimal ro mount “/” readonly rw mount “/” read/write initrd=x (for kernels > 1.3.72) load file x into /dev/ram. If FS in x contains /linuxrc, execute it, and then remount to root=xxx. If root=/dev/ram, just load, bypass execution of /linuxrc for more boot params see PARAMS.TXT or Paul Gortmakers HOWTO: http://sunsite.unc.edu/mdw/HOWTO/BootPrompt-HOWTO.html http://rsphy1.anu.edu/~gpg109/BootPrompt-HOWTO.html …etc… To simplify the booting process, you should create a DOS batch file to execute any processes required. You can find a sample batch file named LINUX.BAT in the C:LOADLIN directory. You can also use the CONFIG.SYS file to boot multiple configurations if you are using DOS 6.0 or later. Be sure to check the LOADLIN documentation for more details on how to do this. Emergency Boot Floppy Disks Almost all Linux distributions, during installation, will prompt you to create an emergency boot floppy. I highly recommend that you do this because there are times when Linux may not boot. Be forewarned, though: These boot floppies only contain the Linux kernel -just enough to get the system booted up. After the system is up, you will have to use the distribution’s disks, such as CD-ROMs, to repair any damage. If you are using LILO as the boot manager and it becomes unusable because of a failed configuration, booting from the hard disk may not be an option. To handle this type of situation, you will also need a root floppy disk. Be sure to update these emergency floppy disks whenever your Linux system changes -specifically, changes to the kernel. Summary In this chapter, we covered Linux bootstrapping. You discovered that the dmesg command can be used to examine the boot messages. The init process, the parent of all processes, was covered in detail. The /etc/inittab file was discussed and an example provided. The scripts used to bring Linux to a specific run level were also discussed. Next, a discussion of the available run levels was covered. In addition, the run-level scripts were discussed. page 376 #BREAK# Inside Linux The Linux Loader (LILO) was covered, including coverage of /etc/lilo.conf, the LILO configuration file. You learned that LILO can, in addition to booting a Linux system, boot other operating systems living on the same machine. Additionally, the available options to LILO were presented. The Load Linux (LOADLIN) DOS boot utility was discussed. LOADLIN is a great option for booting Linux from the DOS command line. Setting up LOADLIN for use is a very simple process: Download LODLIN16.TGZ into a DOS directory, unzip it, and you are ready to go. Finally, we closed the chapter with a discussion about building Linux emergency boot disks. This is important because there may be a time when you will be unable to boot your Linux system from the hard drive. page 377 #BREAK# Inside Linux Chapter 21. Security Obviously, in this day and age, security is a major concern among system administrators. We can take this a step further and say that security is a concern among all users. You need to consider many things when approaching security. This chapter explains tactics and measures you can use to reduce security risks and concerns. Overview Surprisingly enough, some system administrators are rather lazy when it comes to security. A general “no problems here” attitude exists among some system administrators. I believe the problem boils down to one of two thoughts: Some system administrators think their system is secure enough, and some just do not know what the potential threats are. Many security features are disabled or not initially installed, by default, when users install a Linux distribution. Some distributions of Linux attempt to address this by offering a “server install” option during the installation process. The vendor may also offer other versions of its base product, such as a secure server edition. I want to be rather bold and tell you that your system cannot be crack-free. The crack I am talking about here is synonymous with system break-in. All systems are susceptible to break-in by crackers. As a matter of fact, it is my opinion that every system has been cracked at one time or another. Believe it or not, some systems are cracked on a weekly basis! Probably the only system that has not been cracked is the standalone home PC that has never made an outside (network) connection and that is used by only one person. Intruders There is a difference between a cracker and a hacker. The intent of a cracker is to break in to a system. Secondary to that is whether the cracking is malicious in nature. It is true that after the cracker gets in to a system, the course of events usually leads to destruction of data or the collection of corporate data. But not all crackers intend to be malicious; a lot of crackers are interested only in the challenge of a break in. A hacker, on the other hand, is someone who has an extreme interest in computers. The interest may be broad or focused. For example, for a programming hacker, the focus might be in deep technical knowledge about the Java or C++ programming language. In this extreme case, the programmer may dig deep into the mechanics of the language and may even become intimate with the compilers, linkers, and other tools. A hacker has no interest in breaking in to systems, and malicious actions are not a part of the hacker’s regimen. The hacker with broad computer interest just wants to know everything about computers - from details about hardware to operating systems to software. You should establish sound security policies within your organization. When they are in place, you should enforce those policies. You can find a Request For Comment (RFC) at http://www.rfceditor. org that defines a fairly comprehensive security policy Search for RFC2196. RFC1244 is a good example of a network security policy. You should also check out RFC1281, which is a sample security policy with descriptions for each step. Most crackers fall into one of several categories. Although the following list is not comprehensive, it does provide some of the major categories. The Celebrity. This intruder wants “celebrity” fame among his or her peers and will break into your system as an advertising technique. The more visible your site, the more likely this person is to try to break in. Investigative. This group is more curious than anything else. This could be someone who just wants to see what “breaking in” is all about. This person might also be curious about what is on your system. page 378 #BREAK# Inside Linux Espionage. This is a rather broad category, consisting of corporate espionage, competitive espionage, or what is known as data marketing. For the corporate type, the intent is to discover what the “other guy” is up to with respect to products and/or services. The same holds true for the competitive espionage type, but on a much smaller scale. This one usually involves gaming companies. For the data marketer, the intent is to extract useful data that can be sold on the open (or closed) market. The intent here is for financial gain. Leeches. These people actually have the nerve to use your machines’ resources. It is amazing how much this happens. One or more groups might be using your system(s) as a chat site, as an FTP site, for mass storage, as a pornography site, and so on. Malicious. This person has only one thing in mind, and that is to cause some type of damage. This cracker might bring your system(s) down, damage data, or modify files on your Internet site. Piggyback. If your system is connected to other hosts on the network, this category of cracker will use your system to gain access to the other hosts. Let’s move forward and see what it takes to secure your Linux system. Always remember - prevention is your best friend. Physical Security No, I am not talking about some big, hefty security guard here, although a security guard is a form of physical security. When we think of security, we usually think of viruses, worms, crackers breaking into a system, and other such computer system torment. However, I am talking about the physical surroundings and physical influences that impact our system(s). A computer system is susceptible to its environment. Another aspect of physical security is ensuring that your systems are habitually backed up. Surprisingly enough, I visit many client sites only to discover that system backup is viewed as a nuisance rather than as a positive effort. Natural Elements Dust plays a big part in the destruction of our computer equipment. Have you ever opened up the case on a computer that has been sealed up for months? Remember how those dust rodents scurried about when you took the case off? I am not talking about a real rodent, of course, but I am referring to the amount of dust that can accumulate in a computer (and peripherals). Other computer equipment is vulnerable to attack by dust, not just the computer. Printers need occasional attention to remove dust from their internals. External modems and keyboards require “dust maintenance,” too. Personally, I clean my keyboard and computer once every two months. I remove the keys (keyboard) and clean all the garbage out and then blow all the dust out of the computer. Electricity is another physical threat to computer equipment. The real problem here is electrical surges. Most computer equipment is delicate when it comes to electrical surges; modems are notorious for electrical surge damage. You should ensure that all your computer equipment is receiving power through a surge protector. Although an inexpensive surge protector will provide some relief, you should invest in a high-end surge protector with battery backup. You should also ensure that your telephone and answering machine are attached to a surge protector because these items can receive damage. Smoke and fire are both threats to computer systems. Be sure you have fire-fighting equipment that is easily accessed. Your safety and that of the people around you is the primary concern here; the computer equipment is secondary. Be sure to install smoke and fire detectors, alarms, and automatic extinguishers, if available. page 379 #BREAK# Inside Linux Physical Elements Let’s get back to the security guard subject. We really need to touch on this subject because it relates to theft and malicious damage (disgruntled employees). Small computer equipment is easily concealed, such as modems (external and internal), hardware cards, laptops, and some keyboards. Digital cameras are becoming commonplace in the computer-savvy office. Keep these sometimes-used items under lock and key. Theft is an issue that must be dealt with. Physical access to your equipment should be a concern, too. You do not want unauthorized people accessing your computer room or browsing through office space. Crackers are known for watching people log in to a system, or they pick up sticky notes that have login instructions on them. BIOS Locks Many of today’s personal computers provide password facilities in the BIOS. Most allow you to set a boot password and a BIOS setup password. The boot password is used when you turn the computer’s power on. After the power on self test (POST), the computer prompts you for the boot password; this happens before booting any operating system or boot manager software. You are usually given three chances to enter the correct password, and then the computer locks up or reboots. You set the boot password in the BIOS setup. The BIOS setup password is required when you enter into the BIOS setup after powering up the computer. You cannot modify any BIOS settings until you supply the setup password. This password is separate from the boot password. A BIOS setup password is a good administrative tool; it keeps your users from altering the BIOS settings. You should engage the BIOS password for all machines in your organization. These BIOS locks are not foolproof. Anyone with knowledge of computers can disable (or reset) the boot and BIOS setup passwords. To reset or disable these passwords requires physical access to the motherboard, so you should provide some sort of physical computer lock. Computer locks are discussed in the next section. Computer Locks Many of today’s computers come with a physical locking mechanism. Some machines have an integrated lock, requiring a key to lock and unlock the case. These case locks are good for keeping a thief from opening up the case and stealing network cards, video cards, and other internal hardware. The case locks also keep people from opening the case to disable or reset the BIOS and boot passwords. Most machines allow you to disable or reset the passwords by moving a jumper to the “disable” position. With some machines, you can reset the password by removing wall power and momentarily removing the internal battery. The battery is designed to maintain BIOS settings while a machine is unplugged from the power source. Some machines provide loop-lock mechanisms. You simply purchase a key or a combination lock and attach the lock through the loops. For more expensive machines, you can run a cable through the case loops and anchor the cable to the wall or floor. This helps prevent the unauthorized removal of the machine. System Backup As mentioned previously, some organizations view system backup as an annoyance. It seems that a backup occurs only when someone with authority asks, “When was the last backup performed?” Delaying backups should never happen. Backups are even more crucial if you are running a business. If you are the system administrator of your single PC home system, a backup is not as critical. Do not misunderstand me -I am not saying that you should not back up your home machine on a regular basis. If you are the system administrator for a 24/7 organization of 1,000 employees who rely on their computers, then you had better be backing up the systems daily. If you are responsible only for your home box, a weekly or monthly backup is sufficient. page 380 #BREAK# Inside Linux Believe it or not, some system administrators have been relieved of their employment because of failure to perform periodic backups. I have witnessed companies go into total panic because of invalid or missed backups. A case in point -a telecommunications company was having problems with its database system. So severe was the problem that the database vendor sent its top technicians to find and fix the problem. In the meantime, the vendor recommended that the client re-create the databases and restore the data from their most recent backups. The telecommunications company had already lost two days worth of critical data. Guess what? The system administrator discovered that the most current and valid backup was more than 20 days old! The lesson here is that not only do you have to perform backups, but you should ensure that those backups are valid. The telecommunications company lost critical accounting and call-routing data. Backups are not useful only for recovering from the effects of malicious conduct. As mentioned previously, the database failed, which prompted a restore of data. This shows that poorly written software can wreak havoc on a disk’s data, too. Hardware can also be at fault. Hard drives are electromechanical devices that are susceptible to failure at some point in time. You should not rely on the failure statistics presented by disk manufacturers. You must be prepared for failure at any time. If you are diligent with hard-drive maintenance and backups, you reduce the risk of failure and increase your chances of recovery. Surprisingly, I had a hard drive that lasted eight long years on a machine being used as a file and application server! A complete discussion of backup routines is beyond the scope of this section. A universally accepted schedule is the six-tape cycle. This is both easy to implement and practical. Four of the tapes are used for days Monday through Thursday. One tape is earmarked for “even” Fridays and the sixth tape is dedicated for “odd” Fridays. For the Monday-to-Thursday routine, you perform an incremental backup; this implies that only changed data (files) are backed up. Each Friday, you perform a complete backup of all hard-disk data. The ultimate backup routine is to modify the six-tape routine to include the whole month. If you are responsible for a 24/7 operation, this expense is minimal. If you have a four-week month, you will require 20 tapes. The daily incremental backups are performed as usual, in addition to the Friday full backup. The difference is that you stow those tapes (Monday Friday) away - preferably in a safe - and start with fresh tapes beginning on Monday. This method enables you to go back a full month if you need to. You should refer to the section “System Backup and Restoration” in Chapter 23, “Other Administrative Tasks,” for more information concerning system backup. Decreasing the Risk Some tips to decrease the chance of physical security violations are as follows: Revealing paperwork. A policy should be in place that disallows the display (or storage) of sticky notes or other note paper with login information. Instructions concerning login procedures should also be stowed away in a desk. Some people are notorious for pasting sticky notes to their monitors with their usernames and passwords! Unattended hardware. Do not leave computer equipment unattended. This is particularly true of smaller items, such as disk drives, modems, digital cameras, backup tapes and drives, and so on. You might as well include software, too. Unattended terminals. Do not log in to a system and then run off to lunch, especially if that session is the root user. This allows any user to wreak havoc on your system. You should set up your system so that the terminal automatically logs off after a specified period of idle time (or use a screen lock or screen saver). User education. This one is very important because it helps to ensure that the previous three items are understood and, hopefully, enforced. page 381 #BREAK# Inside Linux What is important is to establish sound security policies, to publish those policies, and to enforce those policies. Threats to Security Caused by Social Engineering Now there is a fancy phrase! What is social engineering? In a nutshell, it is the ability of a person to negotiate something from another person. People use many tactics to do this, from misrepresentation to persuasion. Social engineering involves the use and abuse of people and their waste - waste being paper garbage and the like. A typical example is a cracker that befriends the system administrator of a large system. The cracker spends time discovering personal things about the administrator. Why? Because people usually create passwords that are personal in nature, such as their dog’s name or the type of car they own. So the cracker learns these things to help gain access to the system. Crackers are also known to rummage through office trash, either in the office or in the outside dumpster. I knew someone who once obtained a 200-page list of usernames and passwords! Apparently, the system administrator printed the list to weed out dead accounts and she simply threw the list away in the public receptacle. Crackers also exercise their social engineering skills by “visitation methods.” A prime example is a cracker that visits a company to apply for a position. The cracker, of course, has no intention of accepting the job. Rather, she is there to take a tour of the facility to discover any system access hints that might be lying around. Anything will do - sticky notes, printouts, and even watching people log in to the system. This method is quite popular because the candidate is expected to be interested in the office surroundings, so the interviewer never thinks twice about the inquisitiveness of the candidate. Other visitation methods are taking a tour, engaging the company as a potential client, or visiting friends or relatives. A cracker might pretend to be the system administrator and call upon some poor unsuspecting user. During the conversation, he asks the person for his or her username and password so that he can “fix” the damaged password file (/etc/passwd). What can you do to prevent such social engineering occurrences from happening? As mentioned previously, educate your users. Explain what social engineering is all about and how they can prevent it from happening. You might even run some practice sessions to see if you can get past your users. Authentication This section covers the most typical approaches taken to secure Linux systems. I discuss weak passwords and what you can do to alleviate the problem. Also, account types are addressed, such as command and dead accounts. Last, I address encryption as a security measure and describe some of the products available. Passwords Weak passwords, weak passwords, weak passwords, weak passwords… It cannot be said enough: An easy way to breach a computer system is through weak passwords. Some crackers can just sit down at a terminal and guess at passwords, especially if they have employed their social-engineering skills. Some crackers also employ the use of password-cracking software, which automates the task of breaking into a system. There exists a list of the top 100 passwords used by people. You might be surprised to learn that system administrators consistently use the password “GOD.” Why? Because these system administrators might believe that they are the “GOD” of the system. The best defense for weak passwords is to employ a number of policies concerning passwords. First, you should enforce the concept of password reset at regular intervals. Common practice states that you should enforce a change of password every eight weeks. This requires each user to change his or her password at regular intervals. Another policy is to enforce the use of multiple-word passwords. Some examples are hungryBear, goHome, flatTire, and so on. Have your users create their passwords in mixed-case text. Remember, passwords are case sensitive. And better yet, have your users inject a number or two in the password. page 382 #BREAK# Inside Linux Some good password samples are coffee8Tea, half9Half, book4Shelf, phone3Book, fast4Track, and so on. The best passwords are not words at all. As mentioned previously, most crackers use software to automate system cracking. These programs use the dictionary to draw out passwords. The program also concatenates words to use as passwords. Therefore, the stronger passwords consists of random words, numbers, and symbols. The man page for the passwd command states that you can use lowercase alphabetic, uppercase alphabetic, the digits 0 through 9, and punctuation marks. The acronym approach to creating a password should be employed, rather than using common words out of the dictionary. It is really easy; just think of some easy-to-remember phrase or song lyric and create an acronym for it. For example, “it is raining cats and dogs” becomes iirc&d. You could throw in a number to toughen up the password, such as i9irc&d. Just be sure you choose a phrase that you will remember. The CERN Security Handbook provides a wealth of security information at the following URL: http://consult.cern.ch/writeup/security/main.html and more specifically (for passwords) at http://consult.cern.ch/writeup/security/security_3.html. Shadow Passwords The /etc/passwd file serves several purposes. The file is used to store users of the system. Specifically, it stores a username and an encrypted password for each user on the system. A problem with this method is that the encrypted password is available to prying eyes. This is because the /etc/passwd file contains other user information, such as user and group IDs. This means that the /etc/passwd file must be readable by the world. All a user needs to do is utilize a password-cracking program to determine the real password. Shadow passwords provide a means to reduce the risk of password cracking. Shadow passwords are stored in the /etc/shadow file. Only privileged users can read the /etc/shadow file; usually only the root user is allowed to examine and modify the /etc/shadow file. You must ensure that your system supports shadow passwords because some utilities expect the encrypted passwords to be in the /etc/passwd file. The following shows four entries in the /etc/passwd file. root:x:0:0:root:/root:/bin/bash lp:x:4:7:lp daemon:/var/spool/lpd:/bin/bash news:x:9:13:News system:/etc/news:/bin/bash uucp:x:10:14::/var/lib/uucp/taylor_config:/bin/bash Notice that the second field, the password field, contains only the letter x. The password is actually stored in the /etc/shadow file. The following snippet shows the associated entries for the /etc/passwd file. root:j9fd.Np9bUTk:10968:0:10000:::: lp:*:9473:0:10000:::: news:*:8902:0:10000:::: uucp:*:0:0:10000:::: The last three entries do not have encrypted passwords associated with the usernames lp, news, and uucp. Several commands are used to add, delete, modify, and verify users and shadow passwords. The useradd command is used to add a new user to the system. The userdel command is used to delete an existing user from the system. The command usermod is used to modify an existing user account. The passwd command is used to change the password for a user. Finally, the pwck command is used to validate the consistency of the /etc/passwd and /etc/shadow files. Be sure to check Chapter 22, “Managing Accounts,” for more information on these commands. Accounts Numerous types of accounts can figure in your security plan. They are reviewed in the following sections. Command Accounts Some administrators utilize the facilities of command accounts. Quite simply, if you log in using one of these accounts, an associated command is executed and the account is then logged out automatically. page 383 #BREAK# Inside Linux A well-known account is the finger account. If you log in using finger, the associated command, finger, is executed and then the log in session is closed. Most distributions of Linux no longer implement this account - or other command accounts, for that matter. Their popularity has dwindled because of the security risks they pose. Command accounts provide crackers with signatures, or identifying information, about a system site. Also, these commands have well-exposed flaws that can be exploited by crackers. Yet, it is good to know about this risk. Check your system to be sure these accounts are disabled or password enabled. Dead Accounts A dead account is one that is no longer valid. This could be for many reasons, such as an employee that is no longer employed or on an extended leave of absence. The optimal solution, of course, is to completely remove the account. The other solution is to disable the account, as discussed in the previous section. To disable the account, place a * character in the password (second) field of the /etc/passwd file. If your system uses shadow passwords, place the * character in the second field of the /etc/shadow file. If you decide to remove an account, you should use the userdel command. This command is used to delete a user account and its related files. If you do not use this command, you will have to manually remove all the files and directories associated with the account. Simply execute the command as shown in the following example: userdel [-r] accountName The command modifies the system account files, removing the entries that refer to accountName. The named account must exist. If the -r option is specified, files in the account’s home directory will be removed along with the home directory itself. You will have to seek out files located in other file system(s) and delete them manually. Default Accounts During the install process, Linux creates a number of default accounts that are required for Linux to operate properly. In most distributions, many of these accounts are disabled. This is done by placing a * character in the password field of the /etc/passwd file or the /etc/shadow file if shadow passwords are employed. You should be aware that some software packages create special accounts. If any of these accounts are not disabled, you should ensure that each account has a valid and strong password attached to it. Guest Accounts A guest account is used in cases where guests are required to use the system. This relieves the system administrator from having to create an account and then remove it when the guest departs. The problem is - what if a cracker discovers that your system uses guest accounts? Half the battle of cracking a system is knowing a valid account (user) name. Typically, the password associated with the guest account is going to be something such as guest or password or temp. Do not fall prey to this absurdity. If you are utilizing the guest account on your system, be sure that a strong password is associated with it, and change it periodically. You can also disable the account when there are no visitors. You can also employ password aging to alleviate security risks that guest accounts present. Password aging is discussed in the earlier section “Passwords.” Password-Free Accounts I will tell you straight up - do not allow password-free accounts. This is just too easy for crackers and their software. You should not allow a password-free account. You can disable an account by placing a * in the password field of the /etc/passwd file (or the /etc/shadow file if shadow passwords are used). This will disallow anyone from logging in to the system. page 384 #BREAK# Inside Linux The following is a snippet from an /etc/passwd file: root:x:0:0:root:/root:/bin/bash lp:x:4:7:lp daemon:/var/spool/lpd:/bin/bash news:x:9:13:News system:/etc/news:/bin/bash uucp:x:10:14::/var/lib/uucp/taylor_config:/bin/bash The password field is the second field of an entry. Each line constitutes a user on the system. If your system implements shadow passwords, the entry will be found in the /etc/shadow file. The following is a snippet that is associated with the previous /etc/passwd file snippet: root:j9fd.Np9bUTk:10968:0:10000:::: lp:*:9473:0:10000:::: news:*:8902:0:10000:::: uucp:*:0:0:10000:::: Notice that the root account has an associated password, whereas the other three accounts (lp, news, and uucp) are disabled. Encryption Encryption provides another level of security. Kerberos authentication, the first form of encryption discussed next, provides a strong form of security. Kerberos Authentication Developed at MIT in the mid 1980s, Kerberos is used as a distributed authentication service. Kerberos authenticates a user when the user logs in to the system. If a host or server on the network requires authentication, Kerberos provides a method to prove the user’s identity. With Kerberos, a client process runs on behalf of a user. This process is used to prove the user’s identity. Kerberos does this without sending data on the network, thus precluding an attacker from obtaining a password or authentication packet. Kerberos implements authentication by assigning a unique key to the network user. This unique key is called a ticket. The ticket is subsequently embedded in network messages to authenticate the sender. Spoofing has always been a network security concern. Spoofing is the act of a client fooling a server into thinking the client is someone else. Kerberos helps in this regard by preventing users from spoofing the system. You can find more information on Kerberos at http://web.mit.edu/kerberos/www. Pluggable Authentication Modules (PAM) The most basic method of authentication and authorization to use in a system is a username and password scheme. At a log in prompt, you enter your username; then you are challenged to verify who you are by providing a password. If a match is made, the system authorizes your access into the system. At that point, your environment is adjusted to reflect your level of authorization at the point of authentication. Pluggable Authentication Modules (PAM) is a system implemented as a suite of shared libraries enabling the system administrator to elect how applications perform user authentication. PAM allows you to alter the methods of authentication at will and it offers this functionality as loadable modules. Thus, you can switch the authentication mechanism without rewriting and recompiling a PAM application. This implies that you can completely modify your authentication system without modifying your PAM applications. The following lists some highlights of PAM: You can identify particular users as able to log in to the system during a range of hours. You can set resource limits (amount of memory, maximum processes, and so on) for users, thereby disallowing denial-of-service attacks. A denial-of-service attack is when the attacker tries to make a resource too busy so that it cannot answer legitimate network requests or tries to deny legitimate users access to your machine. You can use password encryption methods other than DES. You can enable shadow passwords at will. page 385 #BREAK# Inside Linux The PAM library is locally configured with a combination of files in the /etc/pam.d directory. The dynamically loadable modules are usually located in the /usr/lib/security directory. Older versions of Linux configure PAM using the /etc/pam.conf file. The following is a listing of the /etc/pam.d directory under SuSE 6.3; other distributions of Linux may locate the files in another directory tree. bash-2.03# ls -al total 21 drwxr-xr-x 2 root root 1024 Jan 8 18:33 . drwxr-xr-x 28 root root 3072 Jan 18 23:57 .. -rw-r–r–1 root root 230 Nov 8 15:40 chfn -rw-r–r–1 root root 230 Nov 8 15:40 chsh -rw-r–r–1 root root 580 Nov 8 14:30 ftpd -rw-r–r–1 root root 437 Nov 8 23:54 gdm -rw-r–r–1 root root 500 Nov 8 15:40 login -rw-r–r–1 root root 443 Nov 6 09:49 other -rw-r–r–1 root root 230 Nov 8 15:40 passwd -rw-r–r–1 root root 311 Nov 8 16:52 ppp -rw-r–r–1 root root 263 Nov 8 14:30 rexec -rw-r–r–1 root root 454 Nov 8 14:30 rlogin -rw-r–r–1 root root 292 Nov 8 14:30 rsh -rw-r–r–1 root root 317 Nov 8 14:35 su -rw-r–r–1 root root 108 Nov 8 17:05 su1 -rw-r–r–1 root root 60 Nov 8 17:06 sudo -rw-r–r–1 root root 265 Nov 6 08:57 xdm -rw-r–r–1 root root 67 Nov 8 17:53 xlock -rw-r–r–1 root root 67 Nov 8 17:59 xscreensaver bash-2.03# The following list shows the contents of the /etc/pam.d/passwd file, taken from the list shown previously. #%PAM-1.0 auth required /lib/security/pam_unix.so nullok account required /lib/security/pam_unix.so password required /lib/security/pam_unix.so strict=false session required /lib/security/pam_unix.so The syntax of each file in the /etc/pam.d directory is made up of individual lines taking the following form: module-type control-flag module-path arguments The module-type can be one of four types: auth, account, session, and password. The control-flag tells the PAM library how to react to the success or failure of the associated module. The module-path is the path of the dynamically loadable object file or the pluggable module itself. The args is a token list that is passed to the module. A good site for PAM can be found at http://www.kernel.org/pub/linux/libs/pam/Linux-PAMhtml/ pam.html. File Security The filesystem employed by Linux is a hierarchical one, consisting of a tree of directories and files that are contained within those directories. Linux maintains information about each directory and file within the system. The following list shows some of the attributes of a file. Filename Protection (access permissions) Number of hard links User ID of owner Group ID of owner Total size, in bytes Time of last access Time of last modification Time of last change This can open up a host of problems within a Linux system. One of the most important aspects of file security relates to access permissions. You should pay close attention to how your system implements file security and be certain to employ it properly. page 386 #BREAK# Inside Linux The file permission settings control who has access to a file, but they go beyond that. The permissions also state what those users can do to the file. The following dialog demonstrates the use of the ls command. bash-2.03# ls -l total 9094 -rwxr–r–1 root root 33869 Oct 22 17:09 SuSEconfig -rwxr-xr-x 1 root root 3670780 Nov 9 08:56 YaST -rwxr-x—1 root root 17159 Nov 9 03:31 actctrl -rwxr-xr-x 1 root root 4756 Nov 8 18:28 activate -rwxr-xr-x 1 root root 14004 Nov 8 17:23 agetty -rwxr-xr-x 1 root root 31704 Nov 8 14:17 arp -rwxr-x—1 root root 21951 Nov 9 03:31 avmcapictrl -rwxr-xr-x 1 root root 9708 Nov 8 18:28 badblocks -rwxr–r–1 root root 3185 Apr 30 1999 bootp -rwxr-xr-x 1 root root 14520 Nov 8 14:33 bootpc -rwsr-xr-x 1 root root 22377 Nov 9 09:07 cardctl -rwxr-xr-x 1 root root 51848 Nov 9 09:07 cardmgr -rwxr-xr-x 1 root root 50456 Nov 8 17:23 cfdisk -rwxr-xr-x 1 root root 17668 Nov 9 10:46 checkproc -rwxr-xr-x 1 root root 67304 Nov 8 13:52 ckraid lrwxrwxrwx 1 root root 7 Jan 8 11:29 clock -> hwclock drwxr-xr-x 2 root root 1024 Jan 8 11:51 conf.d -rwxr-xr-x 1 root root 4308 Nov 8 17:23 ctrlaltdel -rwxr-xr-x 1 root root 86192 Nov 8 18:28 debugfs -rwxr-xr-x 1 root root 39608 Nov 8 13:41 depmod bash-2.03# The leftmost column shows us the file’s type and its permissions. The first character, -, designates a normal file. If this character is the letter d, the file type is a directory. The letter l designates the file type to a link. The remaining nine characters in the first column designate the access permissions for the file’s owner, group, and “world.” Each of the three classifications has three settings: r for read permission, w for write permission, and x for execute permission. If the letter is present, the permission is considered on; otherwise, it is off and is visually represented by the -character. Consider the entry debugfs from the previous list. The entire permission setting for debugfs is rwxr-xrx, which yields rwx for the owner, r-x for the group, and r-x for the world. The rwx for the owner states that the owner root can read and write the file and execute it. The r-x for the root group states that the group can read the file and execute it. The permissions for the group are also applicable to the world (everyone else); that is, the rest of the world can read the file and execute it. Network Access Local area networks (LANs) provide for an easy portal into a system. Most system administrators feel secure about their LANs with respect to system security, but do not be fooled. The LAN provides an easy entry point into an otherwise secure system. All that is required is a machine with weak security to provide a penetration point for a cracker. If the security for just one machine on a LAN is weak, all systems on that LAN can be compromised. You should require that all machines on a LAN be challenged for authentication. The machine name and username should both be authenticated. A trusted host allows a machine to connect to a host with a minimum of hassle. Usually, the names of the machines that are trusted can be found in the /etc/hosts, /etc/hosts.equiv, and any .rhosts files. Traditionally, passwords are not required for a trusted host connection. Network File System The Network File System (NFS) is a popular and widely used protocol for file sharing. It is discussed in detail in Chapter 12, “Network File Service (NFS).” NFS allows servers running the nfsd daemon and mountd to export entire filesystems to client machines utilizing the NFS filesystem support built in to their kernels or to machines that provide for NFS support in the kernel. The mountd daemon keeps track of mounted filesystems in the /etc/mtab file and can display them with the showmount command. Many organizations use NFS to serve up users’ home directories. This allows users to roam about and use more than one machine; thus, each user has access to her home directory. page 387 #BREAK# Inside Linux If you are using NFS, be sure that you export only to the machines that actually require those services. You should never export your entire root directory. Take your time and set up NFS so that only the required directories are exported. Network Information Service The Network Information Service (NIS) is a method by which information can be distributed to a group of machines. It is discussed in detail in Chapter 11, “Network Information Service (NIS).” Fundamentally, the NIS master maintains the information tables, and it converts these tables to NIS map files. These map files are then distributed about the network to other machines. The NIS clients can then obtain login, password, home directory, and shell information from these NIS map files. Incidentally, this information is the same as that found in the /etc/passwd file. Users can then manipulate their account information, such as changing passwords just one time and having that change take effect for all other NIS machines in the domain. As you would expect, this type of functionality reduces the security that NIS can control. This is just a side effect of NIS being a flexible and easy information system. If a cracker could discover just the NIS domain name, accessing the /etc/passwd file is a piece of cake. NIS is also easily spoofed, so be sure you know the risks of running NIS before doing so. The update to NIS is NIS+. NIS+ is more secure than NIS. If you are running NIS, you should check out NIS+ at http://metalab.unc.edu/mdw/HOWTO/NIS-HOWTO.html. Firewalls Firewalls have been around for quite a while. The concept is simple - the firewall is used to control the information that is allowed to flow into and out of your network. To use an analogy, townhouses and office buildings use firewalls as a form of protection from fire. Although they are used to reduce the movement of fire, the concept is the same. Walls are strategically placed within the structure to retard the movement of fire to other parts of the structure. Even automobiles employ firewalls - a metal wall that separates the engine and passenger compartments. A computer firewall is the same, but it utilizes software as the “wall.” The very first firewall utilized a UNIX machine that had a connection to two distinct networks. One network card was connected to the Internet and the other card was connected to the internal network. If you wanted to get to the Internet, you had to log on to the UNIX firewall server. From that point, you would use the resources on the UNIX firewall server. To this day, the firewall host is connected to both the Internet and your internal LAN. Any access to the Internet from your client machine (or vice versa) must travel through the firewall. This allows the firewall to have power over the data that is moving in and out of your private network. As you would expect, Linux machines are a natural choice for firewall systems. You have flexibility in the number of options you can employ to set up a firewall. For Linux versions 2.0 and later, firewall support can be provided directly by the kernel. If you have a Linux system utilizing an older Linux kernel, previous to 2.1.102, you can obtain a copy of the ipfwadm package from http://www.xos.nl/linux/ipfwadm. If you are using Linux with a kernel version of 2.1.102 or later, you can obtain the ipchaining package from http://www.rustcorp.com/linux/ipchains. Regardless of the package, you can control the type of network traffic you will allow, and you can change the rules dynamically. Good resources for firewall support are available. An excellent, yet dated, document can be found at the National Institute of Standards and Technology (NIST). The URL to the document is http://csrc.nist.gov/nistpubs/800-10/main.html. Another good site is The Freefire Project, which can be found at http://sites.inka.de/sites/lina/freefire-l/index_en.html. You can get information on firewall tools, resources, and join their mailing list. Unfortunately, I find the site not very browser friendly. page 388 #BREAK# Inside Linux Accounting Data A lot of important information can be found in the /var/log directory. The following dialog shows the contents of a typical Linux /var/log/ directory. bash-2.03# ls -al total 296 drwxr-xr-x 3 root root 1024 Jan 21 01:33 . drwxr-xr-x 17 root root 1024 Jan 8 11:38 .. -rw-r–r–1 root root 6419 Jan 8 18:07 Config.bootup -rw-r–r–1 root root 3127 Jan 21 01:33 boot.msg -rw——-1 root root 24 Jan 21 01:34 faillog -rw-r–r–1 root root 0 Jan 8 11:34 httpd.access_log -rw-r–r– 1 root root 3682 Jan 21 01:34 httpd.error_log -rw-rw-r–1 root tty 292 Jan 21 01:34 lastlog -rw-r—–1 root root 1065 Jan 9 00:03 mail -rw-r—–1 root root 45238 Jan 21 04:53 messages drwxr-xr-x 2 news news 1024 Jan 8 11:29 news -rw-r—-1 root root 616 Jan 9 00:03 sendmail.st -rw——-1 wwwrun root 0 Jan 8 11:34 ssl_scache.dir -rw——- 1 wwwrun root 0 Jan 8 11:34 ssl_scache.pag -rw-r—–1 root root 9191 Jan 21 03:15 warn -rw-rw-r–1 root tty 221568 Jan 21 04:53 wtmp -rw-r—–1 root root 0 Nov 6 08:57 xdm.errors bash-2.03# You should ensure that the files in the /var/log directory can be viewed (read/write) only by appropriate personnel - only people in system administrator roles. You should be familiar with your logging facility because different Linux distributions will perform their logging differently. You can discover where your Linux distribution is logging by viewing the /etc/syslog.conf file. The syslogd daemon uses this file to know where it is to log system messages. The following shows the contents of the /etc/syslog.conf on a freshly installed SuSE 6.3 Linux distribution: # /etc/syslog.conf - Configuration file for syslogd(8) # print most on tty10 and on the xconsole pipe # kern.warn;*.err;authpriv.none /dev/tty10 kern.warn;*.err;authpriv.none |/dev/xconsole *.emerg * # # enable this, if you want that root is informed immediately #*.alert root # # all email-messages in one file # mail.* -/var/log/mail # # all news-messages # these files are rotated and examined by “news.daily” news.crit -/var/log/news/news.crit news.err -/var/log/news/news.err news.notice -/var/log/news/news.notice # enable this, if you want to keep all # news messages in one file #news.* -/var/log/news.all # # Warnings in one file # *.=warn;*.=err -/var/log/warn *.crit /var/log/warn # # save the rest in one file # *.*;mail.none;news.none -/var/log/messages # enable this, if you want to keep all # messages in one file #*.* -/var/log/allmessages As you can see, SuSE’s syslogd daemon performs its logging to various files in the /var/log directory. The following shows the contents of a newly installed Red Hat 6.1 (Deluxe) distribution: # Log all kernel messages to the console. # Logging much else clutters up the screen. #kern.* /dev/console # Log anything (except mail) of level info or higher. # Don’t log private authentication messages! *.info;mail.none;authpriv.none /var/log/messages # The authpriv file has restricted access. Authpriv.* /var/log/secure # Log all the mail messages in one place. Mail.* /var/log/maillog # Everybody gets emergency messages, plus log them on another # machine. page 389 #BREAK# Inside Linux *.emerg * # Save mail and news errors of level err and higher in a # special file. uucp,news.crit /var/log/spooler # Save boot messages also to boot.log local7.* /var/log/boot.log With this distribution of Red Hat, the logging is also performed to files in the /var/log directory. For contrast, the following is the contents of a version 4.0 distribution of Slackware. # /etc/syslog.conf # For info about the format of this file, # see “man syslog.conf” (the BSD man page), # and /usr/doc/sysklogd/README.linux. *.=info;*.=notice /usr/adm/messages *.=debug /usr/adm/debug # We don’t log messages of level ‘warn’. Why? Because if you’re running # a news site (with INN), each and every article processed generates a # warning and a disk access. This slows news processing to a crawl. # If you want to log warnings, you’ll need to uncomment this line: #*.warn /usr/adm/syslog *.err /usr/adm/syslog # # This might work instead to log on a remote host: # * @hostname You should always be in the habit of analyzing your log files. Scripts can be created to automate repetitive tasks, such as validating idle time in log files. Idle time, you ask? If your system is heavily used, your log files might show a maximum of 60 seconds between log entries. This is considered the log idle time. Crackers are notorious for removing entries of their activities from log files before leaving the system. They do this for a couple of reasons. One is that they want to remove any traces of their existence on the system, especially those that would leave a trail to them. This also allows them to return again, especially if they find things on your system that they want. They also remove their trail of existence because it is part of the routine (challenge). The first part of the challenge is breaking in; the second part is getting out undetected. Check for idle time in the log files. This is indicative of someone tampering with the log file specifically, removing entries. Look for short-lived entries, too. Scan for a log in session that is very short. Many crackers just want to get the right username and password. Some crackers will peruse your system for structure and content, and then log off. They capture the structure and content and review the data offline. They examine the data and then form a plan of attack. Watch for usernames being used when they should not be. For example, suppose you discover a log in entry for the username guest and you have not had any visitors using your system. This should raise some suspicion. You then want to disable the guest account and change its password. Make it a point to keep the auth facility from any other log information. This should include information such as log in, using su to switch user, and any other special accounting facts. Other facility keywords besides auth are authpriv, cron, daemon, kern, lpr, mail, mark, news, security (same as auth), syslog, user, uucp, and local0 through local7. The facility specifies the subsystem that produced the message. You should also force syslog to forward logging data to a secure machine. To enable this, use the at (@) sign (REMOTE MACHINE option) to relay the messages. This allows syslogd to send messages to a remote host also running syslogd and to receive messages from remote hosts. The remote host will not forward the message; rather, it will log them locally. If you want to forward messages to a remote host, you have to prepend the hostname using the @ sign. By doing this, you can control the syslog messages on one host if other machines will log (remotely) to it. Refer to the man page for syslog.conf for more detailed information about other information pertaining to syslog rules. Several more advanced syslogd programs are out there. Take a look at http://www.coresdi. com/english/slogging/ssyslog.html for Secure Syslog. Secure Syslog allows you to encrypt your syslog entries and make sure no one has tampered with them. Another syslogd providing more features is syslog-ng. It allows you a lot more flexibility in your logging facilities and uses remote syslog streams to prevent tampering. page 390 #BREAK# Inside Linux The swatch (Simple Watchdog) tool is used for monitoring events. Swatch will modify specified programs, enhancing their logging capabilities. Software is also provided to monitor the system logs for important messages. Finally, log files are much less useful when no one is reading them. Take some time out every once in a while to look over your log files and get a feeling for what they look like on a normal day. Knowing this can help make unusual things stand out. Summary We covered a lot of information concerning security in this chapter. We began with an overview of security, specifically discussing intruders. You learned the difference between a hacker and a cracker: a hacker is someone who has an extreme interest in computers, whereas a cracker is more interested in breaking into a system and potentially causing malicious damage. Crackers can fall into one of several categories: leeches, espionage, celebrity, investigative, piggyback, and malicious. Others exist, but these are the major categories. Physical security was covered next, including natural and physical elements. Some of the natural elements are dust, electricity, smoke, and fire. You can guard against electrical problems by installing surge protectors and battery backup units. For fire, there are many methods of (reactive) prevention, such as smoke and fire detectors, alarms, and automatic extinguishing systems. Some of the physical elements concern subjects such as security guards and access cards, BIOS locks, computer (case) locks, and system backup. I also discussed how to reduce the risk, including “revealing” paperwork, unattended hardware, unattended terminals, and user education. Next, social engineering was covered, which is the ability for someone to negotiate something from another person utilizing tactics such as misrepresentation and persuasion. Other security issues were discussed, such as passwords, account types, and encryption. Some of the account types discussed were command accounts, dead accounts, default accounts, guest accounts, and password-free accounts. Each of these account types has its weaknesses, and you should ensure that preventative measures are put into place. Next, we jumped into the world of authentication, specifically discussing Kerberos Authentication and Pluggable Authentication Modules (PAM). Kerberos provides a method to prove the user’s identity without sending user data on the network. PAM is a suite of shared libraries that enables the administrator to decide how applications perform user authentication. Shadow passwords are a popular staple in the fight against intrusion. Traditionally, the /etc/passwd file contains the username and associated password for each user on the system. Shadow passwords are stored in the /etc/shadow file, allowing only privileged users access to it. Then, we moved into file security, covering file permission settings, which control who has access to the file. These settings also state what those users can do to the files. Also covered are Network File System (NFS), Network Information Service (NIS), and firewalls. NFS is a widely used protocol for file sharing. NIS is a method to distribute information to a group of machines on the network. A firewall controls information that is allowed to flow into and out of a network. Each has its own special security limitations that should be addressed. Finally, we covered accounting information and the need to safeguard it. You should ensure that files in the /var/log directory are viewed only by appropriate personnel. The /etc/syslog.conf file will reveal the directory your Linux distribution is logging to. page 391 #BREAK# Inside Linux Chapter 22. Managing Accounts In this chapter, we focus primarily on the management of user and group accounts. It is important to understand what it takes to add, modify, and remove users and groups. Beginning with the section that follows, an overview of user management is provided, followed by sections dealing with user account management and group account management. Overview Linux is a multitasking and multiuser operating system. When we talk about multitasking, we are referring to the fact that the operating system can execute more than one process at a time. Actually, only one process has the attention of the processor, but you can have multiple applications running and Linux will switch between these processes, allowing each application a slice of processor time. Linux is also a multiuser operating system. This feature allows more than one user to be logged in to a single computer. Because Linux allows multiple users to be on the system at one time, each user on the system must be uniquely identified. There are a number of reasons for this. First, each user on the system must be acknowledged and be held accountable for usage on the system. Many organizations require accounting information for each user on the system. In other words, each user’s time is accounted for so that the user’s time on the system can be billed to the appropriate department. Logging a user’s time on a system provides a measure of accountability concerning activities while the user is utilizing the system. Another reason that each user needs to be uniquely identified is for file storage requirements. When users log on to a Linux system, they are assigned a home directory where they can store files and other electronic artifacts. Many applications that are used with a Linux system store configuration information specific to the user currently using the application. For example, you might be using a word processing application and might have changed various options in the configuration window. When you save these options, the application stores your options to a special data file in your home directory (or other similar scheme). A third reason is security. Some people might classify this subject as “classification of work.” In other words, it’s not so much that security is a concern, but it’s the capabilities that are enabled for specific users. So, if Mary (an accountant) logs in to the system, she will be able to use the accounting system and examine all accounts and records. She will also be able to examine payroll records and perform other financially sensitive functions within the system. John, on the other hand, who is a data entry clerk, can access the accounting system only to add new shipping orders and inventory records. In addition, John can run spreadsheet and word processing applications pertaining only to his area of responsibility. This example shows both a concern for security and a focus for roles played within the system. We do not want John to access the accounting system and view everyone’s payroll information. From a role perspective, we want to allow John to run only the spreadsheet and word processing applications. This helps to provide a focus of activities for John while he is in the system. To help with these situations (and others), Linux provides support for multiple users to be logged in. Each user is given a unique name, known as a username, for identification. You cannot view a username just as something that is specific to one user - the picture is much greater than that. It is the artifacts that result from a user’s use of the system. These artifacts include items such as files, system resources, and other system-oriented pieces of information that are specific to one user. Managing Users This section delves into the world of user management. Although this is an easy chore, it can be a consuming responsibility. This is especially true in a large organization employing hundreds or thousands of employees. Someone has to keep up with all the users on the system, and that someone is the system administrator. page 392 #BREAK# Inside Linux It is not just the adding and removing of users from the system that can be so overwhelming. It is the change in status or directory paths. It might be the addition of an application to the system that applies only to 2 of the 500 people using the system. Yet, as an administrator, you must start somewhere when dealing with users. This involves adding a new user, removing a user, and associating a user with a group. Associating a user with a group adds another level of complication. We discuss groups in a section that follows. In this section, we address the layout and functionality of the /etc/passwd file. We also examine what it takes to add a new user to the system and to remove a user from the system. Starting with the next section, we discuss the purpose and the use of the /etc/passwd file. The /etc/passwd File The /etc/passwd file can be viewed as the central repository for all users on a Linux system. The /etc/passwd file is not specific to Linux; indeed, the /etc/passwd file was born from UNIX systems. Most people refer to the file simply as the password file. A word of caution: Before modifying the /etc/passwd file, you should always make a copy of the file. Although some text editors automatically create a backup file, you cannot rely on this happening with all editors. The password file contains more than just a username. Many other pieces of information about a specific user are maintained in the password file. Also, various applications use the password file for various reasons, such as user verification and group information. The structure of the /etc/passwd file is similar to that of other configuration-oriented files in Linux. Each line is dedicated to one user. Each line contains a number of fields that are separated by a colon. Seven fields compose a user’s entry in the password file. Table 22.1 identifies these seven fields. Table 22.1. Entries in the /etc/passwd File Field Description Username This is the username that uniquely identifies one user of the system. Each organization (usually) has a policy concerning the naming convention to be used for username creation. Password This is an encrypted form of a password that is specific to the username. Numeric user ID Each user is identified within the system with a unique ID that is numeric. Numeric group ID Each user is identified within the system to be a member of some group. Each group within the system can have zero or more usernames associated with it. Full name This is usually reserved for the user’s full name (first and last names). You can also use it to store other information about a user. Home directory This field is a directory path indicating the user’s home directory. Login shell This identifies the shell program to run after the user logs in to the system. As mentioned previously, each of these fields (the file data) is separated by a colon, and each line is specific to one user. The following could represent a typical entry for the /etc/passwd file: sjcat:gTfs4Ggvfes4ws:122:100:Stimpson J. Cat:/home/sjcat:/bin/bash In this sample entry, the username is sjcat. The second field is the (unreadable) password entry. The third entry is the unique numeric ID that is associated with the username. The next field is the numeric group ID, 100, that is associated with sjcat. The entry Stimpson J. Cat is the full name entry, and the sixth entry is sjcat’s home directory. The last field is the shell command to be launched, which is /etc/bash. page 393 #BREAK# Inside Linux The following is a sample /etc/passwd file. stimpy $ cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/bin/bash daemon:x:2:2:daemon:/sbin:/bin/bash lp:x:4:7:lp daemon:/var/spool/lpd:/bin/bash news:x:9:13:News system:/etc/news:/bin/bash uucp:x:10:14::/var/lib/uucp/taylor_config:/bin/bash games:x:12:100::/tmp:/bin/bash man:x:13:2::/var/catman:/bin/bash at:x:25:25::/var/spool/atjobs:/bin/bash postgres:x:26:2:Postgres Database Admin:/var/lib/pgsql:/bin/bash lnx:x:27:27:LNX Database Admin:/usr/lib/lnx:/bin/bash mdom:x:28:28:Mailing list agent:/usr/lib/majordomo:/bin/bash wwwrun:x:30:65534:Daemon user for apache:/tmp:/bin/bash squid:x:31:65534:WWW proxy squid:/var/squid:/bin/bash fax:x:33:14:Facsimile Agent:/var/spool/fax:/bin/bash gnats:x:34:65534:Gnats Gnu Backtracking System:/usr/lib/gnats:/bin/bash adabas:x:36:100:Adabas-D Database Admin:/usr/lib/adabas:/bin/bash irc:x:39:65534:IRC Daemon:/usr/lib/ircd:/bin/bash ftp:x:40:2:ftp account:/usr/ftp:/bin/bash anonymous:*:222:2:ftp account:/usr/ftp:/bin/false firewall:x:41:31:firewall account:/tmp:/bin/false informix:x:43:34:Informix Database Admin:/usr/lib/informix:/bin/bash named:x:44:44:Name Server Daemon:/var/named:/bin/bash db2fenc1:x:46:46:DB2 Instance UDF user:/usr/lib/db2/db2fenc1:/bin/bash db2inst1:x:47:47:DB2 Instance main user:/usr/lib/db2/db2inst1:/bin/bash db2as:x:48:48:DB2 Administration:/usr/lib/db2/db2as:/bin/bash fnet:x:49:14:FidoNet:/var/spool/fnet:/bin/bash gdm:x:50:15:Gnome Display Manager:/var/lib/gdm:/bin/bash postfix:x:51:51:Postfix:/var/spool/postfix:/bin/false cyrus:x:52:12:User for Imapd:/usr/cyrus:/bin/bash nps:x:53:100:NPS admin:/opt/nps:/bin/bash nobody:x:65534:65534:nobody:/tmp:/bin/bash stimpy $ Notice that the root account has a userID of zero (0). The root account is also known as the superuser account. The username for the superuser account does not have to be root, although this is standard practice. You can, for example, use the name king or master if you like. Whatever name you choose, the userID is the determining factor by the system. The first field for a user is the user’s assigned username. Most organizations maintain a policy for username naming conventions. The most popular naming conventions are the concatenation of the user’s first (name) initial and the user’s last name. In the previous example, Stimpson J. Cat becomes scat because the first letter of the first name is prefixed to the last name. This is the most popular convention used, although other schemes can be employed. Another popular scheme is the user’s first name spelled out fully, followed by an underscore (_) character, and then followed by the user’s last name. Using our example then, the username would be stimpson_cat. This alleviates the duplication that can arise from the first name letter plus last name scheme. For example, Valarie Findlay and Vince Findlay will both resolve to the same username (using the first scheme). Another consideration for usernames is that some systems restrict the length of a username to eight characters. Letters, digits, the underscore (_), and period (.) can be used in the creation of a username. The second field is the password and is unreadable because it is in an encrypted form. The password is not in human-readable form - and for good reason. Most every user on a Linux system can print (or view) the contents of the /etc/passwd file; this is why the password is encrypted. The encryption algorithm provides a high level of security. This is not, however, an excuse to choose simple and easy- to-crack passwords. Most Linux distributions use shadow passwords. The encrypted password is stored in a separate file named /etc/shadow. Only the root user can read this file. In the /etc/passwd file, a special marker is used in the second field. Refer to the previous /etc/passwd sample; the “x” character denotes this special marker. To change a user’s password, you invoke the passwd command. The third field is a unique number that is associated with the username, often called the UID. The system refers to a username using its associated UID, rather than the username. The system can process that number much faster than it can a string of text (username). Let’s face it, computers are number-crunching machines. NOTE If more than one account has the same UID, they are considered to be equivalent. There are times when several users must share an account (in contrast to being members of the same group), when doing this is preferable to having those users share one account/password combination. page 394 #BREAK# Inside Linux The fourth field is the group ID (GID) and is used to associate a user with some group. Group information is found in the file /etc/group and is discussed in a section that follows. Users should be associated with a group such as users or staff; they should not be associated with groups such as bin or mail. The fifth field is the user’s full name. Some organizations use this field for other identification purposes. This field is not used by Linux for any purpose; it is simply a free-form text field. The sixth field is the user’s home directory and should be unique. When users log in to the system, their current working directory will be the home directory specified in this field. A user’s home directory is typically a subdirectory under the /home directory. The directory name is usually the same as the username, but it is not restricted to using it. The last field designates the shell command that is launched for the user. For most Linux distributions, the login shell used is /bin/bash. Next, we will see what we can do to add a user to the system. Adding a User We can edit the /etc/passwd file directly to add a user to the system. This can be somewhat cumbersome and can lead to trouble. Before demonstrating this method, we first examine two commands that can be used to add a user. Then, if you are feeling brave, we detail the manual method of adding a user by editing the /etc/passwd file. You should note that not all Linux systems offer both the adduser and useradd commands. The most popular is (probably) the adduser command. In the next section, we detail the adduser command. If your Linux distribution offers both commands, be sure that the command files are unique (no link from one command to the other). For example, under RedHat, adduser is a symbolic link to the useradd command; erroneous results can be expected if you pass adduser options. Using the adduser Command The first command we examine is the adduser command. This command is used to add a nonexistent user to the system. The various forms of usage for adduser are as follows: adduser [–system [–home directory] [–group]] [–quiet] [–force-badname] [–help] [–version] [–debug] username adduser [–quiet] [–force-badname] [–help] [–version] [–debug] username group adduser [–group] [–quiet] [–force-badname] [–help] [–version] [–debug] group Table 22.2 lists the options to the adduser command. Table 22.2. Options to the adduser Command Option Description –system Creates a new system user and is assigned the /bin/false shell; an asterisk is identified in the password field. –home directory Identifies the directory as the user’s home directory. If the directory does not currently exist, it is created. –group Creates a group with the given name. –quiet Suppresses any progress messages. –forcebadname Forces the commands (addgroup or adduser) to be less stringent. Usually, the username and group names must consist of a lowercase letter followed by lowercase letters or numbers. –help Shows any help text for the command. –version Displays the version information. –debug Provides debugging information. page 395 #BREAK# Inside Linux The adduser command adds a user to the system. The command utilizes information found in the configuration file named /etc/adduser.conf. The adduser command automatically assigns an appropriate (and unique) UID and places the value into the /etc/passwd file. If required, the adduser command creates a home directory for the username. Next, it copies the skeletal files (from /etc/skel) to the home directory. Finally, the command allows the system administrator to set a default password, plus finger information for the new user. The adduser command must be run as root. If the adduser command is invoked with a single name, adduser creates a new user with the supplied name. If adduser is passed two names, adduser uses the first name as an existing user and the second name signifies an existing group; then adduser adds the existing user to the group. Using the useradd Command The next command we examine is the useradd command, which is a variation of the adduser command. This command is also used to add a nonexistent user to the system. The various forms of usage for useradd are as follows: useradd [-c comment ] [-d dir ] [-e expire ] [-f inactive ] [-g group ] [-G group [, group…]] [-m [ -k skel_dir ]] [-u uid [-o]] [ -s shell ] login useradd -D [ -b base_dir ] [ -e expire ] [ -f inactive ] [ -g group ] You should note that not all Linux systems offer both commands. The most popular is (probably) the adduser command. Table 22.3 identifies the options to the useradd command. Table 22.3. Options to the useradd Command Option Description -c comment Comment is any text string. It is used as the field of the user’s full name and is stored in the user’s /etc/passwd entry. -d dir Home directory for the new user. The default is base_dir/username; base_dir is the base directory for login home directories (usually /home) and username is the new username. -e expire The expiration date for a login. Beyond this date, the user will not be able to access this login; usually used for temporary logins. -f inactive Specifies the maximum number of days between uses for a login ID. -g group Specifies an existing group’s ID or string name. -G group Defines the new user’s supplementary group membership for an existing username account. -k skel_dir The directory containing the skeleton information that can be copied to a user’s home directory. -m Creates the new user’s home directory if it does not already exist. -s shell Specifies the full pathname of the user’s login shell. -u uid The UID of the new user; it must be a non-negative decimal number. -o Allows a UID to be duplicated. -b base_dir Identifies the default base directory if the -d option is not specified. The useradd command performs two steps. First it adds the new user entry into the /etc/passwd file, and then it applies the password to the /etc/shadow file. The command also creates any group memberships for the user if the -G option is specified. It also creates the user’s home directory if the -m option is specified. The new username entry is locked until you apply the passwd command for the account. You should note that the limit for a line using this command is set to 512 characters. Take this into consideration when supplying a new username account. page 396 #BREAK# Inside Linux The username (or login) field is a string of no more than eight characters, although some distributions of Linux allow more characters. The legal characters can consist of alphabetic characters, numeric characters, the period (.), the underscore (_), and the hyphen (-). The first character specified must be alphabetic. The generally accepted practice is to use all lowercase alphabetic characters for a username. Most versions of useradd produce a warning message if you have not adhered to the rules. Manually Create a New User You can create a username account manually, without the use of the adduser or useradd commands. The following steps detail the sequence that is required. A quick note before starting: the vipw (or vi) command may not be available on your system; use whatever editor is appropriate. 1. Using the vipw command, edit the /etc/passwd file. Insert a new line and the required fields. You should not use another editor to edit this file; the vipw command applies appropriate locks to the /etc/passwd file while editing. Verify that you have supplied a username, UID, GID, the user’s full name, the home directory, and the user’s login shell. For the password entry, use the star (*) character. You will use another command to set a default password. For the time being, a * for the password will disallow the use of the username. 2. Next, create the user’s home directory that you identified in the /etc/passwd file. For example, if the username is newuser, execute the command mkdir /home/newuser. 3. After creating the user’s home directory, you need to copy all the files from /etc/skel to the user’s home directory. Using our example, issue the command cp /etc/skel/* /home/newuser. 4. Next, you need to set the ownership and permission using the chown and chmod commands. The recommended sequence of commands is as follows: cd /home/newuser, chown -R username.group., and chmod -R go=u,go-w. 5. Finally, you need to set an initial password using the passwd command. This command is used to change the password and its attributes for a specified username. If your distribution uses an /etc/shadow file, you must be sure to add the user to that file. If you require a new group for this new user, you will have to edit the /etc/group file. To edit this file, you need to use the vigw command, which is similar in operation to the vipr command. Supply the appropriate additions for the new group account and save the file. After you have completed the final step (setting the password), the account should be accessible. The password step should be the last step in the manual process. If you change the password as an early step, the user will have the ability to log in before you have completed the remaining steps. This exercise is beneficial because you may be required to create special accounts, such as the FTP account. This account is not used by any one person in particular. This account is normally called the anonymous ftp account. You may already be familiar with this if you have downloaded files from an FTP site. Most Linux systems create this account automatically during the installation process. Removing a User The commands in this section are fairly straightforward. Not many options can be applied because the focus of the commands is to simply remove a specified username from the system. When removing a user from the system, you have to remember that besides the entry in the /etc/passwd file, you must remove all files, mailboxes, print jobs, cron jobs, and all references for the user. The userdel command is used to help facilitate all this housekeeping. The use of the userdel command is addressed in the next section. Using the userdel Command The userdel command is used to delete a user’s login from the system. The syntax is as follows: userdel [ -r ] login page 397 #BREAK# Inside Linux The userdel command first deletes the specified username from the system and causes other changes in the system for that username. The only option to the userdel command is the -r option. This option removes the user’s home directory from the system. After the command has completed, the associated files and directories will not be accessible. Manually Removing a User You can also manually remove a user from the system, the same as you can manually add a user to the system. This section addresses the removal of a user from the system; the user dummy is assumed here. First, you must remove the dummy entry found in the /etc/passwd file. This is quite easy; just fire up your editor and bring the /etc/passwd into the editor. Locate the line for dummy and delete the line. Save the file and return to the command prompt. Also, if your distribution uses an /etc/shadow file, be sure to remove the user’s entry in that file, too. Next, you should check for a dummy entry in the /etc/group file. This is also easy; just bring /etc/group into your favorite editor. Locate any line(s) containing dummy and remove the dummy user entry (or entries). Save the file and return to the command prompt. Next, you need to remove the user’s home directory. Assuming the standard /home/… directory path, issue the rm command as follows: stimpy $ rm -r /home/dummy Be absolutely sure you are removing the appropriate home directory before submitting the recursive delete. Finally, you need to purge the mail spool file and crontab entries for the user. In a pinch, you can run the rm command against the user’s spool file, such as in the following dialog. This dialog also demonstrates the use of the crontab command to remove entries for user dummy. stimpy $ rm -r /var/spool/mail/dummy stimpy $ crontab -u dummy r You can also follow up these steps by performing a systemwide search for the username dummy. Managing Groups Each user is a member of one or more groups within a Linux system. The magic of groups pertains to file permissions and accessibility. Each file maintains group ownership attributes and permissions that define how the users in that group can access the file. Some of the more common system-defined groups are bin, mail, and sys. No user should be a member of any of the system-defined groups. A group such as users is a more appropriate group for user. In the next section, we discuss adding a new group to the system, followed by a section concerning the removal of a group. Adding a Group The groupadd command is used to create a new group and its definition. The command applies the attributes by adding the new entry to the /etc/group file. The syntax for the command is as follows: groupadd [ -g gid [ -o ] ] group Table 22.4 details the options for the groupadd command. Table 22.4. Options to the groupadd Command Option Description -g gid Assigns the group ID gid for the new group. This group ID must be a non-negative decimal integer below MAXUID as defined in /usr/include/sys/param.h. -o Allows the gid to be duplicated. page 398 #BREAK# Inside Linux The following dialog shows the contents of a sample /etc/group file: stimpy $ cat /etc/group root:x:0:root bin:x:1:root,bin,daemon daemon:x:2: tty:x:5: disk:x:6: lp:x:7: wwwadmin:x:8: kmem:x:9: wheel:x:10: mail:x:12:cyrus news:x:13:news uucp:x:14:uucp,fax,root,fnet shadow:x:15:root,gdm dialout:x:16:root at:x:25:at lnx:x:27: mdom:x:28: yard:x:29: dosemu:x:30: firewall:x:31: public:x:32: video:x:33: informix:x:34: game:x:40: xok:x:41: trusted:x:42: modem:x:43: named:x:44:named postfix:x:51:postfix dbmaker:x:52: users:x:100: nogroup:x:65534:root stimpy $ The information contained in the /etc/group file is similar in structure to the /etc/passwd file detailed previously. Each group entry exists on a single line. Each line is separated into four distinct fields, using the colon (:) as the separator. The first field is the group name and should consist of alphanumeric characters. The second field is the password and is usually left blank (or an asterisk is used). This field usually exists for backward compatibility because most versions of Linux do not support this field. The third field is the group ID number -each group should have a unique value. The fourth field is a list of all user IDs that are members of the group. Modify a Group You can modify a group using the groupmod command. The syntax for this command is as follows: groupmod [ -g gid [ -o ] ] [ -n name ] group The groupmod command allows you to modify the definition of a group. The command will modify the associated entry found in the /etc/group file. Table 22.5 details the options that are supported by the groupmod command. Table 22.5. Options to the groupmod Command Option Description -g gid Identifies the new group ID for the group. The group ID must be a non-negative decimal integer less than MAXUID. -o Allows the GID to be duplicated. -n name Specifies the new name for the group. The groupmod command is used to modify a group definition in the /etc/group file. If NIS or NIS+ is used to supplement the local /etc/group file, the groupmod command will not change information supplied by NIS. The groupmod command validates the group name and group ID to the external name service. Refer back to Chapter 11, “Network Information Service (NIS),” for more information concerning NIS. page 399 #BREAK# Inside Linux Removing a Group The groupdel command is used to delete a group definition from the /etc/group file. The syntax is as follows: groupdel group The command deletes the appropriate entry from the /etc/group file. You should note that the groupdel command will delete only a group definition that is found in the /etc/group file. If a NIS or NIS+ is used to complement the (local) /etc/group file, the groupdel command will not be able to change the information supplied by NIS. Summary In this chapter, we covered the management of user accounts. Because Linux is a multiuser operating system, we need a way to maintain the users who access the system. This is done by creating a user account for each user on the system. Unique usernames are used so that each user’s work can be uniquely identified and stored on the system, providing a way to isolate a user’s work (from other users). There are security reasons for maintaining unique username accounts for all users on the system. We examined the structure of the /etc/passwd file. We discovered that the /etc/passwd file consists of seven fields, including username, password, user ID, group ID, full name, home directory, and login shell command. We examined how to add a new user to the system. Two commands are available to add a user: adduser and useradd. Some Linux systems have both commands, and some Linux systems have one or the other. Refer to your system documentation for details. We also examined how to manually add a user to the system. Also covered in this chapter is the removal of users from the system. The userdel command is covered; this command automates the process of removing the username entries from the /etc/passwd and /etc/group files and also any crontab and mail entries. We also covered the process of manually removing a user. We covered the use of the /etc/group file and the commands associated with adding and removing groups. The groudadd, groupmod, and groupdel commands were covered. These commands allow you to manipulate groups on your system and the users that are related to those groups. page 400 #BREAK# Inside Linux Chapter 23. Other Administrative Tasks This chapter deals with the administrative tasks that are of great importance on a Linux system. Other chapters have discussed Linux installation and maintenance, user administration, and some of the tools that would be used on a weekly basis by a system administrator. This chapter covers some of the deep technical administrative chores such as backup and recovery, security, and file maintenance. Overview System administration, in my opinion, is really a state of mind. Yes, there are daily chores that must be accomplished to maintain a Linux (or UNIX) system. These daily chores must be adhered to in order to keep the users happy and their daily routines trouble-free. Yet there is more to administration than checking off a list of tasks day after day. Good system administrators have a curiosity about what makes the system tick and a need to troubleshoot. It must seem strange that someone would want to troubleshoot a system, but it is true. Troubleshooting presents a challenge to the administrator. Yet at the same time, it presents some heartaches and sleepless nights. Performing some preventative maintenance can alleviate some of the heartaches and sleepless nights. In order to cut down on future maintenance costs, organizations implement preventative measures. What is the old saying - an ounce of prevention is worth a pound of cure? This also applies to system administration. For example, if you perform weekly preventative maintenance on the system’s hard disk(s), the life of the hard disk(s) will be prolonged - assuming that there are no manufacturer defects. Performing weekly maintenance on user account configuration reduces the likelihood of crackers gaining access to the system. Of course, you must ensure that other security holes are corked up. You should pay attention to security notices posted on the Internet describing new methods of attack performed by crackers. Some people will disagree with me, but as a system administrator, you should subscribe to 2600 Magazine. Why subscribe to a magazine that is advertised as the “hacker’s quarterly”? This magazine (and others like it) can make you aware of methods employed by crackers. One good site is http://www.rootshell.com, which provides security news, exploits, and more. For a fairly comprehensive moderated mailing list for the discussion and announcement of computer security vulnerabilities, join the BugTraq mailing list. To join, simply send an email to listserv@securityfocus.com with the text SUBSCRIBE BUGTRAQ Lastname, Firstname in the body of the email. Staying informed is the key to successful system administration. Administrators who maintain a true interest in their work will be far ahead of the game compared to administrators who wait for the end of the day. Root Account This was discussed in another chapter, but it is worth repeating here. You must remember that the root account is the most privileged account on a Linux system. You can do absolutely anything you want if you have root privileges: add, edit, and remove users; modify user passwords; install and remove software; and delete unwanted files (and wanted files, if you aren’t careful). Bad things can happen while you’re logged in as the root account. I have seen system administrators do what is shown here: bash-2.03# bash-2.03# cd / tmp bash-2.03# rm * -r bash-2.03# page 401 #BREAK# Inside Linux This looks fairly harmless at first glance. There are no errors or warnings. But look closer. The first command executed is cd / tmp, not cd /tmp, which produces a different outcome. The cd command used in the dialog changes to the root directory, not /tmp as the administrator anticipated. Try it on your system -execute cd / tmp and then execute the pwd command. You will discover that you are indeed in the root directory. So the administrator executed the two commands without thinking about or verifying the results of her actions. Some administrators execute the ls command before committing to the rm command. But back to the administrator. She stared in disbelief at the commands she had executed. By the time she pressed Ctrl+C, the damage had been done. If you are unfamiliar with the potential results of the rm* -r command, it obliterates all files in the current (or specified) directory and continues this operation recursively in subdirectories. You should always log in using a normal user account, unless you have to perform root-level maintenance. Many administrators feel less than adequate if they log in as anything but the root account. Do not let your ego get in the way, or you might have the same experience as the administrator just described. If you are logged in as root under Red Hat Linux and you execute the GNOME file manager, an error message is displayed informing you that you are running as root. If you are logged in as the root account, the # is displayed as the last character in the prompt. This is a reminder that you are running as the root account. I know an administrator who modifies the shell prompt to read !RooT!-> to remind him of his power. Beware the strength of the root account. Execute every command with caution. Always think twice about what you are about to execute, and then think again. It pays to be prepared and cautious. Rotating User Passwords You should always set up each user account so that its password expires on a rotating basis. Most users do not like to change their passwords all the time, but it is a good security measure to combat crackers. On really large corporate systems, you should rotate passwords at least every 45 days. Many administrators rotate passwords every 30 days. If you are running a small office system of about 30 users, rotating passwords can be relaxed to about 60 days, especially if the system has Internet access. If the system is a fully enclosed LAN, you might relax rotation beyond 60 days. I do not recommend this, however, because certain employees can become disgruntled and wreak havoc on the system. If you are using SuSE Linux, you can use the YaST tool to set the expiration of a password for an account. From the YaST menu, select the System Administration, User Administration menu option. The User Administration window appears. Once you have a user profile loaded, press the F6 function key to reveal the Duration of Password screen. Generically (regardless of distribution), you can set password expiration for user accounts utilizing the passwd command. The -x, -n, -w, and -i options are used to execute password aging on an account. Use the -x max option to set the maximum number of days that a password remains valid. After max days have passed, the user is required to change the password. Use the -n min option to set the minimum number of days before a password can be changed. The user cannot change his or her password until min days have elapsed. The -w warn option sets the number of days the user is warned before his or her password expires. The warning begins to occur warn days before the password expiration. The warning tells the user how many days remain. Use the -i inact option to disable an account after inact days have passed after the password has expired. The user will no longer be able to sign on to the account. You can also edit the /etc/shadow file directly to change the password aging information. This makes it easier to change multiple users at one time. page 402 #BREAK# Inside Linux Some distributions of Linux, such as Red Hat, utilize the chage command to support the options just listed. The usage of chage is as follows: chage [-m mindays] [-M maxdays] [-d lastday] [-I nactive] [-E xpiredate] [-W warndays] user System Backup and Restoration You must perform system backups at regular intervals. This cannot be stressed enough. Failures can occur, so it is always prudent to be prepared for a system restoration. Many problems can occur. There are various hardware failures, such as a hard disk crash or power outage. Human error accounts for many system outages, from accidental to deliberate acts. Earlier you read about an administrator who accidentally executed the rm -r * command at the root directory. A typical backup procedure consists of copying partition data onto an external medium. This external medium can take many forms, such as CD-ROM, tape, or removable drives. This affords you the ability to keep the medium off site and in a safe place. You can also reuse the medium to help save money. You can also perform a backup to another machine. On a large corporate system, this makes sense, because the backup to moveable media can be executed on one machine. For example, say you have servers scattered about the country. Each of these servers can execute a cron job to archive data files to a central server. Then, only this server will require a backup to external media. Backup Considerations Just as there are many distributions of Linux, there are many ways to execute a backup. Some command-line tools have been with us for quite a while, such as cpio, dd, dump, and tar. There are tools supplied by the distribution’s vendor, both text-based and graphics-based. For example, the YaST tool that is included with SuSE Linux provides an interactive front end for performing a backup. Archiving utilities are provided with some of the graphical desktops such as KDE’s Kdat, a tar-based tape archive utility. We cannot forget about the commercial tools, such as BRU (Enhanced Software Technologies), UNiBACK (Orbit Software), and PerfectBackup+ (Merlin Software). When reviewing these tools, you should consider a few things. One, of course, is ease of use. Do you need a user interface to ease the selection of files and directories and unattended scheduling? Along these lines, technical support can be thought of as providing ease of use (and piece of mind). Unattended backup is another consideration. If you require fairly sophisticated scheduling, look for this feature in a product. There are other things to consider, such as portability and network backups. You should make a checklist of the features that are important for your organization and use it when comparison shopping. Backup Tools We will look at a couple of tools that can be used to perform routine backup. We will take a quick look at a number of tools, both graphical and command-line. Using KDE’s KDat Most distributions of Linux now include the K Desktop Environment (KDE). KDE offers a graphical tool called KDat. KDat provides a nice graphical interface and uses the tar utility for creating archives. This offers you the choice of moving the archive to another Linux (or UNIX) system. Figure 23.1 shows the KDat utility after invocation. If you have installed the K Desktop Environment, you can find the KDat tool on the Utilities menu, labeled as Tape Backup Tool. You can also execute it using the command window. Press Alt+F2, type kdat, and press Enter. The interface consists of a tree view in the left panel and a data panel on the right side. If you have never used this tool, you should first select the File, Create Backup Profile menu option. The data panel on the right displays a number of fields and two tab pages, Backup and Tar Options. You need to provide a profile name and archive name. The profile names are helpful in describing the type of backup. For example, you might have a backup profile named Incremental or Full Backup. page 403 #BREAK# Inside Linux Figure 23.1. KDE’s KDat archive utility. Next, you need to specify the directories and files you want to include in the backup. First, click the Working directory pull-down (in the right panel). Next, click the + associated with the root directory (in the left panel). Figure 23.2 shows the result of clicking the tree and shows the right panel opened. Figure 23.2. KDE’s KDat with the root tree open. Notice that there is an empty box between the + and the folder icon for each folder. If you click in this box, an x appears. A file or directory that is marked (that has an x) will be included in the backup. To perform a full backup, mark the root directory. This will select all the subdirectories and the files within them. Next, remove the x from the box next to the /proc and /mnt subdirectories. You do not want to back up the contents of /proc and probably do not want to back up whatever filesystems are mounted. When you have all the directories and files selected, click the Files >> button in the right panel. Figure 23.3 shows the results. page 404 #BREAK# Inside Linux Figure 23.3. KDE’s KDat with directories selected. Be sure to click the Apply button. The final step is to actually back up to tape. Be sure that you have a tape inserted in the drive. Next, select the Mount Tape menu selection from the File menu. If you receive an error message that says the tape is not available, check the preference settings. Select the Edit, Preferences menu option and be sure that the correct tape drive device is selected. Ensure that the profile you want to use is selected, right-click it, and choose the Backup option. A dialog box appears. Simply click the OK button after you have confirmed the details. The backup will begin. KDat shows the progress of the backup in a dialog box. When the backup is complete, be sure to unmount and eject the tape. To unmount, select File, Unmount Tape. Optionally, you can click the tape drive toolbar icon, or right-click the tape drive tree node and select Unmount Tape. For more information about KDat, select Help, Contents. Using YaST Under SuSE SuSE’s YaST configuration utility offers a simple way to back up files. Start YaST, and then select the System Administration, Create Backups menu option. The screen shown in Figure 23.4 is displayed. Figure 23.4. SuSE’s YaST backup utility. page 405 #BREAK# Inside Linux The right pane is where everything happens. Select the directories to exclude from the backup, and press the F10 key to continue. The utility scans the disk for files that have changed. When the tool is finished with its scan, it displays the file selection screen, shown in Figure 23.5. Figure 23.5. SuSE’s YaST backup file selection screen. At this screen, you can further refine the files to be included in the backup. Once you are satisfied with the choices, press the F10 key to continue. Next, you have the option of specifying the archive name and specific options. If you decide to save to a partition, be sure sufficient space is available. Using the tar Utility If you want to use the tar utility, you should become familiar with the appropriate options to satisfy your type of backup. Table 23.1 shows the functional options for tar (you must select one option from this table). Table 23.2 shows the miscellaneous options available for tar. Table 23.1. Functional Options for tar Option Description -A, - catenate, - concatenate Appends tar files to an archive. -c, - create Creates a new archive. - delete Deletes files from the archive (do not use magnetic tapes). -r, - append Appends files to the end of an archive. -t, - list Lists the contents of an archive. -u, - update Appends only files that are newer than the copies in the archive. -x, - extract, - get Extracts files from an archive. Table 23.2. Miscellaneous Options for tar Option Description –atime-preserve Does not change access times on the dumped files. -b, –block-size N Uses a block size of N 512 bytes. -B, –read-full-blocks Reblocks as reads happen. page 406 #BREAK# Inside Linux Option Description -C, –directory DIR Changes to directory named DIR. –checkpoint Shows the directory names while reading the archive. -f, -file [HOSTNAME:]file Uses an archive file or a device named file. –force-local Archive file is local. -F, –info-script F–newvolume- script file Runs a script at the endof each tape. -G, –incremental Creates, lists, or extracts an old GNU-format incremental backup. -g, –listed-incremental F Creates, lists, or extracts a new GNU-format incremental backup. -h, –dereference Does not dump the symbolic links. Rather, it dumps the files the symbolic links point to. -i, –ignore-zeros Specifies to ignore blocks of zeros in the archive, which usually signifies EOF. –ignore-failed-read Does not exit with nonzero status if files are unreadable. -k, –keep-old-files Keeps existing files and does not overwrite them in the archive. -K, –starting-file file Begins at the file named file in the archive. -l, –one-file-system Stays in the local filesystem when creating an archive. -L, –tape-length N Changes tapes after writing N 1024 bytes. -m, –modification-time Does not extract the file-modified time. -M, –multi-volume Creates, lists, or extracts a multivolume archive. -N, –after-date DATE, –newer DATE Stores only files newer than named DATE. -o, –old-archive, -portability Writes a V7 format archive rather than ANSI format. -O, –to-stdout Extracts files to the standard output. -p, –same-permissions, -preserve- permissions Extracts all protection information. -P, –absolute-paths Does not strip leading /s (slashes) from filenames. –preserve The same as -p -s; all protection information is extracted and a list of names to extract is sorted to match the archive. -R, –record-number Shows a record number within the archive with each message. –remove-files Removes files after adding them to the archive. -s, –same-order, –preserveorder A list of names to extract is sorted to match the archive. -S, –sparse Handles sparse files in an efficient manner. -T, –files-from F Gets names to extract or create from file F. –null -T Reads null-terminated names. –totals Prints the total bytes written with - create. -v, –verbose Verbosely lists files processed. -V, –label NAME Creates an archive with a volume named NAME. –version Prints the tar program’s version number. -w, –interactive, -confirmation Asks for confirmation for every action. -W, –verify Attempts to verify the archive after writing it. page 407 #BREAK# Inside Linux Option Description –exclude FILE Excludes the file named FILE. -X, –exclude-from FILE Excludes files listed in FILE. -Z, –compress, –uncompress Filters the archive through compress. -z, –gzip, –ungzip Filters the archive through gzip. –use-compress-program PROG Filters the archive through a program named PROG. –block-compress Blocks the output of the compression program for tapes. -[0 7][lmh] Specifies the drive and density. As an extreme example, the following performs a complete backup of your system and writes it to the /backup filesystem. As usual, you want to exclude the /proc, /mnt, and /backup filesystems. tar -zcvpf /backup/full-backup.tar.gz - directory / - exclude=mnt - exclude=proc - exclude=backup . If you refer to the previous tables, you can quickly decipher the options being used. The z specifies compression of the archive. c specifies that the archive is to be created. v produces verbose output. p specifies to preserve permissions. f names the file for the archive. The - directory option tells tar to move to the named directory. The -exclude options identify the directories to exclude from the backup. The final . is intentional. It tells tar to back up everything in the current directory. Remember, the - directory option told tar to move to the / (root) directory. Once the archive is written, you can move it to any medium you choose. If you want to write to magnetic tape, be sure to check out the mt command. Finally, to restore the previous archive, you would execute the following command: tar -zxvpf /backup/full-backup.tar.gz That’s all there is to it. Using cron and crontab Files If you’re like me, you execute certain commands on a regular basis. You might want to execute a command every hour on the hour or once a day at midnight. The cron command and crontab files are used to schedule commands and processes that repeat at specified intervals. Dates and times are specified in the crontab files. The cron daemon is started at system startup and can be seen running using the ps x command. The cron command should not be executed from the command line, even by a system administrator. Here is the format of a crontab file: minute hour day month day command Each of the date and time components can be expressed as an integer. The following list shows the values for each of the fields. Minute: 0 to 59 Hour: 0 to 23 Day of month: 0 to 31 Month: 0 to 12 (or names; see the following discussion) Day of week: 0 to 7 (or use names) You can use the * (asterisk) to logically designate “all” for the component. For example, a * for the year component means “every year.” page 408 #BREAK# Inside Linux A range of numbers can be specified. A range consists of two numbers separated by a hyphen (-), the range being inclusive. For example, 7 10 for the hours entry specifies execution at hours 7, 8, 9, and 10. Lists are also allowed. They are a set of numbers (or ranges) separated by commas. For example, 1,2,5,9 and 0 4, 8 12 are valid range specifications. Names can be used for the month and day of week fields. This is the preferred method, because the month and day are obvious. Use the first three letters of the day or month. Unfortunately, ranges and lists of names are disallowed. A couple of examples are in order: 15 09 * * 03 date This crontab entry is used to execute the date command at 9:15 a.m. every Wednesday. 00 10 * * * cat /var/log/messages | mail root This crontab entry mails the contents of the /var/log/messages file to the root account at 10 a.m. every morning. Most Linux distributions offer the following crontab directories: /etc/cron.hourly: Runs the command every hour. /etc/cron.daily: Runs the command once a day. /etc/cron.weekly: Runs the command once a week. Scripts or any other executables can be placed into any of these directories. This relieves you of having to develop a crontab entry. If you have a command that fits into one of these categories, place it in the appropriate directory. The file can be a symbolic link to the actual command. System Monitoring System monitoring must be an aggressive effort. This doesn’t mean you should sit at your computer every minute of every day and watch the system running. It means you should take a proactive role in monitoring the system. Be aware of the potential for break-ins. Keep up with current events in the security arena. Read the hacker magazines and Web sites to gain insight into the habits and methods of attack. A principle of software development is that of change management (versioning). The intent is to create an initial baseline of the software and then continue creating versions throughout the software’s life cycle. Version-control software, complete with a repository, is used to check software components into and out of the repository. This allows you to go back to a previous version of a component if necessary. The same concept should be applied to an operating system such as Linux. Some of the smarter system administrators create a snapshot of a system after initial installation. This might seem extreme, but if the