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.

Revisions

  1. aeinbu revised this gist Oct 23, 2025. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -14,14 +14,14 @@ sudo usermod -a -G peter myAppUsers. #add peter to the myAppUsersGroup

    ## Get information about a user, including the user's group memberships
    ```
    id
    id peter
    id #about me
    id peter #about peter
    ```

    ## List groups
    ```
    groups
    groups peter
    groups #for me
    groups peter #for peter
    ```

    ## File permissions
  2. aeinbu revised this gist Oct 23, 2025. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,12 @@

    ## Add user
    ```
    sudo useradd -m peter
    sudo passwd peter
    sudo useradd -m peter #create user peter
    sudo passwd peter #set peter's password (will be prompted for password)
    groupadd myAppUsers
    groupadd myAppUsers #create the myAppUsers group
    sudo usermod -a -G peter myAppUsers
    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.
  3. aeinbu revised this gist Oct 23, 2025. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -51,10 +51,12 @@ chmod u-x myFile.txt

    TODO: `setfacl` - for working with ACLs

    ## Change ownership of a file
    ## Change ownership of a file or folder
    ```
    chown peter myFile.txt
    chgrp myAppUsers myFile.txt
    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
  4. aeinbu revised this gist Feb 16, 2025. 1 changed file with 12 additions and 1 deletion.
    13 changes: 12 additions & 1 deletion linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -32,12 +32,23 @@ 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: owner, groups and others (global)
    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
  5. aeinbu revised this gist Apr 9, 2024. 1 changed file with 14 additions and 16 deletions.
    30 changes: 14 additions & 16 deletions linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,56 +1,54 @@
    # Linux users/groups/permissions cheatsheet
    See a file's ownership and permissions with `ls -a`

    ## Add user
    ```
    $ sudo useradd -m peter
    $ sudo passwd peter
    sudo useradd -m peter
    sudo passwd peter
    $ groupadd myAppUsers
    groupadd myAppUsers
    $ sudo usermod -a -G peter 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
    id
    id peter
    ```

    ## List groups
    ```
    $ groups
    $ groups peter
    groups
    groups 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: owner, groups and others (global)
    ```
    chmod u=rwx,g=rwx,o=rwx myFile.txt
    chmod 777 myFile.txt
    ```
    r = 1, w = 2, x = 4.
    Add the numbers to get the permission mask, so 7 means all of them (1+2+4=7).
    This permission mask is shown for each file and directory with `ls -l`

    TODO: `setfacl` - for working with ACLs

    ## Change ownership of a file
    ```
    $ chown peter myFile.txt
    $ chgrp myAppUsers myFile.txt
    chown peter myFile.txt
    chgrp myAppUsers myFile.txt
    ```

    ## Execute a command with elevated rights elevated
    ```
    $ sudo commandname
    sudo commandname
    ```

    su - switch user
    `su` - switch user
  6. aeinbu revised this gist Apr 9, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -36,6 +36,9 @@ Permissions are course grained, and set for exactly 3 scopes: owner, groups and
    chmod u=rwx,g=rwx,o=rwx myFile.txt
    chmod 777 myFile.txt
    ```
    r = 1, w = 2, x = 4.
    Add the numbers to get the permission mask, so 7 means all of them (1+2+4=7).
    This permission mask is shown for each file and directory with `ls -l`

    TODO: `setfacl` - for working with ACLs

  7. aeinbu revised this gist Apr 1, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -41,8 +41,8 @@ TODO: `setfacl` - for working with ACLs

    ## Change ownership of a file
    ```
    $ chown myFile.txt peter
    $ chgrp myFile.txt myAppUsers
    $ chown peter myFile.txt
    $ chgrp myAppUsers myFile.txt
    ```

    ## Execute a command with elevated rights elevated
  8. aeinbu revised this gist Jan 8, 2023. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ $ id
    $ id peter
    ```

    ## List group
    ## List groups
    ```
    $ groups
    $ groups peter
    @@ -37,14 +37,15 @@ chmod u=rwx,g=rwx,o=rwx myFile.txt
    chmod 777 myFile.txt
    ```

    TODO: setfacl - for working with ACLs
    TODO: `setfacl` - for working with ACLs

    ## Change ownership of a file
    ```
    $ chown myFile.txt peter
    $ chgrp myFile.txt myAppUsers
    ```

    ## Execute with elevated rights elevated
    ## Execute a command with elevated rights elevated
    ```
    $ sudo commandname
    ```
  9. aeinbu revised this gist Jan 8, 2023. 1 changed file with 23 additions and 8 deletions.
    31 changes: 23 additions & 8 deletions linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -13,20 +13,35 @@ $ sudo usermod -a -G peter myAppUsers

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

    ## Set permissions
    ## Get information about a user, including the user's group memberships
    ```
    $ chmod file permissions
    $ id
    $ id peter
    ```
    setfacl - for working with ACLs

    ## Change ownership
    ## List group
    ```
    $ groups
    $ groups peter
    ```
    $ chown file owner

    ## File permissions
    List files, showing permissions and ownership information
    ```
    ## Get user and group information about a user
    ls -l
    ```
    $ id
    $ groups

    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 myFile.txt peter
    ```

    ## Execute with elevated rights elevated
  10. aeinbu revised this gist Jan 8, 2023. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -6,10 +6,13 @@ See a file's ownership and permissions with `ls -a`
    $ sudo useradd -m peter
    $ sudo passwd peter
    $ addgroup myAppUsers
    $ groupadd myAppUsers
    $ sudo usermod -a -G peter myAppUsers
    ```

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

    ## Set permissions
    ```
    $ chmod file permissions
  11. aeinbu revised this gist Jan 8, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ $ chown file owner
    ## Get user and group information about a user
    ```
    $ id
    $ group
    $ groups
    ```

    ## Execute with elevated rights elevated
  12. aeinbu revised this gist Oct 19, 2019. 1 changed file with 25 additions and 7 deletions.
    32 changes: 25 additions & 7 deletions linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,34 @@
    # Linux users/groups/permissions cheatsheet
    See a file's ownership and permissions with `ls -a`

    ## Add user
    ```
    $ sudo useradd -m peter
    $ sudo passwd peter
    $ addgroup myAppUsers
    $ sudo usermod -a -G peter myAppUsers
    ```
    ## Set permissions
    chmod file permissions
    ```
    $ chmod file permissions
    ```
    setfacl - for working with ACLs

    ## Change ownership
    chown file owner

    ```
    $ chown file owner
    ```
    ## Get user and group information about a user
    id
    group
    ```
    $ id
    $ group
    ```

    ## Execute with elevated rights elevated
    sudo
    su
    ```
    $ sudo commandname
    ```

    su - switch user
  13. aeinbu revised this gist Oct 19, 2019. 1 changed file with 12 additions and 2 deletions.
    14 changes: 12 additions & 2 deletions linux-users-groups-permissions-cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,16 @@
    chmod
    chown
    # Linux users/groups/permissions cheatsheet
    See a file's ownership and permissions with `ls -a`

    ## Set permissions
    chmod file permissions

    ## Change ownership
    chown file owner

    ## Get user and group information about a user
    id
    group

    ## Execute with elevated rights elevated
    sudo
    su
  14. aeinbu renamed this gist Oct 19, 2019. 1 changed file with 0 additions and 0 deletions.
  15. aeinbu created this gist Oct 19, 2019.
    6 changes: 6 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    chmod
    chown
    id
    group
    sudo
    su