Skip to content

Instantly share code, notes, and snippets.

@aeinbu
Last active October 23, 2025 06:37
Show Gist options
  • Save aeinbu/fb67eb4b805f44a069b7ea0a9d1eb78d to your computer and use it in GitHub Desktop.
Save aeinbu/fb67eb4b805f44a069b7ea0a9d1eb78d to your computer and use it in GitHub Desktop.

Linux users/groups/permissions cheatsheet

Add user

sudo useradd -m peter   #create user peter
sudo passwd peter       #set peter's password (will be prompted for password)

groupadd myAppUsers     #create the myAppUsers group

sudo usermod -a -G peter myAppUsers. #add peter to the myAppUsersGroup

adduser and addgroup are interactive convenience scripts that wrap the useradd and groupadd commands.

Get information about a user, including the user's group memberships

id        #about me
id peter  #about peter

List groups

groups        #for me
groups peter  #for peter

File permissions

List files, showing permissions and ownership information

ls -l

The permission mask is the sum of the permissions (r = 1, w = 2, x = 4) for the user (u), group (g) and others (o). Add the numbers to get the permission mask, so 7 means all of them (1+2+4=7).

Permissions are course grained, and set for exactly 3 scopes

  • u (for user) to set permission for the resource owner.
  • g for the resource group.
  • o (for others) to set permissions for everyone else.
  • a for setting all above scopes at once.
chmod u=rwx,g=rwx,o=rwx myFile.txt
chmod a=rwx myFile.txt
chmod 777 myFile.txt

You can add or remove a specific permission for a scope

chmod u+x myFile.txt
chmod u-x myFile.txt

TODO: setfacl - for working with ACLs

Change ownership of a file or folder

chown peter myFile.txt            #change owner
chgrp myAppUsers myFile.txt       #change group
chown :myAppUsers myFile.txt      #alternate syntax for chgrp
chown peter:myAppUsers myFile.txt #change owner and group

Execute a command with elevated rights elevated

sudo commandname

su - switch user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment