Unix Essentials Class

Introduction · Table of Contents · Unix vs. other operating systems · Getting Started · Fundamental UNIX Concepts · Unix Files · Directories · Introduction to the Korn Shell · The vi editor · Korn Shell Again · Hyper-Ad Home Page · Technical Tutoring Home Page · Recommended Books · Online Store

Getting started

Logging In · The Unix Command Line · Some basic commands · Changing a user password · Logging Out

The most irritating thing for UNIX beginners is getting started. There seems to be a lot one has to know just to use the system at all, unlike Windows where one can get away with intuition and pointing and clicking. We'll cover most of these little details in this section.

A. Logging In

The first irritation unfamiliar to Windows users is the concept of accounts. Every user of a UNIX system must log on to the computer using an existing account. Without an account (username/password) one cannot get on the system at all.

At the terminal in front of you, press the enter (return) key. You should get something like this:

login:

This is the login prompt. You must enter the username of an existing account on the system, then hit enter (we're going to assume from now on that hitting enter follows typing any command). The system then immediately prompts for the password for that account:

login: student
Password:
$

Several things are worth noticing here. In the first place, when you typed in your password, the screen did not show the characters you typed. This is deliberate, and is a security feature typical of UNIX. Once you entered your password, the screen shows a dollar sign. This is called the command prompt, and means the computer is waiting for you to enter a command.

Had you logged on as the root user, you would have gotten a different command prompt:

login: root
Password:
#

Suppose you screw up the password? Just try again!

login: student
Password:
Login incorrect
login: student
Password:
Login incorrect
login: student
Password:
Last login: Sat May 26 16:00:57 from homeboy1.hyper-home.com
$

Most systems will give you three tries to get your login right. If you mess up all three, either the terminal session locks up (requires the system administrator to intervene) or the remote access session dies, depending on how you are accessing the system. This is another deliberate security feature, one that forces most users to be careful when they are logging into a system. This feature makes guessing a password by trial and error very difficult.

Once you have logged in, you have started what is called a session. This is the interval between login and logout (exit). All work done on a UNIX computer happens during a session.

B. The Unix Command Line   

As mentioned above, after you entered your password, the screen shows a dollar sign, the command prompt. Anything you type is displayed and sent to the shell program. If the shell recognizes what you typed, the program will perform some action (or not - see examples below). The words you enter are called commands, and give specific instructions to the shell. If you type nonsense, the shell tells you:

$ frog
bash: frog: command not found

Sometimes a command will have no effect, and the result will simply be another command prompt:

$ cd
$

This is actually good - you know you can enter another command. If you don't get a command prompt back, the result can be confusing:

$ cat
dog
dog
frog
frog
what the hell?
what the hell?

Notice there is no command prompt - anything typed is just repeated, like an echo. What has happened here is that we've invoked a program ("cat") that feeds the input (whatever is typed) back to the output (what is written by the computer when we hit enter) and we're still in the program! To get out of this program, hit control-D (from now on, control <something> will be written ^<something>):

$

So using ^D is a way to exit a running program. In fact, you can exit the shell by hitting another ^D (but wait on this until a bit later).

C. Some basic commands

Now we can try some commands. Might as well start with the most basic:

$ whoami
student

The "whoami" command retrieves your username. This may seem trivial or silly, since you just logged in as student, but the command is surprisingly useful in a multi-user environment. One of the things UNIX operators have to do is become other users! Issuing many commands as many users can be confusing - you forget who you are, so this command is there to let you find the current user. A shorter command that returns the username plus some other info is "id":

$ id
uid=503(student) gid=504(student) groups=504(student)

This command returns the user id number or UID, the group id or GID of the user, and a list of all groups the user to which the user belongs.

So now we know who we are. What is the date and time?

$ date
Sat May 26 15:45:30 CDT 2001

Suppose we wanted to know who is currently logged onto the same computer?

$ who
root tty1 May 26 15:28
student pts/0 May 26 15:30

Maybe we'd like to see this month's calendar:

$ cal
May 2001
Su Mo Tu We Th Fr Sa
       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
27 28 29 30 31

Which computer am I on?

$ hostname
homeboy5

Clear the screen and put the prompt at the top:

$ clear

Where am I in the filesystem?

$ pwd
/home/student

This command stands for "present working directory" and tells you what directory you are currently in. Notice that we are in our home directory.

This is a very important and useful command - in navigating the vast UNIX filesystem, it is very common to forget where you are - so this command is there to remind you of your current location.

D. Changing a user password

To change your password, use the "passwd" command:

$ passwd
Changing password for student
(current) UNIX password:
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully

Make absolutely sure you remember what you typed in as your new password - you won't be able to change it back if you forget what you typed.

Let's try changing the password back to the original:

$ passwd
Changing password for student
(current) UNIX password:
New UNIX password:
BAD PASSWORD: it's WAY too short
New UNIX password:

We're in trouble now - just type in the same (new) password:

Password unchanged
passwd: Authentication token manipulation error
$

Fortunately, we were able to recover. It will take the root user to override this and restore the original password. The point is security again. Most modern UNIX systems won't allow ordinary users to put in a password that is too easy to crack. There are often elaborate rules about the number of characters, how many have to be numerals, and so on - IBM has published password rules and makes you change passwords every six months or so.

Pick a good password that is easy to remember and fits the rules. One way to do this is to take a word you can easily remember that has the letters E, I and O, enough characters to satisfy the rules, and substitute 3, 1 and 0 for the above letters respectively. There are plenty of other ways to generate good passwords. It helps if your password can be typed fast, making it harder for other people to watch you type it and figure out your password.

At many work places, computer security is taken very seriously. You can get in trouble for breaking the rules, especially if some hostile person in the workplace gets your password and either uses it for mischief or gives it out to others. Never give anyone else your password! System administrators never need it, and won't ask for it. There are no good reasons to give it to anyone.

E. Logging Out

When you are done with your work, you should exit from the shell:

$ exit
Red Hat Linux release 6.1 (Cartman)
Kernel 2.2.12-20 on an i686
login:

or

$ ^D
Red Hat Linux release 6.1 (Cartman)
Kernel 2.2.12-20 on an i686
login:

Exit is always available; some computers don't support ^D.

This ends your session and brings back the login prompt. If you leave the screen alone for a few minutes, it will blank out (a simple blank screen saver). Typing any key will bring up another login prompt - the shift key is often used for this, since it doesn't print any characters to the screen, although the enter key works, too.

In a multi-user environment, you should always log off if you are done or have to walk away from the computer for a few minutes. Failure to do this might very well allow some joker in your office to send your boss an embarrassing e-mail from you, destruction or alteration of your work, or other unfortunate disasters. Be advised: it is a security breach to leave an open session up on a computer. Don't do it, you'll regret it!