Linux passwd and group Mangagement

Format

/etc/passwd

Username, Password, User ID, Group ID, User ID Info, Home directory, Command/shell

Example:

tom:x:1001:1001:Tom Cruise:/home/zac:/bin/bash

/etc/group

Group name, Password, Group ID, Group List

Example:

sudo:x:27:Lucy,Tom

User and Group Management Files

/etc/passwd and /etc/group

Add

1
2
3
sudo adduser new_username
# Or
sudo useradd new_username

Delete

1
2
3
sudo userdel username
# Then you may want to delete the home directory for the deleted user account :
sudo rm -r /home/username

Edit

To modify the username of a user:

usermod -l new_username old_username

To change the password for a user:

sudo passwd username

To change the shell for a user:

sudo chsh username

To change the details for a user (for example real name):

sudo chfn username

To add a user to the sudo group:

1
2
3
4
5
adduser username sudo

usermod -aG sudo username
# Or in CentOS, members of the wheel group have sudo privileges.
usermod -aG wheel username

To change the Group setting for a directory

  • chown {-R} [user]{:group} [file|directory]