User and Group Management
Create new user
Linux Daddy will guide you.
sudo adduser username
You are now a daddy
sudo useradd username
Check all the users
sudo cat /etc/shadow
Consider, abhishek2:!:19579:0:99999:7:::
The row is split into 9 fields seperate by :
Each field resembles as:
Username. User account and login name that exist in the system.
Encrypted password. Password using the format $type$salt$hashed and eight to 12 characters long.
Last password change. Date since Jan. 1, 1970, when the password was last changed.
Minimum password age. The minimum number of days that must elapse before the password can be changed by the user.
Maximum password age. The number of days after which the password must be changed.
Warning period. The number of days before the password expires, during which time the user gets a warning to change the password.
Inactivity period. The number of days post-expiration -- since Jan. 1, 1970 -- before the user's account is disabled.
Expiration date. The date on which the account was disabled.
Unused. This field is left empty and reserved for future use - ref
User with custom shell
sudo useradd -s /bin/bash abhishek
/bin/bash
-> env shell
User with own home directory
sudo useradd -m -d /home/abhishek abhishek
- /home/abhishek4 -> This can be any path
User with comment
sudo useradd -c "user name is abhishek" abhishek
User with the account expiry date
useradd -e 2023-08-32 apple
- -e -> The date on which the user account will be disabled. The date is specified in the format YYYY-MM-DD.
User with custom userId
sudo useradd -u 1822 abhishek
Change default home directory of user geet
usermod -d /var/tmp/user/geet -m geet
Change login name of user geet
sudo usermod -i geet GEET
Change default shell of user geet
usermod -s /bin/fish geet
Set user password
sudo passwd username
Switch user
su username
add new group with own home directory with custom user id and group and custom comment to user geet, with login shell bash
useradd -m -d /home/geet -u 1029 -g 1822 -c "geet user" -s /bin/bash geet
Create new group
Create a new group
Linux daddy will guide you
sudo addgroup groupName
You are now daddy
sudo groupadd grp1
Create group with custom ID
sudo groupadd -g 2218 groupName
Add user to group
# sudo usermod --append --groups demo user1
sudo usermod -aG groupname userName
Display details about group
sudo cat /etc/gshadow
Change primary group of geet to ak
sudo usermod -g ak geet
Add geet as a menber of group jeet
sudo gpasswd -M geet jeet
Remove user geet from group jeet
sudo gpasswd -d geet jeet
Make geet admin of group jeet
sudo gpasswod -A geet jeet
Set password for group jeet
sudo gpasswd jeet
Delete user and group
Delete user
sudo userdel geet
Delelet user with all files
sudo userdel -r geet
Delete Group
sudo groupdel jeet
If the article helps you, leave a like, follow, or anything ๐.
You can follow me on LinkedIn and GitHub.
Subscribe to my newsletter
Read articles from Abhishek Pathak directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Abhishek Pathak
Abhishek Pathak
A Learner. Learning things which will exist,