Google Search

 
Showing posts with label unix basics. Show all posts
Showing posts with label unix basics. Show all posts

Wednesday, July 25, 2007

Logging In to UNIX

Whether you use a remote PC or a workstation, you have to get the attention of UNIX. You can tell when you have its attention because it demands that you identify yourself by logging in. If you use a workstation, whenever UNIX has finished loading itself, it is immediately ready for you to log in (skip ahead to the section "Logging in: U(NIX) can call me Al"). You terminal users (X or otherwise), however, may not be as lucky.

Direct access

If you're lucky, your keyboard and screen are attached directly to the main computer, either because the main computer is the only one and you're sitting at it, or someone's rigged up a remote PC to log in directly. If so, it displays a friendly invitation to start working, something like this:

ttyS034 login:

Well, maybe the invitation isn't that friendly. By the way, the ttyS034 is the name UNIX gives to your terminal. Why doesn't it use something easier to remember, like Fred or Muffy?

This catchy phrase tells you that you have UNIX's attention and that it is all ears (metaphorically speaking) and waiting for you to log in. You can skip the next section and go directly to "Logging in: U(NIX) can call me Al."

If your UNIX system displays a terminal name, make a note of it. You don't care what your terminal's name is, but, if something gets screwed up and you have to ask an expert for help, the first thing the guru will ask is, "What's your terminal name?" If you don't know, the guru may make a variety of nerd-type disparaging comments. But, if you can say, "A-OK, Roger. That's terminal tty125," your guru will assume that you are a with-it kind of user and may even try to help you. (Even if her name isn't Roger.)

Yo, UNIX! — not-so-direct access

If you're using a PC with a modem, you probably have to tell the modem to call the UNIX system. Although all terminal emulators have a way to make the call with two or three keystrokes, all these ways are different, of course. (Are you surprised?) You have to ask your local guru for info.

After your terminal is attached to the computer, turned on, and otherwise completely ready to do some work, UNIX, as often as not, doesn't admit that you're there. It says nothing and seems to ignore you. In this way, UNIX resembles a recalcitrant child — firm but kind discipline is needed here.

The most common ways to get UNIX's attention are as follows:

  • Press the Return or Enter key. Try it two or three times if it doesn't work the first time. If you're feeling grouchy, try it 20 or 30 times and use a catchy cha-cha or conga rhythm. It doesn't hurt anything and is an excellent way to relieve stress.
  • Try other attention-getting keystrokes. Ctrl+C (hold down the Ctrl key, sometimes labeled Control, and press C) is a good one. So is Ctrl+Z. Repeat to taste.
  • If you're attached to UNIX through a modem, you may have to do some speed matching (described in a minute): Press the Break key a few times. If you're using a terminal emulator, the Break key may be disguised as Alt+B or some other hard-to-find combination. Ask your guru.

Two modems can talk to each other in about 17,000 different ways, and they have easy-to-remember names, such as B212, V.32, and V.32bis. (Bis is French for "and a half." Really.) After you call the UNIX system's modem with your modem, the two modems know perfectly well which way they're communicating, although UNIX sometimes doesn't know. Every modem made since about 1983 announces the method it's using when it makes the connection. Because the corresponding piece of UNIX code dates from about 1975, though, UNIX ignores the modem's announcement and guesses, probably incorrectly, at what's being used.

If you see something like ~xxx~~r.!" on-screen, you need to try speed matching. Every time you press Break (or the terminal emulator's version of Break), UNIX makes a different guess at the way its modem is working. If UNIX guesses correctly, you see the login prompt; if UNIX guesses incorrectly, you see another bunch of ~xxx~~~@(r)!" or you see nothing. If UNIX guesses incorrectly, press Break again. If you overshoot and keep Breaking past your matched speed, keep going and it'll come around again.

After a while, you learn exactly how many Returns, Enters, Breaks, and whatnots your terminal needs in order to get UNIX's attention. It becomes second nature to type them, and you don't even notice what a nerd you look like while you do it. You have no way around that last part, unfortunately.

Logging in: U(NIX) can call me Al

Every UNIX user has a username and password. Your system administrator assigns you a username and a password. Although you can and should change your password from time to time, you're stuck with your username.

Before you can start work, you must prove your bona fides by logging in; that is, by typing your username and password. How hard can it be to type two words? Really, now. The problem is this: Because of a peculiarity of human brain wiring, you will find that you can't enter your username and password without making a typing mistake. It doesn't matter whether your username is al — you will type Al, la, a;L, and every other possible combination.

UNIX always considers upper- and lowercase letters to be different: If your username (sometimes also called your login name) is egbert, you must type it exactly that way. Don't type Egbert, EGBERT, or anything else. Yes, your name is Egbert and not egbert, but your computer doesn't know that. UNIX usernames almost always are written entirely in lowercase. Pretend that you're a disciple of e. e. cummings.

When you type your username and password and make a mistake, you may be tempted to press Backspace to clear your mistake. If only life were that easy. Guess how you clear typing errors when you type your username and password? You press the # key, of course! (That probably made sense in 1975.) Some — but not all — versions of UNIX have changed so that you can use Backspace or Delete; you may have to experiment. If you want UNIX to ignore everything you have typed, press @, unless your version of UNIX has changed the command key to Ctrl+U (for untype, presumably — doubleplus-ungood). So, Egbert (as you typed your username), you may have typed something like this:

