Managing Linux Users and Groups

Test Objective Covered:

Manage the Linux file system.

In the previous chapter, you were introduced to the Linux file system. In
this chapter, we will explore that file system in more depth and specifically
focus on how Linux keeps information in the file system secure.

Linux File System Security

Recall from earlier discussions that Linux is a multiuser operating system.
When you installed your SUSE Linux server, you created two users: root and
student. You could also create many other users. Depending on how the system is
utilized, you could even have dozens or even hundreds of users.

This is a very powerful aspect of Linux, but it also presents some problems.
Suppose you have four users on your systemroot, Kimberly, Josh, and
Jessicaand each user had full access to all the files on the system.
Kimberly uses the Linux system to edit digital video, which involves using very
large files. Josh uses the system to prepare reports and spreadsheetsvery
small files in comparison to Kimberly's.

When Josh logs in, he notices that the system is low on disk space and
decides to clean off some files. Of course, he doesn't want to delete any
of his own files, so he probes through the file system looking for entries owned
by other users and notices that that some of Kimberly's files are over 12GB
in size. Josh feels that these files are obviously wasting space and decides to
delete them.

Josh also probes into the /usr/bin directory and decides to delete
some of the files found there as well. Who needs files with funny names such as
"grep" and "dig" anyway?

Imagine how Kimberly feels when she logs back in, only to find her video
files gone. Imagine how root feels when it is discovered that some
administration files are missing. This is definitely not good.

Windows and Multiple Users

If you use an older version of Microsoft Windows, such as Windows 95 or 98,
this is exactly the situation you could encounter. These operating systems allow
you to create individual user accounts. Each user, however, has full access to
every file in the file system, including the operating system files. This
presents a challenge for many system administrators.

To reduce expenses, many companies with multiple employee shifts assign users
in different shifts to use the same workstation. All too often, the day-shift
employee arrives to find that the swing- or night-shift employee had deleted his
or her files.

Later versions of Windows, such as Windows 2000 and XP, rectified this
problem by allowing the administrator to create user accounts that don't
have access to system files and that can't access other users'
files.

To prevent this situation, Linux implements a file system security system
that uses the following components:

Users

Groups

Permissions

Ownership

Each of these components are explored in the following sections.

Linux Users

As with other multiuser operating systems, Linux uses user accounts. During
the installation of a Linux system, one user account is always created by
default: root.

The root user account has full access to the entire system. Anyone logged in
as root can open, modify, copy, or delete any file in the file system. This user
account has a great deal of power and must always be used with discretion.

As mentioned earlier in this book, you should never log in as root to perform
routine, day-to-day work. This rule prevents two problems. First, it eliminates
the possibility of someone using your root account to wreak havoc on your system
while you're away from your desk. Second, it keeps you from accidentally
wreaking havoc on your own system. I'll explain why later in this
chapter.

For these reasons, you should always log in as a regular system user to
conduct your normal tasks on the system. When you need root-level access, use
the su  command at the shell prompt to switch to the root
account. When you're done, be sure to switch back to your regular account
with the exit command at the shell prompt.

Most Linux installation routines provide you with the ability to create one
or more regular user accounts during installation.

TIP

Some Linux distributions will require that you create at least one regular
user account during installation.

After installation, you can use YaST2 on a SUSE system to create new user
accounts. If you're working from within GNOME or KDE, just select
Applications, SUSE Menu, System, YaST2.

When you do, the YaST Control Center appears. Select Security and
Users and then select Edit and Create Users. The User and group
administration screen appears, as shown in Figure 3.1.

Notice that the passwd file is composed of lines of information. Each line
represents a single user account record. Seven individual pieces of
information appear on each line (or record). These are called fields and
are delimited by a colon (:) character. The fields, in order, are as
follows:

User nameThis is the name the user enters to log in to the
system.

PasswordNotice that each account appears to have a password
of "x"." That's because the passwd file doesn't
actually contain the user's passwords. This will be explained in more
detail later.

User IDThis is a number assigned by the system to each user
account. Each User ID is unique on the system. No two users can have the same
ID.

Group IDThis is the ID number of the group the user is a
member of. Multiple users can be members of the same group and, hence, have the
identical Group ID numbers.

Full nameThis is the user's full name. This parameter
is optional.

Home directoryThis is the path to the user's home
directory in the file system.

ShellThis is the default type of shell that will be
presented to the user.

If you look closely at Figure 3.2, you'll notice that each user account
appears to be assigned a password of x. That's because user passwords
aren't actually stored in the passwd file.

To prevent this, user passwords are stored in encrypted format in the
shadow file located in the /etc directory. A typical shadow file
is shown in Figure 3.3.

It is possible to install your Linux system such that passwords are stored in
the passwd file. Depending on the Linux distribution you are using, you should
be presented with a screen during installation that asks if you want to shadow
your passwords (or text to that effect). You should always use shadow passwords.
If you don't, they'll appear in the passwd file.

Notice in Figure 3.3 that, like the passwd file, each line in the shadow file
represents a user record. Each user record has nine fields delimited by
colons:

User nameThis is the same name as is used in the passwd
file.

PasswordThis field contains the user's encrypted
password.

Last changeThis field lists the date when the password was
last changed.

Minimum daysThis field lists the minimum number of days the
user can have the same password.

Maximum daysThis field lists the maximum number of days the
user can have the same password.

WarningYou can configure the system such that users are
prompted a couple days before their password expires. This field lists the
number of days prior to expiration that the warning is displayed.

Allow inactiveYou can configure the system such that users
can still log in for a couple days after their password has expired. This field
contains the number of days this is allowed.

ExpiresThis field lists the date that the user's
password will expire.

(Unused field)

To change these values on a SUSE system, you can use YaST. Access the Edit
and Create Users option and select the user you want to modify. Then select
Edit, Password settings. The screen shown in Figure 3.4appears.

Look closely at the record for the root user account. Notice that the
password appears to be a complex string of characters. This is actually the
password in encrypted form. The root password on this system is actually
novell. Because of this, you shouldn't directly edit the shadow file
with a text editor. You should use a system utility such as YaST to change a
user's password.

Linux Groups

Not only does Linux differentiate accounts by user, but it also uses groups.
A group is simply a collection of user accounts. At first glance, groups
and users may seem somewhat redundant. Groups are very powerful management
entities, especially when you're working with a large number of user
accounts.

To illustrate, imagine that you have 40 user accounts on a Linux system. All
these users need the same permissions to a given set of directories in the file
system. Without groups, you would have to manually assign permissions to each
user.

TIP

Permissions will be introduced later in this chapter.

With groups, however, you can make all 40 user accounts members of a single
group. Then you can assign permissions just once to the group. Each of the
members of the group automatically receive the permissions that have been
assigned to the group.

As a general rule, you should create groups and assign permissions to them
first and add users to those groups. After that, assign individual permissions
to specific users who require access differing from that required by other
members of the group. The goal is to minimize the number of permissions assigned
directly to individual user accounts.

For example, suppose you have 40 users who all need the same level of system
access. You can create a group for these users, assign permissions to the group,
and make the 40 users members of the group. Further, suppose that one of the 40
users needs additional access beyond that provided by the group. You can then
assign additional permissions to that individual user.

Managing your system in this manner can greatly decrease your administrative
workload. Suppose you have the 40-user system mentioned previously and you
install a new application on the system. Each user needs access to the files for
that application. If you use groups to manage access, you simply need to make
one permission change. If, on the other hand, you chose to assign permissions to
each individual user instead of using groups, you need to make 35 changes.

On a 40-user system, that may not sound overwhelming. Instead of 40, however,
suppose you administer a Linux system that has several hundred users. The
difference in work required to manage permissions becomes much more
apparent.

When working with groups, you should keep in mind a couple important points.
First, only two users can change groups assigned to a file or a directory and
the associated permissions: root and the file/directory owner.

Second, you can't have a user account that isn't assigned to a
group. Each and every user must be a member of at least one group. On a SUSE
Linux system, every user is made a member of the users group, by default,
when the user account is created.

In Figure 3.5, user rtracy has just been created. You can see that
rtracy was made a member of the users group along with the student account we
created during the installation of the system.

It's important to note that users can be members of more than one group.
Users can switch to a different group (and receive the permissions of the new
group) by entering newgrp new_group_name at the shell prompt.
When they do, they'll be prompted to supply the new group's password,
discussed next.

Group information is stored in the group file located in the
/etc directory. This file is shown in Figure 3.6.

Just like the passwd and shadow files, each line in the group file represents
a record for an individual group. The fields within the record are delimited by
colons. The fields in the group file include the following:

Group nameThis field contains the name of the
group.

PasswordYou can, optionally, require that members of this
group supply a password when switching to the new group.

Group ID (GID)The GID is a unique number assigned to the
group.

Group membersThis field lists users who are assigned as
members of the group.

You probably noticed that, like in the passwd file, an x represents passwords
in the group file. If you configured your system to use shadow passwords during
installation (and you should), group passwords are saved in the gshadow
file in the /etc directory. A typical gshadow file is shown in Figure
3.7.