Account Creation and Deletion
Cybersecurity Linux Lesson 2.2.1
Creating User Accounts
To create a new user account, we use the command useradd followed by the username.
Format:
sudo useradd <options> <new username>
For example:
sudo useradd john
Adding More Information
You can change or add info to a user account with the usermod command. Format:
sudo usermod <options> <username>
For example:
sudo usermod –c “John Smith” john
This will set the user’s comment, which is often a full name, to John Smith.
Or
sudo usermod –g Sales john
This will add the john account into the Sales group.
Adding Groups
The groupadd command in Linux is used to create a new user group on the system.
Format:
sudo groupadd <options> <new group name>
For example:
sudo groupadd mygroup
Groups can be used to manage users with similar permissions or rights.
Modifying Groups
Groups can by modified with the groupmod command.
Format:
sudo groupmod <options> <group name>
For example:
sudo groupmod –n supergroup mygroup
This would change the name of an existing group from “mygroup” to “supergroup”.
Deleting User Accounts and Groups
To delete a user account, use the userdel command followed by the username. For example:
sudo userdel john
To delete the account plus their directories use the –r option:
sudo userdel -r john
Similarly groupdel deletes entire groups.
sudo groupdel mygroup
Check User Information
There are commands you can use to quickly check system information about a user.
The id command displays the user’s unique ID, their groups and other user account properties. Use the following command:
id john
The who command displays list of logged-in users.
The w command provides detailed information about logged in users including the time they logged-in and the processes they are running