Lab Exercise: User and Group Management
Add a User with
useraddCommand:We'll create a new user named "johndoe" using the
useraddcommand:sudo useradd johndoeThis command will add an entry for "johndoe" in the
/etc/passwdfile.
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, orlessto 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 aliceThis 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/shadowentry for her.Set a password for "alice" using the
passwdcommand:sudo passwd aliceAfter setting the password, verify the updated
/etc/shadowentry.
Verify Home Directory and
/etc/skel:Check the contents of "alice"'s home directory (
/home/alice).Also, explore the contents of the
/etc/skeldirectory, which serves as a template for new user home directories.
Use
usermodto Change Group and Login Shell:Change "alice"'s primary group to "devteam":
sudo usermod -g devteam aliceChange 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 designersAdd "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
fingerCommand:The
fingercommand 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