New to running Linux? Cozy up to your computer for a peek into the command line tools available to you in Fedora Core 6. Running routine tasks and basic maintenance are explained in this sample chapter from the best-selling Fedora Core Unleashed.

Most modern Linux distros are a world away from versions that were available only four or five years ago. Sporting a highly
polished graphical interface, Fedora gives you graphical tools with which to carry out most system administration tasks. However,
things can occasionally go wrong and it is important that you know what to do in the event that you cannot use the GUI interface.
In this chapter we will look at some of the basics of Fedora, laying the foundations for other chapters in this book. We will
cover the Linux file system, as well as working with essential user information and accessing useful documentation available
for Fedora. We will also take a look at working with the shell, otherwise known as the command line interface. Then we will
explore the various text editors that can be used with Fedora, as well as examine the fundamentals of file permissions. Finally,
we will clearly explain the importance of the root or super-user account in the maintenance and administration of your system.

Some of the basic command-line skills covered in this chapter include

Performing routine tasks—Logging in and out, using the text console, changing passwords, and listing and navigating directories

Basic user management—Creating and deleting users from the command line

Basic system management—Shutting down and rebooting, reading man pages and other documentation, and using text-based tools to edit system configuration
files

Read this chapter if you are migrating to Linux from another platform; the information here is valuable for individual users
or system administrators who are new to Linux and are learning to use the command line for the first time.

TIP

For those of you who have used MS-DOS in the past, delving into the command line does not seem as scary as for those who,
when faced with a black screen, automatically press the speed-dial button allocated for their neighborhood geek. Regardless
of which user you are, knowledge of the command line serves you well. Because Linux is a UNIX-style operating system, if you
learn the command line functions on Linux, it will be easier for you to use other UNIX-like operating systems, such as the
BSD’s and even Max OS X.

NOTE

On the whole, there are two types of users that access a Linux system: normal day-to-day users and the root user or super
user. At large organizations, a few people might be granted access rights to the root or super-user account in order to complete
necessary system administration tasks. Normal users do not normally need to have root access.

However, if you have Linux installed on your machine as a standalone PC, you automatically have access to the root account. This is so that you can complete necessary configuration and other tasks that require interacting with the system.

This particular aspect of Linux is the victim of a lot of bad press because new users can see it as a significant obstacle
to them getting their work done. This is not the case: The root account, as mentioned earlier, is fundamental to a successful
Linux system. A lot of work has gone into creating easy-to-use administration tools that take away a lot of the difficulty
in maintaining your system. It is still the case that a bit of command-line knowledge serves you well, especially in an emergency.

Working with the Linux File System

Fedora uses a file system, or layout of hierarchical directories similar to that used by other UNIX variants (such as Mac OS X). Nearly all Linux distributions
use a similar directory structure, and Linux distribution vendors have generally agreed on the naming and location of critical
Linux files and directories.

NOTE

The effort to build a consensus regarding the Linux directory structure began in 1993 with the Filesystem Hierarchy Standard
(FHS), a draft proposal that addressed not only Linux issues, but also those of other operating systems, such as BSD. Red
Hat has stated that it is committed to staying compliant with the FHS, which specifies the location and names of files and
directories.

Fedora uses the current 2.3 standard. Key additions to this include the creation of a /media directory for removable storage devices such as DVD drives and zip disks (although keeping /mnt as a temporary mount point). udev has also been added to Fedora; although it is not a part of FHS 2.3, it enables /dev to become a dynamically managed folder allowing the hot-plugging of devices onto the system and the creation (on demand)
of device nodes.

The commonality of how the Linux directory structure is laid out is very useful for open source developers because it cuts
down the amount of work they have to do to get their programs to work with different distributions. For a programmer to know,
for example, that the useradd command is always under /usr/sbin means that he can create shell scripts and other utilities that take advantage of this, and know that they will work universally.
Perhaps unsurprisingly, given the ancestry of Linux, you will find that other UNIX-like operating systems follow the same
directory organization. Of course, you do not get the most of knowing this secret unless you actually learn a little about
how the directories are organized, along with the contents of files and directories, and where software should be installed
and files stored.

A good knowledge of the Linux file system pays dividends to pretty much every system administrator. Because you have full
control (through the root or super-user account), this information is invaluable in keeping your system running smoothly and
securely.

Viewing the Linux File System

Look at the layout of a typical Fedora system by using the list directory contents command, ls, like this:

This section provides an overview of the Fedora file system. You might find a fewer or greater number of directories than
discussed here in your own system. When some software packages are installed, they create new directories. Updating software
packages might also remove or change the name of some directories. See Chapter 7, “Managing Software and System Resources,” for more information on installing, upgrading, and removing software from your
Linux system.

To get a more detailed picture, use the tree command to show the root or base directory layout, along with associated subdirectories, like this (note that your system’s /usr/src directory might be somewhat different, depending on the version of Fedora you have installed or if you have updated Fedora
with a new kernel, and that not all subdirectories are listed):

