Logging In
Before you can use Linux, you must enter a user name and password to log in, even if you are the only user. The reason for this is that Linux (like other Unices), is designed to be a multiuser system. Windows/MS-DOS was designed to be a single-user system (except for Windows NT).
A simple analogy to explain the difference between single-user and multi-user systems is the difference between an apartment building and a single-family house. In the house there is usually one front door, and one family lives in the building. In Windows you turn on the computer and start using it, just as to enter a house you unlock the front door and walk inside. In Linux there can be many users, just as in an apartment building there are many people living in the same building. There is a front door that you walk through, but there is also the door to your individual apartment, to which only you have access. The individual apartments are like different user accounts on a Linux system.
There are two ways to start the login screen in Linux. One way, called runlevel 5, starts the X graphical interface automatically when you start up Linux. A graphical login box appears in a window on the screen (just like in Windows NT). When you enter your username and password, the desktop appears, just like in Windows or Macintosh.
When you installed Red Hat 7.0, you were asked if you wanted X to start automatically whenever you booted your computer. If you answered Yes, then your Linux system starts in runlevel 5.
Another way to start Linux is the non-graphical way called runlevel 3. At runlevel 3, when startup is complete, the login: line appears on a blank screen (some distributions display a simple text-based graphic as well). After you enter your user name and password, a new line appears with nothing but your username, the name of your computer, and a $ sign, like this:
judith@localhost$
Rather than being in a graphical environment, you are in a shell environment. The $ sign is called the shell prompt, or sometimes the command line. There are different shell environments, such as bash, csh, ksh, sh, and zsh, but Red Hat Linux uses bash by default. In fact, most Linux users use bash.
You can start a graphical environment from the command line, but we won't talk about that until Hour 6, "XFree86The Linux Window System."
For the rest of this hour and for Hours 4 and 5, we will assume that you are in a shell environment. If your Linux system starts at runlevel 5 (in a graphical environment), there are two ways to drop into a shell:
-
You can press Ctrl+Alt+F2 (or any other function key, except for F7) to open a virtual terminal.
-
You can open an xterm, which is a shell environment within the X environment. To open an xterm, click the computer icon on the panel, as shown in Figure 3.3, or (assuming you're in GNOME), click Main Menu, System, GNOME terminal.
A virtual terminal is one of the niftier tools you can use with Unix. Unix is not only multi-user in the sense that multiple users can use the same computer, it is multi-user in the sense that multiple users can use the same computer at the same time. You can hook up multiple terminals to the computer, or you can use virtual terminals. To use a virtual terminal, press Alt+F[1-12], which means press the Alt key plus any of the function keys (you can go up to as many virtual terminals as your system supports). You are presented with a completely new login screen and you log in as a new user. You can log in as yourself multiple times, or you can log in as a completely different userit doesn't matter. If you are in X, you can open a new virtual terminal by pressing Ctrl+Alt+Fx. To return to X, press Alt+F7. (If you are running an X session, F7 is reserved for X.) Virtual terminals are particularly useful if you want to run several processes at one time in the foreground (we'll talk about running processes in the foreground and the background later).
Why You Should Not Log in As Root
Now that you know about multiple logins and virtual terminals, it is time for the advice that every new Unix user gets. The root account is intended for administrative use only. Do not login as root unless you must do so to perform an administrative task.
Some new users get into the bad habit of using root for everything. This is bad for several reasons: You can inadvertently destroy important files. You can do irreparable damage to your filesystem or wreak havoc with system processes. Also, if you are connected to a network, being logged in as root is a potential security hole for a cracker to get into your system.
If you log in as root all the time, you increase your chances of making a simple error that can cost you hours of recovery time. If you are the administrator of your system, there is a simple command called su, which enables you to assume the identity of root or any other user (if you know the password). It is much better to log in as an ordinary user, then use the su command to give yourself administrative privileges to perform a task. This is also called becoming the "superuser." If you simply type
$ su
followed by the root password, you will assume the root identity. If you type
$ su other_username
followed by other user's password, you will assume that user's identity.
When you become the superuser, look twice at every command you enter to make sure that it is what you intended. When you are finished with the administrative task, type
# exit
You will re-assume your ordinary user identity.
Do not log in as root, unless you must do so to administer the system. Instead, use the su command to assume root status. Then, carefully review each command you type before pressing Enter. Carelessness can cause a lot of damage!