Often when we want to modify a file on Linux we have to use the command $ sudo gedit file, extract $ sudo tar zxvf file.tar.gz -C /opt, for easy access to the /var/www folder typing the command $ sudo chmod -R 777 /var/www/. The sudo and chmod commands are done because these files and folders can only be accessed by root or in other words we are limited by file/file permissions.
Below is a list of files that appear when typing the command $ ls -l, visible file access rights along with users and groups. rwx file permissions exist only on unix/linux filesystems and do not apply on windows filesystems.
drwxrwxr–x 2 moses moses 4096 Aug 25 14:00 data
lrwxrwxrwx 1 moses moses 18 Aug 25 14:00 music -> /media/data/Music/
–rwxrwxrwx 1 moses moses 11 Aug 24 20:19 readme.txt
– = file
l = link
d = directory
r = read
w = write
x = execute
There are 3 rwx segments, the first segment is for User, the second segment is for Group and the third segment is for Other.
User = who owns/creates the file.
Group = a combination of several Users.
Other = Users who are not registered in the Group or system, can also be called Public.
From the information above, the readme.txt file is owned by User=musa with Group=musa. The readme.txt file can be read, written, and executed by the User, Group and Other, which means that anyone can modify it with full access.
Changing File/Folder Permissions
r = 4
w = 2
x = 1
sudo chmod 777 file_folder
The file is set to full access (read, write, execute) for all (user, group, other). Use sudo if the file/folder is owned by root.
chmod -R 777 file_folder
Additional -R (recursive), all files and sub-folders are set to access rights
chmod 755 file_folder
Files are set to rwx for users, rx for groups and others
In addition to using numbers, changing file permissions can also use letters.
u = user
g = group
o = other
a = all
chmod a+x files
Files can be executed by all. Usually the file that is set to x is a .sh script file, the file cannot be executed before the execute permissions are enabled.
chmod ow file
Remove the write option for Other
chmod a+rw file
Install read write options for all be it User, Group or Other
chown user_baru file_folder
Changing User Files/Folders
Changing Group Files/Folders
chown user:group_baru file_folder