Users, Groups and Permissions in Linux

Users

  • Add a user : sudo adduser <userName>
  • Delete a user : sudo userdel <userName>
  • All the user detail about users are saved in /etc/passwd file
  • Change the password : sudo passwd <userName>

Groups

  • Add a group : sudo groupadd <groupName>
  • Delete a group : sudo groupdel <groupName>
  • Adding a user to a group : sudo adduser <userName> <groupName>
  • Removing a user from a group : sudo deluser <userName> <groupName>
  • Group information is stored in /etc/group file.

Permissions

  • Permissions are granted using a three digit number.
    • The first digit will be applicable for the Owner of the file
    • The second digit will be applicable for the users of the owner’s group
    • The third digit will be applicable for all other users
  • Permissions represented by digits
    • 1 => Execute
    • 2 => Write
    • 4 => Read
  • Examples
    • sudo chmod 777  <fileName>
    • sudo chmod 744  <FolderName> -R
  • Using symbolic method to change permission

sudo chmod u+rwx,g+rw-x,o+r-w-x <fileName>

u=user, g=group, o=others // + is for adding permissions and – is for remoning permissions

  • Own a file or a folder : sudo chown <userName> <fileName> or sudo chown -R <userName> <folderName>
  • Change the group ownership: same as above with chgrp command

 

Leave a comment

Your email address will not be published. Required fields are marked *