Courses/Command Line/Permissions and Users

    Permissions and Users

    Understand file permissions, chmod, chown, sudo, and user management.

    What You'll Learn

    • Reading the rwxr-xr-x permission string
    • chmod โ€” changing permissions (numeric & symbolic)
    • chown โ€” changing file ownership
    • sudo, user management, and SSH key permissions

    Understanding File Permissions

    Every file and directory in Linux has three permission sets for three types of users:

    ๐Ÿ” Real-World Analogy: Think of permissions like access cards in an office building. The owner (employee) has their own office key. The group (department) has a floor access card. Others (visitors) have a lobby pass. Each level gives different access.

    $ ls -l
    -rwxr-xr-- 1 alice devs 2048 Mar 18 deploy.sh
     โ”‚โ”‚โ”‚ โ”‚โ”‚โ”‚ โ”‚โ”‚โ”‚
     โ”‚โ”‚โ”‚ โ”‚โ”‚โ”‚ โ””โ”€โ”€ Others: r-- (read only)
     โ”‚โ”‚โ”‚ โ””โ”€โ”€โ”€โ”€ Group:  r-x (read + execute)
     โ””โ”€โ”€โ”€โ”€โ”€โ”€ Owner:  rwx (read + write + execute)
    PermissionLetterOctalMeaning
    Readr4View contents
    Writew2Modify contents
    Executex1Run as program
    None-0No access

    Octal notation adds the values: rwx = 4+2+1 = 7, r-x = 4+0+1 = 5, r-- = 4+0+0 = 4. So rwxr-xr-- = 754.

    Reading Permissions

    Understand the permission string and common permission sets.

    Try it Yourself ยป
    JavaScript
    // File Permissions โ€” simulated
    console.log("=== Understanding Permissions ===");
    console.log("$ ls -l script.sh");
    console.log("-rwxr-xr-- 1 alice devs 1024 Mar 18 script.sh");
    console.log();
    
    console.log("Breaking down: -rwxr-xr--");
    console.log("  -    = file type (- file, d directory, l link)");
    console.log("  rwx  = Owner permissions  (read, write, execute)");
    console.log("  r-x  = Group permissions  (read, -, execute)");
    console.log("  r--  = Others permissions (read, -, -)");
    console.log(
    ...

    Changing Permissions and Ownership

    chmod โ€” Two Modes

    # Numeric (octal) โ€” set exact permissions
    $ chmod 755 script.sh       # rwxr-xr-x
    $ chmod 644 config.json     # rw-r--r--
    $ chmod 600 .env            # rw------- (secrets!)
    
    # Symbolic โ€” add/remove specific permissions
    $ chmod +x deploy.sh        # Add execute for everyone
    $ chmod u+w,g-w file.txt    # Add write for owner, remove for group
    $ chmod -R 755 public/      # Recursive for directories

    chown โ€” Change Ownership

    $ sudo chown alice file.txt          # Change owner
    $ sudo chown alice:developers dir/   # Change owner and group
    $ sudo chown -R www-data:www-data /var/www/  # Recursive

    โš ๏ธ Common Mistake

    SSH keys (~/.ssh/id_rsa) MUST be chmod 600. SSH will refuse to use keys with overly permissive settings. This is the #1 SSH troubleshooting issue.

    ๐Ÿ’ก Pro Tip

    Use sudo sparingly. Running everything as root is dangerous โ€” one typo could wipe your system. Only use sudo when you actually need elevated privileges.

    chmod, chown, sudo

    Practice changing permissions and ownership.

    Try it Yourself ยป
    JavaScript
    // chmod, chown, sudo โ€” simulated
    console.log("=== chmod โ€” Change Permissions ===");
    console.log();
    console.log("Numeric mode (octal):");
    console.log("$ chmod 755 script.sh    โ†’ rwxr-xr-x");
    console.log("$ chmod 644 readme.md    โ†’ rw-r--r--");
    console.log("$ chmod 600 id_rsa       โ†’ rw-------");
    console.log();
    
    console.log("Symbolic mode:");
    console.log("$ chmod +x script.sh     โ†’ Add execute for all");
    console.log("$ chmod u+x script.sh    โ†’ Add execute for owner only");
    console.log("$ chmod g+
    ...

    ๐Ÿ“‹ Quick Reference

    CommandDescription
    chmod 755 fileSet permissions (rwxr-xr-x)
    chmod +x fileMake executable
    chown user:grp fileChange ownership
    sudo commandRun as root
    whoami / idShow user info
    groupsShow group memberships

    ๐ŸŽ‰ Course Complete!

    Congratulations! You've completed the Command Line course โ€” from basic navigation to process management and permissions. You now have the skills to work efficiently in any terminal environment. Keep practising daily and the terminal will become your most productive tool! ๐Ÿ’ป

    Sign up for free to track which lessons you've completed and get learning reminders.

    Cookie & Privacy Settings

    We use cookies to improve your experience, analyze traffic, and show personalized ads. You can manage your preferences below.

    By clicking "Accept All", you consent to our use of cookies for analytics and personalized advertising. You can customize your preferences or reject non-essential cookies.

    Privacy Policy โ€ข Terms of Service