Creating Users and Groups in Linux
Creating a User
- Via GUI Tools
- Some distros have a GUI tool you can use
- Find from the Menu
- Via Shell
- every distro supports
useraddutility - e.g.,
sudo useradd -m -c "Hoburn Washburne" -u 1006 hwash-msets a home directory-cadds a comment field containing full name-usets UID of1006- sets username to
hwash
- when an account is created, it is in a locked state
- user cannot login
- to unlock, need to use
passwdcommand
- every distro supports
Modifying an Account
Check If a User is Logged In
- some account changes could be disruptive if a user is logged in
- check if the user is logged out:
whowlastshows a list of recent logins and who is still logged in
- displays data stored in
/var/log/wtmp
- Using GUI tools
- usually can modify:
- Account type
- standard or privileged user
- Name
- Password
- Groups
- Account type
- usually can modify:
- Using Shell
passwdchanges a user’s password- e.g.,
sudo passwd hwash- enter new password
- retype
- done
- can also adjust password aging and other options
- e.g.,
usermodmodifies an existing user- options are identical to
useradd - e.g.,
sudo usermod -u 1072 -m -d /home2/hwash hwash-uchanges UID to1072-mchanges home directory to/home2/hwash-dmoves contents of original home to the new home
- options are identical to
Deleting Accounts
- Delete via GUI
- Delete via Shell
userdelcommand deletes accounts from CLI- e.g.,
sudo userdel hwash -roption deletes user’s home directory- does not delete user’s home directory by default
-foption force deletes a user if they are currently logged in- will still complain about user being used by a process, but will still delete the account
- e.g.,
Managing Groups
- Using GUI Tools
- can typically find in Menu
- typically part of User management
- Via Shell
groupaddcommand creates a group- e.g.,
groupadd -g 1001 consultants
- e.g.,
- to add users to group:
usermod -aG consultants rich
groups richchecks all groups for an accountgroupmodcommand modifies a groupgroupdeldeletes a group
Wheel Group
The wheel group is an important group used for system administration.
- members are granted admin privileges
- allows access to
sudocommand
- allows access to
- not all distros use this group