ttyS034 login: Eg##egberq#t

Finish entering your username by pressing Enter or Return.

After you type your username, UNIX asks you to enter your password, which you type the same way and end by pressing Enter. Because your password is secret, it doesn't appear on-screen as you type it. How can you tell whether you've typed it correctly? You can't! If UNIX agrees that you've typed your username and password acceptably, it displays a variety of uninteresting legal notices and a message from your system administrator (usually delete some files, the disk is full) and passes you on to the shell.

If UNIX did not like either your username or your password, UNIX says Login incorrect and tells you to start over with your username.

In the interest of security, UNIX asks you for a password even if you type your username wrong. This arrangement confuses the bad guys — but not nearly as much as it confuses regular users. So, if UNIX rejects your password even though you're sure that you typed it correctly, maybe you typed your username incorrectly.

Understanding Permissions in UNIX

Unlike some operating systems, UNIX was designed from the beginning to be used by more than one person. Like all multiuser systems, UNIX keeps track of who owns what file and who can do what with each file. Permissions attached to each file and directory determine who can use them.

Permissions come in three types:

  • Read permission: Enables you to look at a file or directory. You can use cat or a text editor to see what's in a file that has read permission. You also can copy this type of file. Read permission for a directory enables you to list the directory's contents.
  • Write permission: Enables you to make changes to a file. Even if you can write (change) a file, you can't necessarily delete it or rename it; for those actions, you must be able to write in the directory in which the file resides. If you have write permission in a directory, you can create new files in the directory and delete files from it.
  • Execute permission: Enables you to run the program contained in the file. The program can be a real program or a shell script. If the file doesn't contain a program, execute permission doesn't do you much good and can provoke the shell to complain bitterly as it tries (from its rather dim point of view) to make sense of your file. For a directory, execute permission enables you to open files in the directory and use cd to get to the directory to make it your working directory.

Rock groups, pop groups, and UNIX groups

Every UNIX user is a member of a group. When the system administrator created your username, she assigned you to a group. To see which group you're in, type id.

You see something like this:

uid=113(margy) gid=102(guest) groups=102(guest),101(book), 103(cheese)

Groups usually indicate the kind of work you do. UNIX uses groups to give a bunch of people (the accounting department, for example) the same permissions to use a set of files. All the people who work on a particular project are usually in the same group so that they can look at and perhaps change each other's files.

In Linux and BSD, you can be in several groups at a time, which is handy if you're working on several projects. To find out what groups you're in, type groups.

That's mine!

Every file and directory has an owner and a group owner. The owner is usually the person who made the file or directory, although the owner can sometimes change the ownership of the file to someone else. The group owner is usually the group to which the owner belongs, although the owner can change a file's group owner to another group.

Who can do what?

To see who can do what to a file, use the ls command with the -l option. Type this line:

ls -l myfile

You see something like this:

-rw-r--r-- 1 margy staff 335 Jan 22 13:23 myfile

If you don't specify a filename (in this case, myfile), UNIX lists all the files in the directory, which is often more useful. For every file, this listing shows all the following information:

  • Whether it's a file, symbolic link, or directory. The first character in the line is a hyphen (-) if it's a file, an l if it's a symbolic link, and a d if it's a directory.
  • Whether the owner can read, write, or execute it (as shown by the next three characters, 2 through 4, on the line). The first character is an r if the owner has read permission or a hyphen (-) if not. The second character is a w if the owner has write permission or a hyphen (-) if not. The third character is an x (or sometimes an s) if the owner has execute permission or a hyphen (-) if not.
  • Whether the members of the group owner can read, write, or execute the file or directory (as indicated by the next three characters, 5 through 7). An r, w, or x appears if that permission is granted; a hyphen (-) appears if that permission is not granted.
  • Whether everyone else can read, write, or execute the file or directory (as indicated by the next three characters, 8 through 10). An r, w, or x appears if that permission is granted; a hyphen (-) appears if that permission is not granted.
  • The link count, that is, how many links (names) this file has. For directories, this number is the number of subdirectories the directory contains plus 2 (don't ask).
  • The owner of the file or directory.
  • The group to which the file or directory belongs (group owner).
  • The size of the file in bytes (characters).
  • The date and time the file was last modified.
  • The filename — at last!

Permissions by number

It's not too difficult to figure out which permissions a file has by looking at the collection of rs, ws, and xs in the file listing. Sometimes permissions are written another way, however: with numbers. Only UNIX programmers could have thought of this method. (It's an example of lazy typists at their finest.) Numbered permissions are sometimes called absolute permissions (perhaps because they are absolutely impossible to remember).

When permissions are expressed as a number, it's a 3-digit number. The first digit is the owner's permissions, the second digit is the group's permissions, and the third digit is everyone else's permissions. Every digit is a number from 0 to 7. Table 1 lists what the digits mean.

Table 1: Absolute Permissions Decoded

Digit

Permissions

0

None

1

Execute only

2

Write only

3

Write and execute

4

Read only

5

Read and execute

6

Read and write

7

Read, write, and execute

Amazon