Adding Users
One of the most important activities in administering a Linux box is the addition of users. Here you'll find some simple examples to provide a foundation for future chapters. It is not intended to be comprehensive, but is a good memory refresher. You can use the command man useradd to get the help pages on adding users with the useradd command or the man usermod to become more familiar with modifying users with the usermod command.
Who Is the Super User?
The super user with unrestricted access to all system resources and files in Linux is the user named root. This user has a user ID of 0, which is universally identified by Linux applications as belonging to a user with supreme privileges. You need to log in as user root to add new users to your Linux server.
How to Add Users
Adding users takes some planning; read through these steps before starting:
1. | Arrange your list of users into groups by function. In this example there are three groups: parents, children, and soho:
Parents Children Soho
Paul Alice Accounts
Jane Derek Sales
| 2. | Add the Linux groups to your server:
[root@bigboy tmp]# groupadd parents
[root@bigboy tmp]# groupadd children
[root@bigboy tmp]# groupadd soho
| 3. | Add the Linux users and assign them to their respective groups:
[root@bigboy tmp]# useradd -g parents paul
[root@bigboy tmp]# useradd -g parents jane
[root@bigboy tmp]# useradd -g children derek
[root@bigboy tmp]# useradd -g children alice
[root@bigboy tmp]# useradd -g soho accounts
[root@bigboy tmp]# useradd -g soho sales
If you don't specify the group with the -g, Red Hat/Fedora Linux creates a group with the same name as the user you just created; this is also known as the User Private Group Scheme. When each new user first logs in, they are prompted for their new permanent password.
| 4. | Each user's personal directory is placed in the /home directory. The directory name will be the same as the user's username:
[root@bigboy tmp]# ll /home
drwxr-xr-x 2 root root 12288 Jul 24 20:04
lost+found
drwx------ 2 accounts soho 1024 Jul 24 20:33 accounts
drwx------ 2 alice children 1024 Jul 24 20:33 alice
drwx------ 2 derek children 1024 Jul 24 20:33 derek
drwx------ 2 jane parents 1024 Jul 24 20:33 jane
drwx------ 2 paul parents 1024 Jul 24 20:33 paul
drwx------ 2 sales soho 1024 Jul 24 20:33
sales[root@bigboy tmp]#
|
How to Change Passwords
You need to create passwords for each account. This is done with the passwd command. You are prompted once for your old password and twice for the new one:
User root changing the password for user paul:
[root@bigboy root]# passwd paul
Changing password for user paul.
New password: your new password
Retype new password: your new password
passwd: all authentication tokens updated successfully.
[root@bigboy root]#
Users might want to change their passwords at a future date. Here is how unprivileged user paul would change his own password:
[paul@bigboy paul]$ passwd
Changing password for paul
Old password: your current password
Enter the new password (minimum of 5, maximum of 8
characters)
Please use a combination of upper and lower case letters and
numbers.
New password: your new password
Re-enter new password: your new password
Password changed.
[paul@bigboy paul]$
How to Delete Users
The userdel command is used to remove the user's record from the /etc/passwd and /etc/shadow used in the login process. The command has a single argument, the username:
[root@bigboy tmp]# userdel paul
There is also an optional -r switch that additionally removes all the contents of the user's home directory. Use this option with care. The data in a user's directory can often be important even after the person has left your company:
[root@bigboy tmp]# userdel -r paul
How to Tell the Groups to Which a User Belongs
Use the groups command with the username as the argument:
[root@bigboy root]# groups paul
paul : parents
[root@bigboy root]#
How to Change the Ownership of a File
You can change the ownership of a file with the chown command. The first argument is the desired username and group ownership for the file separated by a colon (:) followed by the filename. In the next example we change the ownership of the file named text.txt from being owned by user root and group root to being owned by user testuser in the group users:
[root@bigboy tmp]# ll test.txt
-rw-r--r-- 1 root root 0 Nov 17 22:14 test.txt
[root@bigboy tmp]# chown testuser:users test.txt
[root@bigboy tmp]# ll test.txt
-rw-r--r-- 1 testuser users 0 Nov 17 22:14 test.txt
[root@bigboy tmp]#
You can also use the chown command with the -r switch for it to do recursive searches down into directories to change permissions.
 |