Lab Exercise: User and Group Management
Add a User with
useradd
Command:We'll create a new user named "johndoe" using the
useradd
command:sudo useradd johndoe
This command will add an entry for "johndoe" in the
/etc/passwd
file.
Check the Entries in Files:
Verify the entries in the following files:
/etc/passwd
: Contains user account information./etc/shadow
: Contains encrypted passwords and other user-specific settings./etc/group
: Contains group information.
You can use commands like
cat
,grep
, orless
to view the contents of these files.
Add User with Common Options:
Let's create a new user named "alice" with specific options:
sudo useradd -g developers -G admins -s /bin/bash -d /home/alice -u 1001 alice
This command:
Sets the primary group to "developers."
Adds "alice" to the "admins" group.
Sets the login shell to
/bin/bash
.Specifies the home directory as
/home/alice
.Assigns a custom user ID (UID) of 1001.
Check Shadow Entry Before and After Password:
Before setting a password for "alice," check the
/etc/shadow
entry for her.Set a password for "alice" using the
passwd
command:sudo passwd alice
After setting the password, verify the updated
/etc/shadow
entry.
Verify Home Directory and
/etc/skel
:Check the contents of "alice"'s home directory (
/home/alice
).Also, explore the contents of the
/etc/skel
directory, which serves as a template for new user home directories.
Use
usermod
to Change Group and Login Shell:Change "alice"'s primary group to "devteam":
sudo usermod -g devteam alice
Change her login shell to
/bin/zsh
:sudo usermod -s /bin/zsh alice
Create a New Group and Add It to an Existing User as a Secondary Group:
Create a new group named "designers":
sudo groupadd designers
Add "alice" to the "designers" group:
sudo usermod -a -G designers alice
Remove the User:
To remove "alice" and her home directory:
sudo userdel -r alice
Use
finger
Command:The
finger
command provides information about users. For example:finger alice
Lab Exercise:
Here's a lab exercise for you:
Create a new user named "bob."
Set his password.
Verify the entries in
/etc/passwd
,/etc/shadow
, and/etc/group
.Explore Bob's home directory.
Change Bob's primary group to "developers."
Add him to the "designers" group.
Remove Bob from the system.
Last updated