miniguide

Linux Permissions, Ownership & Sudoers Cheatsheet: Essential Commands for DevOps

Introduction

This cheatsheet provides common Linux commands for managing file permissions, changing ownership, and configuring sudoers. It is designed for DevOps professionals managing Linux systems.

Table of Contents

  1. Change File Permissions (chmod)
  2. Change File Ownership (chown)
  3. Recursively Change Ownership
  4. View File Permissions
  5. Add User to Sudoers
  6. Edit Sudoers File
  7. List Sudoers
  8. Reset Permissions to Default
  9. Find Files with Specific Permissions
  10. Audit File Permissions

1. Change File Permissions (chmod)

chmod 755 filename

2. Change File Ownership (chown)

chown user:group filename

3. Recursively Change Ownership

chown -R user:group /path/to/directory

4. View File Permissions

ls -l filename

5. Add User to Sudoers

usermod -aG sudo username

6. Edit Sudoers File

Use visudo for safe editing.

visudo

7. List Sudoers

grep '^sudo' /etc/group

8. Reset Permissions to Default

Example: set default for directories and files

find /path/to/directory -type d -exec chmod 755 {} \;
find /path/to/directory -type f -exec chmod 644 {} \;

9. Find Files with Specific Permissions

find / -perm 644

10. Audit File Permissions

ls -lR /path/to/directory | less