User and Group Management
Users and groups often need to be created and modified. This section revolves around those tasks. All users and groups have a numerical value. The numerical value for a user is uid. The numerical value for a group is gid. The system can auto generate these when you create users and groups, or you can specify these when creating them.
id¶
The id is a useful command. It gives you information about a user including the uid, gid, and any groups that user is associated with. If you run just the id command with no arguments it will give you information about your user. If you specify a user when running id it will give you information about that user.
groups¶
The groups command gives you a list of groups the user is a member of. If you run the groups command without any arguments, it will give you your groups. If you give an argument of another user it will give you the groups of that user.
User Management¶
User management is a key point to managing a linux system. The next sections will go over how to add, delete, and modify users.
useradd¶
useradd is the command used to adding a user to a system. I recommend reading through the man page as there are many switches to this command. useradd is called with useradd [options] new_username.
useradd examples
usermod¶
Often a user needs to be updated. This is done with the usermod command. Again there are many switches to this command, so please check the man page.
usermod examples
userdel¶
Group Management¶
Groups will also need to be managed on a system. This section is about adding, modifying, and deleting groups.
groupadd¶
There are a few switches to this command so checkout the man page. Most of the time this command will be used without any switches. The command is pretty simple: groupadd group_name.
groupadd examples
groupmod¶
This command allows you to modify a group. It has quite a few switches so check the man page.
groupmod examples
groupdel¶
groupdel allows you to delete groups from the system. groupdel has a few switches so check the man page, but most of the time you won't use those.
passwd¶
This utility manages password for accounts. Please check the man page for available switches. If it is called without any arguments it will change the password for the current account. -d or --delete deletes a password for an account. -e or --expire will expire the password making user change on next login. -l or --lock with lock the password so users cannot login with it. -S or --status shows the password status for an account -u or --unlock unlocks the password for an account. There are a few other switches so read the man page.
passwd examples
chage¶
chage command is useful to show information about an account and password. It can show when an account or password expires. It can show when a password was last changed. The minimum amount of days on a password, or the max amount of days on a password. Check the man page for switches.
chage examples
sudo¶
sudo is how to make a normal user execute something another users privileges. This is most commonly used to run things with root privileges. There is quite a bit of configuration to sudo. That will be gone over in another chapter. This section is more about the use. Please check the man page for switches. The most common ways to use it though will be sudo command, sudo -u different_user command, sudo -i, or sudo -u different_user -i.
sudo examples
which sudo user
When in an interactive sudo prompt you can forget which user you are. You can run the id command without any parameters to figure this out
Storage for user and groups¶
The information for user accounts is stored in multiple places. User account information is stored in /etc/passwd. Password hashes for users are stored in /etc/shadow. Group information is stored /etc/group. If you have privileges you can look at any of these files. One way to do that is with the cat command or getent command. cat displays the entire file. getent displays a single entry. See examples below
view user examples
Exercise¶
Note
On AWX https://tower.tuckhome.lan use the User Management - Setup, User Management - Grade, User Management - Cleanup.
Tasks¶
- create testuser1
- create testuser2 with a uid of 9999
- delete deluser
- make inactiveuser password locked
- add testgroup1
- add testgroup2 with gid 9998
- add expireuser to testgroup1 without removing any other groups
- delete group delgroup
- set expireuser to expire on 2027-12-01
- set password to testuser1 to P@ssw0rd!123
Solution
- create testuser1
- create testuser2 with a uid of 9999
- delete deluser
- make inactiveuser password locked
- add testgroup1
- add testgroup2 with gid 9998
- add expireuser to testgroup1 without removing any other groups
- Option 1 usermod
- Option 2 groupmod
- delete group delgroup
- set expireuser to expire on 2027-12-01
- set password to testuser1 to P@ssw0rd!123