stottj / Command-Line

0 stars 0 forks source link

Understand and modify file permissions with `chmod` #10

Closed stottj closed 1 year ago

stottj commented 1 year ago

Ticket: Understand and Modify File Permissions with chmod


Summary

Learn how to understand and modify file permissions using the chmod command in a Unix-like operating system.


Description


Learning Tasks

  1. File Permission Basics:

    • Learn about the three basic types of permissions: Read (r), Write (w), and Execute (x).
  2. Syntax and Basic Usage of chmod:

    • Understand the syntax and how to use chmod to change permissions on a file or directory.
  3. Specify Permissions:

    • Explore how to specify permissions using both numeric and symbolic modes.
  4. Best Practices and Warnings:

    • Familiarize yourself with the responsible use of chmod, including potential pitfalls and how to avoid them.
  5. Hands-on Practice:

    • Exercise 1: Create a text file and change its permissions to read-only.
    • Exercise 2: Create a script file and make it executable.
    • Exercise 3: Use symbolic mode to add write permission to a group for a specific file.
    • Exercise 4: Revert a file to its default permissions.
  6. Troubleshooting:

    • Discover common issues users may face while working with chmod and learn solutions for them.

Learning Goals


Priority

stottj commented 1 year ago

in chmod rwx displays what the status of permissions are for a file depending on the class of user (owner,group,other).

symbolic mode could show a file as rwxr--r-- which would mean the user class(owner) can read(r), write(w) and execute(x). While the group class (group owning the file) would be able to read the file. Lastly the last three letters define permissions for the other class (non-user or group class individiuals) showing they dont have access to anything.

Another way to set permissions is to use numerical permissions. chmod will use 3 digits ranging from 0-7 for designating the user/group/other class rights. ie 740 would mean user has r,w,x/group has r/others have none.

Ex 1 touch test.txt chmod a=r test.txt

Ex 2 touch test.sh chmod a=x test.sh

Ex 3 chmod g+w test.txt

Ex 4 chmod 644 test.txt

Common issues for using chmod is giving the wrong permissions at the wrong level. Becareful to not remove your permissions, really bad if you do it while using ssh, as you will have to re-add them or need to use a backup to go to a previous version. Careful on the -R usage as this is recursive so it might affect more than just the file you intended.

tupleHunden commented 1 year ago

👍🏻