3. Users

$Id: user.xml 2331 2009-04-18 12:59:52Z rafi $

Table of Contents

3.1. User related Commands

UNIX is a multi-user operating system, meaning that it is possible for several users to work concurrently on the same system. Thus, UNIX needs a way to identify the user for login and security purposes. This is where your user name and password comes into play. Each user has a user name and a password which identify him or her on the system. The users are stored in /etc/passwd.

On regular UNIX systems, there exists a user called root. Root is the most powerful user, because he literally can do as he please. The file permissions do not apply to him, he can configure the system, create and delete users, change passwords, reboot and halt the system, you name it. I mention this user only for completeness.

Users can belong to groups, which are a way to manage access to files (see also Section 5.4, “File and Directory Permissions”). Groups are a way to give several users (the group members) access to files and directories in one whoop. Users can be listed in several groups. Last but not least, each user has its own home directory as described in Section 5.1, “The Home Directory”.

3.1. User related Commands

User related Commands

id

Returns the “user identification”. On Sun Solaris the output looks like this

$ id
uid=1010(joe) gid=1010(joe)

On FreeBSD and Linux the output looks more confusing

$ id
uid=1001(joe) gid=1001(joe) groups=1001(joe),0(wheel),4(tty)
,92(gdm),99(video),700(cdrom),701(floppy),702(speaker),703(mou
nt),704(usb),1100(media),999(users)

The important thing with both outputs is the uid. The uid is the number internally assigned with your user name. UNIX does not think of users in terms of user names, but as uids. The user name is only provided for convenience, so you don't have to remember your uid.

groups

To find out to which groups you belong, type in the command groups. It will display all the groups you belong to. Groups are used to give access to files and directories as explained in Section 5.4, “File and Directory Permissions”.

who am i

If you need to find out as which user you are logged in (yes, this happens sometimes), type in the command who am i. On Linux it prints out something like this

$ who am i
joe     pts/1        2009-01-01 14:05 (salma.example.org)

in the first column, you will see your user name.

If you type only who, you will see who is also currently using the computer, as shown below

$ who
jack       console      Jan  1 12:21    (:0)
jack       pts/7        Jan  1 13:21    (:0.0)
joe        pts/4        Jan  1 16:04    (penny.example.org)
averell    pts/8        Jan  1 16:04    (penny.example.org)
william    pts/9        Jan  1 16:05    (uma.example.org)
joe        pts/10       Jan  1 16:06    (ava.example.org)
su

The su command lets you switch to another user (switch user).

$ id
uid=1006(jack) gid=1006(jack)
$ su - william
Password:
$ id
uid=1002(william) gid=1002(william)

The dash is used to make the user switch behave like a full login. After the dash, type the name of the user you want to switch to. Of course, you need to type in the user's password, else security would be compromised.

passwd

This command lets you change your password. The usage is simple, as shown by Example 4, “Changing the user password” (please note, that the messages may vary from UNIX to UNIX). After using this command, the next login you'll do, you have to enter your newly set password.

Example 4. Changing the user password

$ passwd
Changing password for joe
(current) UNIX password:
Retype new UNIX password:
passwd: password updated successfully

Important

UNIX is case-sensitive, so please make sure you remember the capitalization of the letters, else you will be locked out from your account.