Linux: Creating Users, Groups, Permissions and Ownerships
This article is for SRE beginners and even experts that need to quickly look up a command that relates to creating users, groups, permissions and ownerships with Linux.
To create a user,
sudo adduser <username>
To delete a user,
sudo userdel <username>
To change the password of a user,
sudo passwd <username>
To create a group,
sudo groupadd <groupname>
To delete a group,
sudo groupdel <groupname>
Add user to group,
sudo adduser <username> <groupname>
Delete users from group,
sudo deluser <username> <groupname>
View all users,
sudo nano /etc/passwd
View all groups,
sudo nano /etc/group
Add permission to a directory,
sudo chmod 777 <directoryname> -R
The -R
flag suggests that you want to use this permission in the subdirectories of this directory
Add file ownership to user,
sudo chown -R <username> <filename>
Add directory ownership to user,
sudo chown -R <username> <directoryname>
Assign file ownership to group
sudo chgrp -R <groupname> <filename>
Assign directory ownership to group
sudo chgrp -R <groupname> <directoryname>