TL;DR
chown user:group <file>
orchown user:group -R <folder>
: Change the owner of a file or folder to a particular user and group. You cannot force user ownership unless you are root.chmod ### <file>
orchmod ### -R <folder>
: Change the permissions of a file or folder to use a permission triplet.- ALSO KEEP IN MIND:
ls -la
: List all the files and their owners in your current directorycd [path]
: Change Directory to [path]/home/kali/folder1/folder2
: Absolute File Path; this will never change.~/folder1/folder2
: Absolute File Path, relative to home directory. This shouldn’t change unless your home directory changes.folder1/folder2/
: Relative File Path, this depends on which folder you are in (seepwd
).
- TL;DR
- Users and Groups
- ls -l (Click to Open)
- The Permission Octet
- Changing Permissions (chmod)
- File Owners and Group Owners
- Sudo
Users and Groups
On Linux, as we discussed previously everything is a file. Another feature of Linux is that all files in the file system must be “owned” by a user account and a group account. When you run ls -l
, you see all the metadata info for files, but ALSO the user and group owners for the files in the third and fourth columns:
ls -l (Click to Open)
There are many default users and groups on Linux, something to know is that on Linux, Users have IDs and Groups have IDs, which can be substituted for the name. Some notable groups include:
User | ID | Notes |
root | 0 | The root (superuser) user, capable of doing anything on the system. A lot of system binaries are owned by this user. |
Web/http | 33 | A locked-down user which some applications run under |
Primary User | 1000 | The primary user for desktop linux environments. “kali” for Kali Linux by default. |
Group | ID | Notes |
root | The root (superuser) group. A lot of system binaries are owned by this group. | |
Web/http | 33 | A locked-down group which some applications run under. |
Primary Usergroup | 1000 | The primary user for desktop linux environments. “kali” for Kali Linux by default. |
The Permission Octet
On Linux, we have what I like to call the permissions “octet”, that is “r” means read, “w” means write, and “x” means execute. They can either be “on” or “off” just like bits, where “off” is “-”. For each file, you can define the permissions for the User Owner in the first triplet, the Group Owner in the second triplet, and EVERYONE ELSE in the third octet. This works with binary where “r” is +4, “w” is +2, and “x” is +1. So, “rwx” is “7”. If I want to only let the owner read, write, and everyone else only read, I would use the number 644, which translates to “rw-r--r--” as seen above. These numbers come into play later on when we want to change permissions (scroll down to “Changing Permissions” category)
Another useful command while you’re getting the hang of things is getfacl <file>
as shown below, it lists details on the file, the user owner and group owner:
Changing Permissions (chmod)
File Owners and Group Owners
Also on Linux-based operating systems, every file is owned by a user and a group. After the permissions