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

See a file's ownership and permissions with ls -a

Add user

$ sudo useradd -m peter
$ sudo passwd peter

$ groupadd myAppUsers

$ sudo usermod -a -G peter myAppUsers

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
$ id peter

List groups

$ groups
$ groups peter

File permissions

List files, showing permissions and ownership information

ls -l

Permissions are course grained, and set for exactly 3 scopes: owner, groups and others (global)

chmod u=rwx,g=rwx,o=rwx myFile.txt
chmod 777 myFile.txt

TODO: setfacl - for working with ACLs

Change ownership of a file

$ chown peter myFile.txt
$ chgrp myAppUsers myFile.txt

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