File Permissions in Linux

space, earth, bug-19070.jpg

Project description

In this project, I used Linux commands to manage file and directory permissions in the Bash shell.


Check file and directory details

Use the following commands to navigate to the projects directory and check the file and directory details and other permissions. By combining the -l and -a options to modify the ls command, we are able to see permission details (-l) and hidden files (-a):

cd projects
ls -la

Describe the permissions string

The first character in the permissions string describes type of the file: d for directory & – for file.

For example, drafts is a directory because the permissions string begins with d.

For the rest of the characters, r means read, W means write, x means execute, and – means that permission is not granted.

The next three characters represent the permissions for the user: rwx

The following three characters represent permissions for the group: –x

The final three characters represent permissions for other: ––


Change file permissions

Next, I will remove the w permissions for other for project_k.txt using chmod:

chmod o-w project_k.txt

As we can see, w no longer appears in the final three characters for project_k.txt.

Next, I notice that the permissions for project_m.txt are -rw-r—–. However,  and  should not be able to read or write this file. So, I will update the permissions accordingly:

chmod g=---,o=--- project_m.txt

As we can see, group and other no longer have r or w permissions for project_m.txt.


Change file permissions on a hidden file

Next, I will check and update the permissions for the hidden file .project_x.txt

Hidden files and directories begin with a . and are accessible by using the option -a on the ls command.

ls -la

As we can see, the user has r and w permissions, and group has w permissions only. However, this file is archived and should not be written to by anyone. The user and group should have read-only access to this file. I will update the permissions accordingly using the following command:

chmod u=r–-,g=r-- .project_x.txt

As we can see, the permissions for .project_x.txt are now correct.


Change directory permissions

Finally, I will manage the permissions for the drafts directory. Only the user should be able to access (execute) the directory. As such, I will remove the x permission for group:

chmod g-x drafts

As we can see, now only the user has x permissions on the drafts directory.


Summary

In summary, the chmod command is a powerful and useful tool for managing permissions of files ad directories from the Linux command line.

Leave a Reply

Your email address will not be published. Required fields are marked *

| A SOHUM.media Property