This example (pruned from more than 30,000 directories) shows the higher-level directories and corresponds to the directories
and descriptions in Table 5.1.

Table 5.1. Basic Linux Directories

Name

Description

/

The root directory

/bin

Essential commands

/boot

Boot loader files, Linux kernel

/dev

Device files

/etc

System configuration files

/home

User home directories

/initrd

Initial RAM disk boot support (used during boot time)

/lib

Shared libraries, kernel modules

/lost+found

Directory for recovered files (if found after a file system check)

/media

Mount point for removable media such as DVDs and floppy disks

/mnt

Usual mount point for local, remote file systems

/opt

Add-on software packages

/proc

Kernel information, process control

/root

Super-user (root home)

/sbin

System commands (mostly root only)

/selinux

Holds the data for SELinux, the security component of Fedora

/sys

Real-time information on devices used by the kernel

/tftpboot

Network boot support

/tmp

Temporary files

/usr

Secondary software file hierarchy

/var

Variable data (such as logs); spooled files

Some of the important directories in Table 5.1, such as those containing user and root commands or system configuration files, are discussed in the following sections.
You use and edit files under these directories when you use Fedora.

Use Essential Commands from the /bin and /sbin Directories

The /bin directory (about 5MB if you do a full install) contains essential commands used by the system when running and booting Linux.
In general, only the root operator uses the commands in the /sbin directory. Many (though not all) of these commands are statically linked; such commands do not depend on software libraries residing under the /lib or /usr/lib directories. Nearly all the other applications on your system are dynamically linked—meaning that they require external software libraries (also known as shared libraries) in order to run.

TIP

Because the system contains dynamically linked applications, you might sometimes get dependency errors when installing or
upgrading software packages; in those situations, a supporting library (or application) might not be present. See Chapter 7 for more information on working with dynamically linked applications and other methods of avoiding such problems. Thankfully,
“dependency hell” is largely a thing of the past due to programs such as yum.

Store the Booted Kernel and View Stored Devices in the /boot and /dev Directories

The /boot directory contains a compressed version of the Linux kernel (loaded at boot time), along with other files that describe the
kernel or provide information for booting Linux. When you rebuild or install a new kernel, the kernel and related files are
placed in this directory (see Chapter 39, “Kernel and Module Management,” for more information on rebuilding or installing a kernel).

Linux device files are contained under the /dev directory. Note that under Linux, nearly everything on your system is a file. This means that (with the exception of network
interfaces; see the note that follows the upcoming list) regular files; directories; hard drive partitions; serial, printer,
or USB ports; and video and sound devices all are files!

The /dev directory contains more than 7,500 files representing devices that may or may not be in use on your system. Some of the most
commonly used devices in this directory include

CD-ROM drives; some which are IDE, others which are CD-RW (CD read/write) drives emulated as SCSI (Small Computer Systems
Interface) devices, such as /dev/scd0

Serial ports, such as /dev/ttyS0 for COM1, /dev/ttyS1 for COM2, and so on

Pointing devices, including /dev/input/mice and others

Printers, such as /dev/lp0

NOTE

Network interfaces (such as eth0 or ppp0) are not represented by Linux device files, but are created in memory when activated. See Chapter 18, “Network Connectivity,” for more information.

Use and Edit Files in the /etc Directory

More than 65MB of system configuration files and directories reside under the /etc directory if you install all the software included with this book. Some major software packages, such as Apache, OpenSSH, and xinetd, have directories of configuration files under /etc. Other important system-related configuration files in /etc are

fstab—The file system table is a text file listing each hard drive, CD-ROM, floppy, or other storage device attached to your PC.
The table indexes each device’s partition information with a place in your Linux file system (directory layout) and lists
other options for each device when used with Linux (see Chapter 39, “Managing the File System”). Nearly all entries in fstab can be manipulated by root using the mount command.

inittab—The system initialization table defines the default runlevel, also known as run-control level or system state. Changes to this file can determine whether your system boots to a graphical or text login, as well as whether dial-up remote
access is enabled. (You learn about default runlevels in the section “System Services and Runlevels” located in Chapter 15, “Automating Tasks.” See the section “Starting X,” located in Chapter 6, to learn more about changing inittab to boot to a graphical interface. The section “Configuring a Dial-In PPP Server” in Chapter 18 discusses editing inittab to enable dial-up remote access.)

modprobe.conf—This configuration file contains directions and options used when loading kernel modules to enable various types of hardware,
such as sound, USB, networking, and so on (discussed in the section “Managing Modules” in Chapter 39). The contents of this file are used during boot time, and the file can be manually edited or automatically updated by Fedora’s
kudzu hardware management tool (if enabled, as you learn later in this section).

passwd—The list of users for the system, along with user account information. The contents of this file can be changed by various
programs, such as useradd or chsh.

