-->

Previous | Table of Contents | Next

Page 291

Part V

Administering Your System

Hour

  1. Basic System Administration
  2. Handling Files
  3. Red Hat Tools
  4. Archiving
  5. Scheduling

Page 292

Page 293

Hour 20

Basic System Administration

This hour introduces you to the basics of system administration. You'll learn how to use the su command, get information about your system, how to manage other users, and how to use file tools to keep Linux running in top form. Although much of what's discussed in this hour consists of commonsense guidelines, you'll also get some valuable tips on squeezing the best performance out of Linux. You'll also use this knowledge in the next four hours, which cover handling files, the Red Hat control panel, archiving, and scheduling.

Even if you're the only person who uses your computer, you should still learn basic system administration, or sysadmin, skills, for at least some of the following reasons:

Page 294

Here's a good reason that you should never run your system as the root operator: Always running as root can be dangerous because you have access to all files on the system, and can delete, move, or copy them all. You can wipe out your system (remember the warning in Hour 5, "Manipulation and Searching Commands," about the rm command) with this command:


# rm -fr /*

If you run Linux from your own account, this problem won't happen, because rm will complain with "Permission denied," and quit. But what if you're logged in under a user other than root, and you need to do things to your system as the root operator? This is where the su command comes into play.

Running as the Root Operator with the su Command

The su command, although commonly called the superuser command, allows you to run a command as any user on your system. Found under the /bin directory, su has seven different command-line options. Several of the most common are covered here. Although you'll most likely use su to become root, this command can be handy if you want to become another user and troubleshoot such problems as email or printing. Using the su command is easy, for example:


# su

Password:

su: incorrect password

By default, the su command will allow you to become the root operator if you call it without a username. You'll be asked to enter a password, and su will complain and quit if you enter the wrong one. If you enter the right password, you'll be logged in as root. To return to your shell, use your shell's exit command, as follows:


$ su

Password:

# whoami

root

# exit

exit

$ whoami

bball

This shows that after you execute the exit command, you're returned to your normal user status. Another handy feature of the su command is the -s command-line option to run a different shell. If you want to try a different shell without using the chsh command to permanently change your shell, you can use the following:


$ printenv | SHELL

SHELL=/bin/bash

$ su -s /bin/ksh

Page 295


Password:

# printenv | fgrep SHELL

SHELL=/bin/ksh

# exit

$

This shows that although the default shell is bash, you can temporarily use the pdksh, or public domain Korn shell. But unless you specify your own username, you'll run the new shell as the root operator. A better approach is


$ su -s /bin/ksh yourusername

Finally, you can also use the su command to execute a command when you use the -c command-line option. This can be handy to do tasks only permitted to the root operator, for example:


# su -c "mount -t msdos /dev/hdc1 /mnt/flash"

Password:

This command line mounts the /dev/hdc1 device, a SunDisk flash card with a DOS filesystem, at the /mnt/flash directory mount point. If you need to temporarily mount or unmount diskettes, CD-ROMs, or other devices, you'll find this a convenient approach. Hour 21, "Handling Files," covers mounting and unmounting other filesystems.

If you're using Linux in the console mode (not running X11), you can use the console keys (Alt-F1 and so on), to run a virtual console as the root operator to do root operator tasks. But this is a bad convenience, as you may be tempted to run as root all the time. At least using the su command makes you think about why you're running as root. Be careful!

The next section introduces you to tools you can use to determine how your system is working.

Getting Disk Space Information

When you installed Linux, you installed your system onto a partition, designated by a specific device, such as /dev/hda1, /dev/sdb1, and so on. Hopefully, you made the partition large enough to accommodate your present and future needs. But how do you check to see how much room you have left on disk, or for that matter, how many disks you have? Although Linux can support up to 4 terabytes, and maximum file sizes up to 2 gigabytes, not many of us are wealthy enough to own, or even need, that much storage. Even though disk storage is getting cheaper, it is still at a premium when you have a lot of software installed or need the work space.

Getting Filesystem Statistics with the df Command

Previous | Table of Contents | Next