File and Directory Permission Changing
Need to change permissions? Use chmod!
Now that you know what permissions are, you can use the chmod command to change a file or directory’s permissions.
Let’s try changing the permissions of testfile so that only the owner can write and execute it. Looking at the chart below, the octal value for write and execute is ‘3’. Since we only want the owner to have these permissions, the octal value for group and other users will be ‘0’. This leaves us with an octal permissions value of “300”.
If you try to read the file, it will give you a permission denied message.
Now let’s try changing the permissions so that everyone can read, write, and execute the file.
This may just be an example, but in reality, giving all the permissions to everyone can be very dangerous. You should think about all the users when setting permissions to a file to prevent unwanted users from modifying your files. The default directory permissions are 755 and the default file permissions are 664.
Changing the ownership of a file/directory is fairly simple using this command:
chown- changes ownership of a file or directory
In order to change the ownership of a file, you must add sudo in front of the command to grant superuser (admin) powers. The sudo command allows you to access and modify any files and operations.
chgrp- changing user group ownership of a file/directory
You can also use the chown command to change both the user and the user group: