Advanced File Management
Advanced File Management
This covers things like the following
- Access permissions
- Octal permission allocation
- Modifying existing ownership
- Calculate and set permissions on files and directories
- Setting setgid bits
- Applying sticky bits
- Searching for files
- Grasp and manage extended access controls
- Setting default access controls
File and Directory Access Permissions
- Linux is a multi user file system that can have thousands of users and thousands of folders. These permission dictate which users can see, access, traverse, or execute each file or folder.
Permissions Classes
- There are three permission classes Users [u], Groups [g], and Owners [o] as well as "All [a]".
Permissions types
- There are also three main permission bits Read [r], Write [w], and Execute [x]
- Files
- Read
- viewing and copying
- Write
- modifying
- Execute
- running
- Read
- Directories
- Read
- allow listing of directory [ls]
- Write
- Creating, deleting, and renaming files and sub-directories
- Execute
- enter directory with [cd]
- Read
- Files
Permission Modes
- The [-] represents every permission that is not included on a file or directory
drwxr-xr-x. 1 root root 54 Jan 23 2024
- Using this information you can add [+] . remove [-], or assign [=] permissions.
- In the example above the first character tells us what type of it is. Checked the following examples
This shows starting with the [-] that it is a normal file
-rw-r--r--. 1 root root 3216 May 16 12:50 passwd
Now for a directory it would have a [d] to start
drwxr-xr-x. 1 root root 28 Feb 13 19:00 nvme
For a symbolic link [l]
lrwxrwxrwx. 1 root root 16 Mar 6 19:00 opensc-x86_64.conf -> /etc/opensc.conf
For a character device it would be a [c]
crw-rw----. 1 root tty 7, 132 Jul 25 12:42 vcsa4
For a block device it would be a [b]
brw-rw----. 1 root disk 252, 0 Jul 25 12:42 zram0
For a Named Pipe [s]
prw-------. 1 root root 0 Jul 25 12:42 dmeventd-client
For a socket [s]
srwxr-xr-x. 1 root root 0 Jul 25 12:42 mcelog-client
Modifying Access permission bits
- You can use the command chmod to modify permission bits
| Octal Value |
Binary Notation |
Symbolic Notation |
Explanation |
| 0 | 000 | --- | No permissions |
| 1 | 001 | --x | Execute only |
| 2 | 010 | -w- | Write only |
| 3 | 011 | -wx | Write and Execute |
| 4 | 100 | r-- | Read only |
| 5 | 101 | r-x | Read and Execute |
| 6 | 110 | rw- | Read and Write |
| 7 | 111 | rwx | Read, Write, and Execute |
Let us do some testing
touch test
This creates the file
Assign testing permissions
chmod 444 test
You may have guessed it this should modify permissions to a r-- r-- r-- file.
-r--r--r--. 1 user1 user1 0 Jul 25 14:45 test
The first grouping is the owner permission state, the second grouping is the group permissions state, and the last grouping is the everyone permission state
Lets break this down
[-] [r--] [r--] [r--]
- The first bracket [-] shows us it is a file
- The second bracket [r--] shows us the owner has read permissions to the file test
- The third bracket shows us that the group has read permissions to the file test
- The last and fourth bracket shows us that everyone else not the owner or in the group has read permissions to the file test.
Modify Permissions Bits Using Symbolic Form
1. Lets adjust the testing on the file so that the the owner can execute and the group and others can write
- You can do this with Octal or Symbolic values. (we can also use -v [verbose] for more information)
chmod u+x test -v
[root@rhel01 ~]# chmod u+x test -v
mode of 'test' changed from 0444 (r--r--r--) to 0544 (r-xr--r--)
You can now see that in for the first permission state bracket that the user has read and execute permissions [r].
2. Lets add the write permission for the group (you can put the -v after the command or at the end of the command)
chmod -v go+w test
[root@rhel01 ~]# chmod -v go+w test
mode of 'test' changed from 0544 (r-xr--r--) to 0566 (r-xrw-rw-)
Now you can see the group and others had read and write in their state brackets [rw].
3. Lets remove the write permissions for other users
chmod -v o-w test
[root@rhel01 ~]# chmod -v o-w test
mode of 'test' changed from 0566 (r-xrw-rw-) to 0564 (r-xrw-r--)
So now in the other state bracket the write permissions were removed
4.Now lets assign read, write, and execute to all of the categories at once.
chmod -v a=rwx