Linux User & Group Management
Creating groups and users, and locking a shared directory like /var/www down to a single group with the right permission bits.
Groups
Create a new group with a specific group id (-r instead gives a low, system-level id):
sudo groupadd -g 1002 mygroupRestrict a shared directory to one group:
sudo usermod -a -G www-data someuser
sudo chgrp -R www-data /var/www
sudo chmod -R g+w /var/www
sudo find /var/www -type d -exec chmod 2775 {} \;
sudo find /var/www -type f -exec chmod ug+rw {} \;The 2775 on directories sets the setgid bit, so new files created inside inherit the www-data group automatically.
Add an existing user to a group, then refresh the current shell's group membership:
sudo usermod -aG developers john
newgrp developersDelete a group (fails if it's still a user's primary group):
sudo groupdel mygroupUsers
Create a user with a specific home directory, shell, and group memberships:
sudo useradd -m -d /home/subho -s /bin/bash -G standard,admin subhoSet or change that user's password:
sudo passwd subhoDelete a user and their home directory (-r removes the home dir and mail spool):
sudo userdel -r someuserInspect a user's numeric IDs and group memberships:
id someuser # uid, gid, and every group they're in
groups someuser # group names only