Donation?

Harley Hahn
Home Page

Send a Message
to Harley


A Personal Note
from Harley Hahn

Unix Book
Home Page

List of Chapters

Table of Contents

List of Figures

Chapters...
   1   2   3
   4   5   6
   7   8   9
  10  11  12
  13  14  15
  16  17  18
  19  20  21
  22  23  24
  25  26

Glossary

Appendixes...
  A  B  C
  D  E  F
  G  H

Command
Summary...

• Alphabetical
• By category

Unix-Linux
Timeline

Internet
Resources

Errors and
Corrections

Endorsements


INSTRUCTOR
AND STUDENT
MATERIAL...

Home Page
& Overview

Exercises
& Answers

The Unix Model
Curriculum &
Course Outlines

PowerPoint Files
for Teachers

Chapter 4...

Starting to Use Unix

When you take your very first lesson on how to use Unix, what you need to learn depends on how you will be accessing Unix. Will you be using Unix as part of a shared, multiuser system, say, at school or on the job? Or do you have a Unix computer of your own, in which case you will control the computer and be the only user?

In this chapter, we'll discuss the first situation: what it's like to use a Unix system that is maintained by someone else. I'll show you how to start and stop a work session, and I'll explain the basic concepts, such as system administrators, passwords, userids, users and superusers. As I explain ideas to you, I will assume that you are using a straightforward text-based interface.

In Chapter 5, we'll talk about the more complex situation, in which you are using your own Unix system installed on your own computer. In that chapter, we'll talk about the ideas underlying a graphical interface.

What if you are never planning to use Unix as part of a shared system? What if you will only be using your own computer and a graphical interface? Do you still need to read this chapter?

