Table of contents
- Tasks
- <mark>Create user accounts</mark>
- <mark>Create groups</mark>
- <mark>Add user as admin of a group</mark>
- Create a new password for user
- <mark>Switch to another user</mark>
- Delete user account
- Change the login name of user
- Add new group
- Delete a group
- Add a single user to a group
- Add multiple users to a group
- Remove user from a group
- Solution
Managing user accounts and groups is a fundamental aspect of system administration, allowing you to control access, privileges, and organizational structure on a computer system. In this guide, we will explore various tasks related to user account creation, group management, password administration, and membership adjustments.
Note: The ones that are highlighted have some explanation.
Tasks
Create user accounts
Create the user account "alice" with the password "Pass1234" and the home directory "/home/alice."
Create the user account "bob" with the password "Bob@5678" and the home directory "/home/bob."
Create a user account with the username "charlie."
Create groups
Create the group "developers" with Group ID 1010.
Create the group "designers" with Group ID 1011.
Add user as admin of a group
Add the user "alice" as the admin of the group "developers."
Add the user "bob" as the admin of the group "designers."
Create a new password for user
- Create a new password for the user account "alice."
Switch to another user
- Switch to the user account "alice."
Delete user account
- Delete the user account "bob."
Change the login name of user
- Change the login name of the user account "alice" to "alicia."
Add new group
- Add a new group account named "testers."
Delete a group
- Delete the group account "designers."
Add a single user to a group
- Add a single member with the username "charlie" to the group "testers."
Add multiple users to a group
- Add multiple members ("alicia" and "charlie") to the group "developers."
Remove user from a group
- Remove the group member "alicia" from the group "developers."
Solution
Create user accounts
ubuntu@~$: sudo useradd -m alice ubuntu@~$: ls /home/ alice ubuntu ubuntu@~$: sudo passwd alice New password: Retype new password: passwd: password updated successfully ubuntu@~$: sudo grep alice /etc/passwd alice:x:1001:1001::/home/alice:/bin/sh ubuntu@~$: sudo grep alice /etc/shadow alice:$y$j9T$H3Af2FpfPo10bANWWWgWU/$au0KFIMfWHz.oekhL.tJtc616vD4KrlMXQOOL75l589:19565:0:99999:7::: ubuntu@~$: sudo useradd -m bob ubuntu@~$: ls /home/ alice bob ubuntu ubuntu@~$: sudo passwd bob New password: Retype new password: passwd: password updated successfully ubuntu@~$: grep bob /etc/passwd bob:x:1002:1002::/home/bob:/bin/sh ubuntu@~$: sudo grep bob /etc/shadow bob:$y$j9T$JNjgYMHI3S3H1v6UcwU8U.$qeW9qRcPK9ruNSf5/ykvsyz4HCn3cXFLRK741N8gAI6:19565:0:99999:7::: ubuntu@~$: sudo useradd charlie ubuntu@~$: grep charlie /etc/passwd charlie:x:1003:1003::/home/charlie:/bin/sh
/etc/passwd
file contains the user account details. Each field is separated by:
alice:x:1001:1001::/home/alice:/bin/sh
alice
- usernamex
- denotes that the password is encrypted and present in /etc/shadow file1001
- user ID1001
- group ID/home/alice
- user home directory/bin/sh
- default login shell/etc/shadow
file contains the secure user details. Each field is separated by:
alice:$y$j9T$H3Af2FpfPo10bANWWWgWU/$au0KFIMfWHz.oekhL.tJtc616vD4KrlMXQOOL75l589:19565:0:99999:7:::
alice
- username$y$j9T$H3Af2FpfPo10bANWWWgWU/$au0KFIMfWHz.oekhL.tJtc616vD4KrlMXQOOL75l589
- encrypted user password19565
- The date of the last password change, expressed as the number of days since Jan 1, 1970 (Unix time)0
- the number of days left before the user is allowed to change her password again. An empty field and a value of 0 mean that there is no minimum password age99999
- The maximum number of days the password is valid, after that user is forced to change her password again7
- The number of days before password is to expire that user is warned that his/her password must be changedCreate groups
ubuntu@~$: sudo groupadd -g 1010 developers ubuntu@~$: grep developers /etc/group developers:x:1010: ubuntu@~$: sudo groupadd -g 1011 designers ubuntu@~$: grep designers /etc/group designers:x:1011:
/etc/group
file contains the information about groups. Each field is separated by:
developers:x:1010:
developers
- group namex
- denotes whether the group has a password and whether is it present in/etc/gshadow
file1010 - group ID
The last field is blank as there are no users that are part of
developers
groupAdd user as admin of a group
ubuntu@~$: sudo gpasswd -A alice developers ubuntu@~$: sudo grep developers /etc/gshadow developers:!:alice: ubuntu@~$: sudo gpasswd -A bob designers ubuntu@~$: sudo grep designers /etc/gshadow designers:!:bob:
/etc/gshadow
file contains secure information about groups. Each field is separated by:
developers:!:alice:
developers
- group name!
- group password. If the value of this field is!
, then no user is allowed to access the groupalice
- group administratorlast field is blank because there are no users that are part of
developers
groupAlso, when a user is made admin of the group, it doesn't mean the user is added to the group.
alice
is made the admin ofdevelopers
the group but she is not part of the group.Create a new password for user
ubuntu@~$: sudo passwd alice New password: Retype new password: passwd: password updated successfully
Switch to another user
ubuntu@~$: su - alice Password: $ whoami alice $ pwd /home/alice $ exit ubuntu@~$: ubuntu@~$: su alice Password: $ whoami alice $ pwd /home/ubuntu $ exit ubuntu@~$:
There are two ways to switch to another user.
su - alice
changes the current directory to the home directory of the target user i.e./home/alice
su alice
the current directory remains the same as of the previous user i.e./home/ubuntu
Delete user account
ubuntu@~$: sudo userdel bob ubuntu@~$: grep bob /etc/passwd ubuntu@~$:
Change the login name of user
ubuntu@~$: sudo usermod -l alicia alice ubuntu@~$: grep alicia /etc/passwd alicia:x:1001:1001::/home/alice:/bin/sh
Add new group
ubuntu@~$: sudo groupadd testers ubuntu@~$: grep testers /etc/group testers:x:1012:
Delete a group
ubuntu@~$: sudo groupdel designers ubuntu@~$: grep designers /etc/group
Add a single user to a group
ubuntu@~$: sudo usermod -aG testers charlie ubuntu@~$: grep testers /etc/group testers:x:1012:charlie
Add multiple users to a group
ubuntu@~$: sudo gpasswd -M alicia,charlie developers ubuntu@~$: grep developers /etc/group developers:x:1010:alicia,charlie
Remove user from a group
ubuntu@~$: sudo gpasswd -d alicia developers Removing user alicia from group developers
"๐ฑ Keep learning, and spread the knowledge to inspire others. ๐๐ก"