For brevity, not all directories and files are discussed here. /etc/sysconfig contains many different hardware and software settings critical to the operation of your Fedora system. Knowing the location
and contents of these files can be helpful if you need to troubleshoot new hardware configurations.

The settings in various files under /etc/sysconfig (such as keyboard, mouse, sound, and so on) are usually created automatically by a related Fedora graphical or console-based configuration utility.

These contents might dynamically change if you use the kudzu hardware configuration service. The kudzu service also prompts you at boot time to remove, configure, or ignore a related setting if kudzu detects new or different hardware (such as a new USB keyboard, network card, or monitor). kudzu creates a file called hwconf that contains a hardware profile of your PC’s current state. Note that if kudzu is not enabled or running, you can use device-specific configuration utilities such as system-config-keyboard, or you can manually edit configuration files.

Information about the type of pointing device attached to the PC, for example, is contained in the file /etc/sysconfig/mouse:

If you are new to Linux, the system-config-mouse client is the best tool to use to configure a new mouse. You should manually edit system hardware configuration files used
by graphical management clients only as a last resort.

Protect the Contents of User Directories—/home

The most important data on a Linux system resides in user’s directories, found under the /home directory. Segregating the system and user data can be helpful in preventing data loss and making the process of backing
up easier. For example, having user data reside on a separate file system or mounted from a remote computer on the network
might help shield users from data loss in the event of a system hardware failure.

Use the Contents of the /proc Directory to Interact with the Kernel

The content of the /proc directory is created from memory and only exists while Linux is running. This directory contains special “files” that either
extract information from or send information to the kernel. Many Linux utilities extract information from dynamically created
directories and files under this directory, also known as a virtual file system. For example, the free command obtains its information from a file named meminfo:

The /proc directory can also be used to dynamically alter the behavior of a running Linux kernel by echoing numerical values to specific
files under the /proc/sys directory. For example, to turn on kernel protection against one type of denial of service (DOS) attack known as SYN flooding, use the echo command to send the number 1 (one) to the following /proc path:

# echo 1 >/proc/sys/net/ipv4/tcp_syncookies

NOTE

The Linux kernel has a number of built-in protections, but good system administration security policies and a secure firewall
protecting your gateway, router, or Internet-connected system are the best protection you can use. See the section “Securing
Your Network” in Chapter 18 for an overview of firewalling and examples of how to implement Red Hat’s network security tools included with Fedora.

Other ways to use the /proc directory include

Getting CPU information, such as the family, type, and speed from /proc/cpuinfo.

Viewing important networking information under /proc/net, such as active interfaces information under /proc/net/dev, routing information in /proc/net/route, and network statistics in /proc/net/netstat.

Retrieving file system information.

Reporting media mount point information via USB; for example, the Linux kernel reports what device to use to access files
(such as /dev/sda) if a USB camera or hard drive is detected on the system. You can use the dmesg command to see this information or find information about these devices under the Device File System directory /proc/devfs (see the Linux Devfs FAQ at http://www.atnf.csiro.au/~rgooch/linux/docs/devfs.html if the source code for the Linux kernel is installed). The file /usr/src/linux-2.6/Documentation/usb/proc_usb_info.txt contains general information about USB and the /proc directory, as well as what to expect in files under this directory. Note that devfs might be supported, but will generally be obsolete in the 2.6 kernel because /proc/udev replaces it as a way of managing hot-plug devices on your system.

Getting the kernel version in /proc/version, performance information such as uptime in /proc/uptime, or other statistics such as CPU load, swap file usage, and processes in /proc/stat.

Work with Shared Data in the /usr Directory

The /usr directory (nearly 5GB in size if you do a full install) contains software applications, libraries, and other types of shared
data for use by anyone on the system. Many Linux system administrators give /usr its own partition. A number of subdirectories under /usr contain the X Window System (/usr/X11R6), man pages (/usr/share/man), software package shared files (/usr/share/name_of_package, such as /usr/share/emacs), additional application or software package documentation (/usr/share/doc), and an entire subdirectory tree of locally built and installed software, /usr/local.

Temporary File Storage in the /tmp Directory

As its name implies, the /tmp directory is used for temporary file storage; as you use Linux, various programs create files in this directory. The /tmp directory is cleaned of stale files each day by the tmpwatch command. (A stale file is any file not used after 10 days.) Fedora is configured by default to use tmpwatch to check /tmp each day by settings in your system’s scheduling table, /etc/crontab.

Access Variable Data Files in the /var Directory

The /var directory contains subdirectories used by various system services for spooling and logging. Many of these variable data files,
such as print spooler queues, are temporary, whereas others, such as system and kernel logs, are renamed and rotated in use.
Incoming electronic mail is usually directed to files under /var/spool/mail.

Linux also uses /var for other important system services. These include the topmost File Transfer Protocol (FTP) directory under /var/ftp (see Chapter 24, “Remote File Serving with FTP”), and the Apache web server’s initial home page directory for the system, /var/www/html. (See Chapter 21, “Apache Web Server Management,” for more information on using Apache.)