The answer is yes. No matter how you use Unix, the skills and ideas we are going to cover in this chapter are basic to Unix and important for everyone. (Besides, you don't want to miss the story about the Hotdog-bun Boy.)

Jump to top of page

The System Administrator

In the broadest sense, there are two ways in which you can access a Unix system. First, you might have your own Unix computer, in which case you are the only user and you are in charge of managing the system.

Alternatively, you might use a shared multiuser system — at school or at work — in which case you will be only one of the users. If this is the case, someone else will be in charge, so you don't have to worry about maintaining the system. However, you will have to follow some rules and work within certain limitations.

Of course, you may be able to access Unix in both ways. For example, you might use a shared system at school and your own PC at home.

Although having your own Unix computer sounds simpler, it actually isn't. The truth is it's easier to use a shared system. Because you don't own the system, someone else manages it for you, which is a very big deal.

All Unix systems require administration and maintenance. The person who performs these duties is called the SYSTEM ADMINISTRATOR, often abbreviated as SYSADMIN or ADMIN. (The old term, not used much anymore, is SYSTEM MANAGER.)

If the computer you use is owned by an organization — such as a university or a company — the admin will probably be a paid employee. Indeed, within organizations that have networks of Unix computers, system administration is a full-time job that calls for a great deal of specialized knowledge. There may be many admins with a staff of assistants.

Before the mid 1990s, it was very unusual for someone to have his or her own Unix computer. Most everyone who used Unix did so by accessing a shared system. Unix systems were maintained by an organization (usually a school or a company), and there were rules that all the users were required to follow.

Most of the time, people accessed Unix remotely, either by using a terminal or by using a PC to emulate a terminal (see Chapter 3). As such, the most common way to use Unix was with a text-based interface, using only a keyboard and a monitor (as we will be doing in this chapter). It was only a minority of users who used Unix with a graphical interface.

When have your own personal Unix computer, you are, for better or for worse, your own admin. At best, administering your system is a highly fulfilling activity, which will build your skills and confidence, making you feel that you are truly in control of your computing destiny. At worst, you will, at times, feel frustrated and confused.

To use Unix well, you need to understand a number of basic concepts: the file system, text editors, the shell, and so on, all of which I will teach you in this book. To be an effective administrator of a large system or a network, you need a lot more. You will have to master a great many esoteric skills, many of which are, alas, beyond the scope of this book. To manage your own personal system is a lot easier. All you will need is basic Unix skills and a thoughtful attitude.

Regardless, no matter how long it takes to learn to manage your own Unix computer well, I can assure you that system administration is always a learning experience. (If nothing else, you will, at least, learn patience.)

In the meantime, let's move ahead and see what life is like when someone else is managing the system for you.

Jump to top of page

Userids and Passwords

Before you can use a Unix computer, the system administrator must give you a name that you will use to identify yourself to the system. This name is called your USERID. The word userid is a contraction of "user identification", and is pronounced "user-eye-dee".

Along with the userid, you will also get a PASSWORD, which you will have to type in each time you start a work session.

Once you have permission to use a Unix system, we say that you have an ACCOUNT on that computer. Even though you aren't paying real money for your account, Unix will keep track of how much you use the system. (Unix comes with a lot of built-in accounting, which your system administrator can use to keep records of who is doing what.) In addition, your account will probably come with certain predefined limits, such as how much disk space you are allowed for your files, or how many pages you can print.

If you are a student, one limit you are likely to encounter is an expiration date on your account. For example, your account may terminate automatically at the end of the semester, which only makes sense.

What will your userid be? In most cases, your system administrator will choose a userid for you. One common method is to base the userid on the person's real name. For example, for the name Harley Q. Hahn, the userid might be harley, hahn, hhahn, harleyh or hqh.

Alternatively, your userid may reflect some completely objective criteria. For example, if you are a student and you are the 25th person in the CS110 class to ask for a Unix account, you might be assigned the userid cs110-25.

Each time you start a Unix session, you must enter your userid. From then on, this name is used by Unix to identify you. For example, when you create files, they will not belong to you; they will be "owned" by your userid. (We'll talk about this distinction later in the chapter.)

It is important to understand that userids are not secret. For example, if you use Unix for email, your userid will be part of your address. Moreover, at any time, it is easy for anyone to display all the userids that are currently using the system and — if you know what you are doing — you can even display a list of all the userids that are registered with the system.

Security, of course, is important, but it does not require that userids be secret. Rather, security is maintained by making sure that passwords are secret. In this way, everyone can find out who else uses the computer, but access to the system is controlled.

Your password will probably be a meaningless group of characters, such as H!lg%12, something which is difficult for someone else to guess. Later in the chapter, I'll explain how to change your password if you don't like it, and what types of passwords are good to use.

Jump to top of page

Logging In (Starting Work with Unix)

When you sit down in front of your terminal, the process you go through to start work is called LOGGING IN. Although the idea is simple, the terminology is a bit tricky.

When we talk about the idea as a verb, we write two words, "log in". When we express the same idea as a noun or an adjective, we use a single word LOGIN.

For example, "In order to log in, you need to learn the login procedure." Or, "We need a larger computer. Our current one gets over 500 logins a day; there are too many people trying to log in at the same time."

The actual login process is straightforward. All you need to do is type your userid and your password. Here is how it works.

When a Unix program wants you to type something, it displays a PROMPT, a short message indicating that you must enter input from the keyboard. When Unix wants to show that it is waiting for you to log in, it displays the following prompt:

login:

Unix is saying, "Type your userid and press the <Return> key."

Although this seems straightforward, I would like to pause for a moment to answer an important question: What, exactly, is the <Return> key?

In Chapter 7, you will learn that Unix uses a set of special keys that do not necessarily correspond to the exact same physical keys on every keyboard. We'll talk about the details then. For now, all I want you to know is that Unix has a special key that you press to indicate you have finished typing a line of input. This key is called the <Return> key. When you press the <Return> key, it sends Unix a signal called a newline.

If your keyboard has an actual <Return> key, pressing it will send the newline signal. (This is the case with a Macintosh.) Otherwise, you send the newline by pressing the <Enter> key (which is the case with PCs). Thus, throughout this book, when I tell you to press <Return>, use either the <Return> key or the <Enter> key, whichever you have on your particular keyboard.

Once you have typed your userid and pressed <Return>, Unix asks for your password by displaying the following prompt:

Password:

As you type, you will notice that your password is not echoed. This is to prevent other people from seeing your password if they happen to be looking over your shoulder. (Remember, in Unix, userids are not secret but passwords are, which is why, when you log in, userids are echoed but passwords are not.)

Notice also that, unlike Windows, when you type a password, the system does not display an asterisk for each character. This means that if someone is watching you, he not only can't see your password, but he doesn't even know how many characters you typed.

After you have typed your password, press <Return> once again. Unix will check to confirm the password is valid. If it is, Unix will complete the login process and you will be ready to start work.

If either your userid or password was incorrect, Unix will display:

Login incorrect

and let you try again. If you are connecting remotely, some systems will disconnect you if you log in incorrectly too many times. This is to make it difficult for someone who is trying to break into the system to keep guessing passwords indefinitely. (Typically, you get 3-5 tries. The exact number is controlled by the system administrator.)

As you type your userid and your password, there are three important things I would like you to remember.

• Be careful not to confuse the number 0 (zero), with the capital letter O (oh).

• Be careful not to confuse the number 0 (zero), with the capital letter O (oh).

• Be careful not to confuse the number 1 (one), with the small letter l (el).

Before we finish this section, I want to point out a curious thing that very few people notice. On virtually all Unix systems, the login program displays login: with a small "l" and Password: with a capital "P". No one knows why.

— hint —

Whenever you type a userid, Unix always asks for a password, even if that particular userid is invalid. This makes it more difficult for evil-minded people to guess userids.

For example, if someone enters the userid harley, he or she will always be asked for a password, even if there is no such userid registered with the system.

Of course, this also means that if you mistype your userid or your password, you won't know which one was wrong. You will just be told that your login was incorrect.

What's in a Name?

The <Return> key


Today, most keyboards have an <Enter> key, not a <Return> key. Why, then, does Unix use the name <Return>?

The use is traditional. As I explained in Chapter 3, for many years Unix was accessed from terminals, not from PCs, and it happened that all terminals had a <Return> key. Even though there are now countless PC keyboards with <Enter> keys, the Unix terminology has not changed.

The name "Return" comes from typewriters. In the olden days, the part of a mechanical typewriter that held the paper was called the "carriage". Each time you put in a new piece of paper, the carriage would start at the far right. As you typed, the carriage would move to the left one character at a time.

When you came to the end of a line, you would use your left hand to push a lever that would move the carriage back to the right. At the same time, the lever would also move the paper up one line. In this way, the paper would be positioned at the start of a new line.

The first Unix terminals were Teletype ASR33 machines (see Chapter 3). Unlike typewriters, they did not have a movable carriage. However, while printing text, changing from the end of one line to the beginning of the next did involve two separate motions. These motions were analogous to what happened when you pushed the lever on a typewriter, so they were described using typewriter terminology and referred to as CARRIAGE RETURN and LINEFEED. (These two terms are still important in the world of Unix, and you will meet them time and again.)

Figure 4-1 shows a photo of the Teletype ASR33 keyboard. Notice that there is both a <Linefeed> key and a <Return> key. This is why, to this day, Unix still refers to the key that terminates a line of text as the <Return> key.

Figure 4-1: Keyboard of the Teletype ASR33

The keyboard of the Teletype ASR33, the very first device used as a Unix terminal. Notice the <Linefeed> and <Return> keys (on the far right of the second row).

Jump to top of page

What Happens After You Log In?

After you log in successfully, Unix will display some informative messages, followed by an invitation to enter a command. You can then start your work session by entering one command after another.

The informative messages you see will vary, depending on how the system administrator has configured your system. Figure 4-2, for example, has a typical example from a FreeBSD system:

Figure 4-2: Login messages

After you log in successfully, you will see welcome messages. In this example, we see typical messages displayed by a FreeBSD system.

Last login: Sat Jun 28 17:02:18 on ttyp1

Copyright 1980,1983,1986,1988,1990,1991,1993,1994
The Regents of the University of California.
All rights reserved.

FreeBSD 4.9-RELEASE: Wed Mar 8 16:26:07 PDT 2006

Welcome to FreeBSD!

The first line shows us the last time we logged into this computer using the current userid. At the end of the line, we see ttyp1, which is the name of the terminal that was used at the time.

Whenever you log in, take a minute to check this line; it is here for security reasons. If the time you see is more recent than you remember, someone else may have been using your account without your permission. If so, change your password immediately. (I'll explain how to do so later in the chapter.)

The next three lines contain copyright information. As you will recall from Chapter 3, FreeBSD is based on work done at U.C. Berkeley, so it is understandable that the University of California is named as the copyright holder.

The second to last line shows we are using FreeBSD version 4.9. The date and time show that the kernel was "built" -- that is, generated -- March 8, 2006 at 4:26 PM. (Unix uses a 24-hour clock.)

Finally, the last line is a welcome greeting put there by a friendly FreeBSD programmer.

What happens after the login message is displayed depends, in part, on how your system was set up. As part of the login process, Unix executes a list of predefined commands that are kept in special initialization files. Some of these files are controlled by the system administrator, so he can ensure that specific tasks are carried out each time someone logs in. For example, he may want to display a specific message to all the users whenever they log in.

Aside from the general initialization files, each userid has its own personal initialization files which can be customized. The first time you log in, your initialization files will contain whatever default commands your system administrator has put in it. As you become more experienced, you can modify these files to suit your preferences. For example, you might have Unix execute a certain program each time you log in.

We'll talk about these files in Chapter 14, after we discuss the details and basic concepts involved in using the shell. (As I mentioned in Chapter 2, the shell is the program that reads and processes your commands.)

Jump to top of page

Getting Down to Work: The Shell Prompt

Once the initialization commands have finished executing, you are ready to start work. Unix will start the shell and pass control to it. The shell will then display a prompt — called the SHELL PROMPT — and wait for you to enter a command. To do so, you type the command and press the <Return> key. The shell will then process the command appropriately, usually by running a program.

For example, if you enter the command to start your email program, the shell will see that the program starts properly and will give it control. When the email program terminates, control will return to the shell, which will display a new prompt and wait for another command.

Eventually, when you have no more commands to enter, you will end your work session by logging out (explained below), at which time the shell will stop running.

It is very important to know when the shell is waiting for you to enter a command. For this reason, the shell prompt is chosen to be particularly distinctive.

Within the world of Unix, there are many different shells, and the actual prompt depends on which shell you are using. The three most popular shells are (in this order) Bash, the C-Shell, and the Korn Shell. I'll talk about each of them in detail later in the book (Chapters 12-14). For now, all I want you to know is what the basic shell prompt looks like for each particular shell.

For Bash and for the Korn shell, the prompt is a dollar sign:

$

For the C-Shell, the prompt is a percent sign:

%

If your system administrator has customized your environment, the prompt may be somewhat different. For instance, it may show the name of the machine you are logged into such as:

nipper$

In this case, the prompt shows us that we are logged into the machine called nipper. As you get more advanced, you can customize your shell prompt in many different ways. However, one thing that you should never change is the very last character of the prompt (the $ or the %). This character is a reminder that the shell is running and that it is waiting for you to type in a command. And, because the various shells use different prompts, this character is also a reminder of what shell you are running. (It is true that both Bash and the Korn shell use the $ prompt, but it's not difficult to remember which shell you are using so, for practical purposes, there is no real ambiguity.)

Regardless of which shell you are using, once you see the prompt, you can type any command you want and press the <Return> key. If you are logging in for the first time and you would like to practice, try the date command to display the time and date; the whoami command to display your userid; or the who command to display the userids of all the people who are currently logged in. If you want to snoop a bit more, try the w command. It tells you who is logged in and what they are doing.

Jump to top of page

Logging Out (Stopping Work with Unix):
logout, exit, login

When you are finished working with Unix, you end your session by LOGGING OUT. (When we refer to this idea as a noun or adjective, we use a single word, LOGOUT.) You log out to tell Unix that you are finished working under the current userid. Once your logout is complete, Unix will stop your shell and end your work session.

It is important that you never forget to log out when you are finished working with a Unix system. If you were to just pick up and leave with your terminal (or computer) logged in, anyone could come by and use the Unix system under the auspices of your userid.

At the very least, you run the risk of someone fooling around under your userid. At the other extreme, some mischievous person might erase files (including yours) and cause all types of trouble. If this happens, you will bear some responsibility: leaving a terminal logged in in a public place is like leaving your car unlocked with the keys in the ignition.

There are several ways to log out. First, you can wait until you see the shell prompt and then press <Ctrl-D>. (Hold down the < Ctrl> key and press the <D> key at the same time.)

When you press <Ctrl-D>, it sends a signal called eof or "end of file". Essentially, this tells the shell that there is no more data coming. The shell terminates, and Unix logs you out. (We will discuss the Unix keyboard in detail in Chapter 7.)

As you will find out later, the end-of-file signal has other uses, and it is altogether possible that you might press <Ctrl-D> once too often and inadvertently log yourself out.

For this reason, there is a safeguard. Most shells have a way for you to specify that you do not want to log out by pressing <Ctrl- D>. Rather, you must enter a special command. In this way, it is impossible to log out accidentally.

It may be that your system administrator has set up your system so that, by default, you cannot log out by pressing <Ctrl-D>. If this is the case, you must use one of the specific logout commands. They are logout and exit.

To find out how you must log out with your system, try pressing <Ctrl-D>. If it works, fine. If not, your shell was set up to ignore <Ctrl-D>, and you may see a message like this:

Use "logout" to logout.

In this case, use the logout command. (Type "logout" and press the <Return> key.) If, instead, you see a message like this:

Use "exit" to logout

you will need to use the exit command.

One final way to log out is to use the login command. This tells Unix to log you out and then get ready for a new person to log in. After you are logged out, Unix will ask for a new userid by displaying the original prompt:

login:

This command is handy if you want to log out but leave your computer or terminal ready for someone else to log in.

— hint —

On some systems, the login command will not disengage you completely. Instead, login will change the userid temporarily but, officially, you will still be logged in under your original name. When the new person logs out, he will find himself back in your original session.

If this is the case on your system, you should not use login because it could allow someone else to end up logged in under your userid.

You can find out how your version of login works by testing it. Enter the login command. Then log in and log out, and see if you are back in your original session. If so, it is not safe to use login for logging out. Use logout or exit instead.

Jump to top of page

Upper- and Lowercase

Unix distinguishes between small letters and capital letters. For example, when we discussed possible userids, I used the examples harley and hahn, both of which start with a small "h". At the same time, I suggested a possible password, H!lg%12, which contains two small letters and one capital letter.

Some operating systems are designed to ignore the differences between small and capital letters, a notable example being Microsoft Windows. Unix (which is much older) was written to be more precise.

For convenience, we refer to small letters as LOWERCASE and capital letters as UPPERCASE. The names come from typewriter terminology. When you use an old-fashioned typewriter, pressing the key moves the "upper" case into position to print capital letters.

— hint —

Within Unix, when you type names or commands, you must be sure to be exact. For example, if your userid is harley, you must type all lowercase letters when you log in. If you type Harley, Unix considers it to be an entirely different userid. Similarly, when you log out, you must type logout, not Logout.

When a program or an operating system distinguishes between upper- and lowercase, we say that it is CASE SENSITIVE. Thus, we can say that Unix is case sensitive, and Windows is not.

Since Unix considers uppercase letters to be different from lowercase letters (as, indeed, they are), it is possible for a system administrator to assign two different userids that differ only in the case of the letters, for example, harley and Harley. In practice, however, you would never see such userids, because it would be too confusing. In fact, it is the custom to use only lowercase letters for userids.

In order to maintain scrupulous accuracy in this book, I will not capitalize command names, even when they come at the beginning of a sentence. For example: "logout, exit and login are three commands that you can use to log out."

Please appreciate that the distinction between upper- and lowercase applies only when you are logging in and entering Unix commands. When you use a program that works with regular textual data — for example, if you are using a word processor to create a document — you type in the regular manner.

Jump to top of page

A Sample Session with Unix

Figure 4-3 shows a short session with Unix. This example was created using a shared system on which several userids were logged in at the same time.

Figure 4-3: Sample Unix work session

login: harley
Password:

Linux weedly 2.6.22-14-generic Tue Jun 24 16:53:01 2008

The programs included with the Ubuntu system are
free software; the exact distribution terms for
each program are described in the individual files
in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the
extent permitted by applicable law.

Last login: Sat Sep 20 08:33:17 from nipper.harley.com

harley@weedly:$ date
Mon Sep 29 10:34:36 PDT 2008

harley@weedly:$ who
tammy  tty1   Sep 28 21:25
linda  pts/0  Sep 29 07:13 (static)
tammy  pts/1  Sep 29 09:31 (coco)
casey  pts/2  Sep 29 10:07 (luna)
alex   pts/4  Sep 29 10:27 (alpha.taylored-software.com)
harley pts/3  Sep 29 10:34 (nipper.harley.com)

harley@weedly:$ logout
Connection to weedly.wordsofwonder.net closed.

The session starts by logging in using userid harley. Notice that Unix does not echo the password.

After the userid and password are accepted, the Unix system identifies itself. In this example, you can see that we are using Linux on a computer named weedly.

The rest of the numbers show information about the kernel. The version of the kernel is 2.6.22-14-generic; it was built on June 24 at 4:53 PM. (Remember, Unix uses a 24-hour clock.)

Next come two messages regarding Ubuntu, which is the name of this particular Linux distribution.

After the Ubuntu messages is a line showing the last time we logged in under the same userid. The login was on September 20 at 8:33 AM, and the connection was made from a computer named nipper.harley.com.

Finally, the preliminaries are over, and we are presented with the shell prompt. In this case, the prompt is configured to display the name of the userid (harley), the name of the computer (weedly, and the $ character.

The $ indicates that we are using Bash for our shell, and that the shell is ready for us to enter a command.

We enter the date command, which displays the current time and date. (Unix does have a time command, but it does not display the time. Rather, it times how long it takes to execute a specified command.)

After the date command has displayed its output, we see the shell prompt again. We then enter the who command. This displays a list of all the userids that are currently logged in to the system.

The first column shows the userids. Notice that tammy (who happens to be the system administrator) is logged in from two terminals.

The second column — tty1, pts/0, pts/1, and so on — are the names of the terminals that are in use.

The third column shows the time that the userid logged in.

The final column shows the computers from which the users logged in. The first three computers (static, coco, luna) are on the same network as weedly. The last two are on remote networks, which is why we are shown longer names.

After the who command finishes, we see another shell prompt. We type the logout command, ending the session.

As I mentioned, userid tammy is logged in twice. Unix allows you to log in as many times as you want without logging out. However, you would normally use only one terminal at a time. In our example, tammy is the system administrator, so it's okay.

However, if you ever enter the who command and see yourself logged in to more than one terminal, you should figure out what is happening. You may have inadvertently finished a previous work session without logging out. Or, you may be running more than one X session (see Chapter 6), and each such session shows up as a separate terminal. Alternately, the explanation may not be so benign: someone may be using your userid without your permission.

Jump to top of page

Changing Your Password: passwd

When your Unix account is set up, the system administrator will assign you a userid and a password. System administrators usually have their own ways of organizing things, and you may not be able to get the userid you want.

For example, you may want to use your first name as a userid, but the system administrator may have decided that all userids should be last names. Don't fight with your system administrator. He or she has a great deal of responsibility — Unix systems are hard to manage — and is probably massively overworked.

You can, however, change your password on your own. Indeed, some system administrators use a facility called PASSWORD AGING to force you to change your password regularly for security reasons. (Password aging may also be used to prevent you from changing your password too often.) For example, you might be required to change your password every 60 days.

If your system has password aging and your password has expired, you will be notified the next time you log in. At that time, you will be forced to select a new password.

Aside from password aging, you can change your password voluntarily whenever you want (as long your system manager has no restrictions). To change your password, use the passwd command.

Once you enter the command, passwd will ask you to enter your old password. This proves you are authorized to make the change. Otherwise, anyone who walks by a terminal or computer that was left logged in could change your password.

Next, passwd will ask you to type the new password. Some systems require all passwords to meet certain specifications. For example, your password may need to be at least eight characters. If your new password does not meet the local criteria, you will be so informed and asked to enter a new choice.

Finally, passwd will ask you to retype the new password. Entering your new password a second time ensures that you did not make a mistake.

As you type the password, the characters will not be echoed. This prevents anyone from reading your new password over your shoulder.

What's in a Name?

passwd


To change your password, you use the passwd command. Obviously, passwd is a contraction of "password", so why isn't the command named password?

The answer is that Unix people like short names. As you learn Unix, you will encounter this tradition repeatedly. For example, the command to list your files is ls; the command to copy files is cp; and the command to show the status of processes (programs that are running) is ps. There are many more such names.

At first, leaving out a few letters seems unnecessary and even a bit odd, but once you get used to it, you will find the brevity to be comfortable.

Jump to top of page

Choosing a Password;
Hackers and Crackers

The reason we use passwords is to make sure that only authorized people are able to access Unix accounts. As you might imagine, there are always a number of bright people who take pleasure in trying to break into a system. Such people are called CRACKERS. (Note: You will often see troublemakers referred to as hackers. There is a difference, which I will explain below.)

Some crackers want only to match wits against the Unix security system to see if they can log in on the sly. Other crackers enjoy causing real damage.

Thus, it behooves you to (1) never tell your password to anyone, and (2) choose a password that is not easy to guess. Remember, if you give your password to someone who damages the computer system, you are responsible.

When you first get your Unix account, the system administrator will choose a password for you. Whenever you want, you can use the passwd command to change your password.

The rules for choosing a password are actually guidelines for what not to choose:

• Be careful not to confuse the number 0 (zero), with the capital letter O (oh).

• Do not choose your userid (such as harley), or your userid spelled backward (yelrah). This is like hiding the key to your house under the mat.

• Do not choose your first or last name, or any combination of names.

• Do not choose the name of a loved one or friend.

&Bull; do not choose a word that is in the dictionary, any dictionary.

• Do not choose a number that is meaningful to you, such as a phone number, important date (such as a birthday), social security number and so on.

• Do not choose a password that is even remotely related to Harry Potter, Star Wars, Monty Python, The Hitchhiker's Guide to the Galaxy, or any other part of the popular culture.

• Do not choose a keyboard sequence, such as 123456, qwerty, or 1q2w3e4r. There are password-guessing programs that look for this type of pattern.

• Do not use the password fred. Many people pick this password because it's easy to type, but it's also one of the first ones a cracker will try.

In addition, there are several routine precautions you should practice:

• Never write down your password on a piece of paper. (Someone is bound to find it after you lose it.)

• Change your password regularly (once a month works well).

Within the cracker community, there are programs that exist to guess passwords. Such programs not only make intelligent guesses (such as your first name, last name and so on), but they use large lists of probable passwords to see if any of them will work. For example, there are lists of dictionary words, first and last names, movie actors, movie titles, Internet addresses, U.S. zip codes, and much, much more, including words from foreign languages.

Thus, if you think of an idea that is well- known and amusing, chances are that the crackers have been there ahead of you. This is especially true for passwords that relate to popular movies, books, and TV shows. For example, if you are a college student, both Star Wars and Monty Python were cool long before you were born, and there is probably no name or term that you could use that is not in a widely distributed cracker's list.

Password cracking programs are far more successful than you would imagine, so protect yourself (and your files) by choosing wisely. The best idea is to make up a pattern of meaningless characters. For good measure, mix in uppercase, lowercase, numbers and punctuation. (Some systems will force you to use such mixtures.) As an example, consider the password H!lg%12, which I used earlier in the chapter. Such a password would be hard to guess.

If you suspect that someone knows your password, change it right away. If you are using a shared system and you forget your password, all you need to do is tell your system administrator. He or she can assign you a new password without knowing the old one. You can then change the new password to whatever you want.

An ideal password is one you can remember without writing down, but that no one will ever guess and that will never appear on a cracker's word list. One good idea is to start with a phrase or sentence that makes sense to you and create an abbreviation. Here are some examples:

dontBL8

("Don't be late")

tHd-bBic

(the Hotdog-bun Boy(*) is cool)

2b||~2b

(for C programmers: "To be or not to be")

wan24NIK8?

(random meaningless phrase)

You get the idea. Just be sure that, in the excitement of creating a totally cool password, you resist the temptation to tell someone just to show off how clever you are.

* Footnote

The Hotdog-bun Boy came home from school one day. His mother looked at him and said, "You look so unhappy. Did something go wrong in school today?"

"Yes," he answered. "I hate history class."

"Why is that?" asked the Hotdog-bun Boy's mother.

"Because we read and read, and we listen to the teacher talk, and we have to memorize so many facts, but we never learn anything about Hotdog buns."

"Now son," said the mother, "how many times do I have to tell you? History is written by the wieners."

What's in a Name?

Hacker, Cracker


There are two types of people who spend a lot of time programming: hackers and crackers. A HACKER is someone who spends his or her time working on useful (or at least benign) programming projects.

The word HACK is often used as a verb to indicate a larger-than-life devotion to programming. For example, "Elmo spent all weekend hacking at his file-sharing program."

Thus, the term "hacker" is often used in a positive sense, to describe someone who is capable of massive amounts of nerd-like effort. Similarly, "hacker" also refers to a clever person who knows how to utilize a computer to solve problems creatively.

Hackers are socially useful people, though rarely cool. The most financially successful hacker in the world is Bill Gates.

A CRACKER is a bad guy: someone who enjoys breaking into computer systems and doing things that people in authority do not want him to do. (Notice I say "him". For some reason — perhaps a genetic deficiency — virtually all crackers are male.)

A cracker is someone you would not want your sister to marry. A hacker in the family would be okay. It's just that everyone would receive their wedding invitations by email and, during the honeymoon, you would receive a daily email update of what the happy couple is doing, along with a Web address where you can find the latest photos of their trip and updated blog entries.

Jump to top of page

Checking If Someone Has Been Using Your Unix Account: last

Whenever you log in, look carefully at the initial message; most systems will tell you the time and date you last logged in. If you don't remember logging in at this time, somebody might be using your account.

To check further, you can use the last command. Simply enter last followed by your userid. For example, if you are logged in as harley, enter:

last harley

You will see some information telling you the last time, or last several times, you logged in.

If you accidentally enter the command without a userid:

last

you will see information about all the userids on the system. This may go on for some time, so if you want to terminate the command, press <Ctrl-C>. (Hold down the <Ctrl> key and press <C> at the same time.)

You might think it would be fun to enter the last command without a userid and spy on all the other people by seeing when they logged in. Well, you can if you want, but it gets boring real fast. If you have nothing to do, you will probably have more fun using one of the programs I describe in Chapter 8.

Jump to top of page

Userids and Users

A USER is a person who utilizes a Unix system in some way. However, Unix itself does not know about users: Unix knows only about userids.

The distinction is an important one. For example, if someone logs in using your userid, Unix has no way of knowing whether or not it is really you (which is why you need to protect your password).

In the world of Unix, only userids have a real identity. Userids, not users, own files, run programs, send email, log in, and log out. This means that if someone is able to log in using your userid, he will have the same rights as you do. He will be able to change your files, send email under your name, and so on.

Earlier in this chapter, we saw a sample session in which we used the who command to find out who was logged in. Figure 4-4 shows the output from that command.

Figure 4-4: Output of the who command

$ who
tammy   tty1   Jun 28 21:25
tlc     pts/0  Jun 29 07:13 (static)
tammy   pts/1  Jun 29 09:31 (coco)
casey   pts/2  Jun 29 10:07 (luna)
harley  pts/3  Jun 29 10:52 (nipper.harley.com)
alex    pts/4  Jun 29 14:39 (thing.taylored-soft.com)

Notice that you see only userids, not people's names. This is because Unix systems are populated by userids, not users.

Jump to top of page

The Superuser Userid: root

Within Unix, all userids are more or less equal, with one notable exception.

From time to time, it becomes necessary for the system administrator to have special privileges. For example, he or she may need to add a new user to the system, change somebody's password, update some software, and so on.

Toward this end, Unix supports a special userid, called root, that has extraordinary privileges. A person who has logged in using the root userid is allowed to do anything he or she wants. (Obviously, the root password is a closely guarded secret.) When someone logs in as root, we refer to him or her as the SUPERUSER.

At first, the name root may not make any sense. However, in Chapter 23, you will see that the basis of the entire Unix file system is called the "root directory". Thus, the name root refers to a very important part of Unix.

Most of the time, the system administrator will use his regular userid for regular work and will change to superuser only to do work that requires special privileges. Once the special job is done, the system administrator will change back to his regular userid. This prevents the power of the superuser from causing damage inadvertently.

For example, if you make a mistake entering the rm (remove) command, it is possible to erase files accidentally. If you are logged in under your own userid, the worst that you can do is erase your own files. If you are logged in as root, an ill-formed rm command could create widespread damage by erasing files all over the system.

— hint —

When the shell is ready to accept a command from you, it displays a prompt. The final character of the prompt shows you which shell you are using. For example, the Korn shell and bash use a $ character. The C- Shell uses a % character.

Regardless of which shell you are using, when you log in as superuser, your prompt will change to the # character. When you see the # prompt, be careful: the superuser has a lot of power.

Jump to top of page

Having Fun While Practicing Safe Computing

From its early days, Unix was designed for people working together who needed to share programs and documents, and who enjoyed helping one another. The basic design of the system assumes that everybody is honest and of good will. Even modern Unix, with its passwords and security measures, is not 100 percent bulletproof, nor is it meant to be. People who use Unix are supposed to respect other users.

Since Unix is so complex, there are always a few crackers who get a kick out of trying to beat the system. In some environments, young programmers who figure out how to break into a system and perform clandestine acts are tolerated, perhaps even admired for their ingenuity.

Not so in the Unix community. Crackers and troublemakers are tracked down and punished. For example, I mentioned earlier that there exist programs that are used to guess people's passwords. In some schools, just being caught running such a program is grounds for immediate expulsion.

However, the wonderful thing about Unix is that there are so many challenging and pleasant diversions. It is unlikely that you (as one of my readers) will ever become bored enough to get into real mischief. Nevertheless, if you are ever so tempted, please remember that system administrators are always overworked, and they have little patience with willful people who create unnecessary trouble.

If you find that you like Unix and you do have extra time on your hands, you can get a great deal of pleasure out of teaching and helping other people, two of the most important Unix traditions.

Jump to top of page



Exercises

Review Question #1:

What is the difference between a user and a userid?

Review Question #2:

What are four different ways to log out?

Review Question #3:

You suspect that someone has been using your Unix account without your permission. How do you check to see if this was the case?

Suppose you find out someone has been using your account, but you don't know who it is. How do you stop them?

Review Question #4:

What is the userid of the superuser?

Applying Your Knowledge #1:

Being able to change your password is a basic skill you must master before you start using Unix. Whenever you change your password, you should immediately test to make sure it works properly.

Use passwd to change your password to dontBL8 ("Don't be late").

Log out and back in again to make sure it works.

Then change your password back to what it was originally.

Test again to make sure it worked.

For Further Thought #1:

Unix is case sensitive; that is, it distinguishes between lower case (small letters) and upper case (capital letters). Microsoft Windows is not case sensitive. For example, in Unix, harley and Harley are two completely different names. With Windows, they are the same.

Why do you think the original Unix developers chose to make Unix case sensitive? Why did Microsoft choose to make Windows case insensitive?

Which do you prefer, and why?

For Further Thought #2:

When you use passwd to change your password, the program requires you to type the new password twice. Why?

For Further Thought #3:

Why is it important to have a superuser?

Jump to top of page