Linux File Permissions: Commands with Examples - Linux Tutorial 6

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to the video tutorial on setting file permissions on Linux security is a big concern for Linux which is a clone of Unix the multi-user operating system as Linux is used in mainframes and servers it is vital to keep it safe from a maligned user who can corrupt change or remove crucial data this is why for effective security Linux divides authorization into two levels ownership and permission the concept of permissions and ownership is crucial and Linux here we will discuss both of them let's start with ownership and the next files every file in directory in your UNIX or Linux system is assigned three types of owner the first one among them is user a user is the owner of the file by default the person who created a file becomes its owner hence a user is also sometimes called an owner the next one is a group a user group can contain multiple users all users belonging to a group will have the same access permissions to the file so you can add many users to a group and assign group permission to a file so that only the group members can read or modify them furthers other who is any other user who has access to a file this person has neither created the file nor does he belong to a user group which owns the file practically it means everybody else hence when you set the permission for others it is also referred as set permissions for world now the big question arises how does Linux distinguishes between these three user types so that a user a cannot affect a file which contains some other user B's vital information or data it is like you do not want your colleague who works on your Linux computer to view your personal images this is where permissions set in and they define user behavior let us understand the permission system on Linux every file in directory and your UNIX or Linux system has three permissions read write and execute define for all the three users that we discussed earlier this permission gives you the authority to open and read a file read permission on a directory gives you the ability to list its content the write permission gives you the authority to modify the contents of the file the write permission on a directory gives you the authority to add remove and rename files stored the directory in windows an executable program usually has an extension exe which you can easily run in UNIX or Linux you cannot run a program unless the execute permission is set for example in the sample file here the user does not have the permission to execute it hence we would get an error message if we try to open it therefore if the execute permission is not set you will not be able to run the file let us learn more about Linux security by examples running the LS L command on terminal gives us the following result by picking the details for the first file we get to know that the file types and access permissions are displayed by this weird-lookin code let us learn what it is about let's first learn about the characters R stands for read permission W is for write permission X is execute permission and the - stage no permission here the first - implies that we have selected a file else if it were a directory D would have been shown the next part of the code is our W - and it tells us the permissions for the Amna this suggests that the owner can read the file write or edit the file but he cannot execute the file since the execute bit is set to - which is no permission the next part is our w - it is for the user group which is going 99 and the group members can read the file and write or edit the file by design many Linux distributions like fedora sent us Ubuntu etc we'll add users to a group of the same group name as the username thus a user Tom is added to a group named Tom the third part is for the world which means any user it says are - - this means that the user can only read the file moving on let's say you do not want your colleague to see your personal images you can easily do so by changing file permissions we can use the chmod command which stands for change mode using the command we can set permissions is that read write and execute on a file or directory for the owner group and the world there are two ways to use the command the first one is the absolute mode and the second one is the symbolic mode starting with the first one in this mode file permissions are not represented as characters but a three-digit octal number the table shows numbers for all the permission types for example the number 0 states no permission and the symbol for it is three hyphens successively the number 1 would be 4 execute and the symbol for the same is - - X let us understand this by an example here we have a file with the main test we will change the permissions for this file using the absolute mode of chmod command here we use the seven six for absolute code and now the permissions for test file would change let's examine the changes to the permissions seven six for absolute code says the following read write and execute for the user or the owner read and write for the user group and read only for other users so this is how we can change the permissions using the absolute mode of the chmod command moving on to the next way in the absolute mode we change permissions for all three owners but on the symbolic mode you can modify permissions of a specific owner as well it makes use of mathematical symbols to modify the file permissions so the plus sign would mean adding a permission to a file or directory - would suggest removing the permission and equal to we'll set the permission and override the permissions set earlier the various owners are represented as u G o and a let us learn it with some examples again we would use the same test file and change its permissions using the symbolic mode by using oh is equal to r WX we have changed permissions for the other users let us check what the new permissions are as you can see here the other users have the read write and execute permission for this test file with G + X we have added execute permission to the group now if you will check the test file it will show the read write and execute permission for the crew by running u- r we will remove the read permission for the user or the owner of the file let us see how it looks now as we can see the permissions for test file do not show any read permission for the owner this is how we can use the two methods for chmod command and change permissions for changing the ownership of a file or directory you can use this command in case you want to change the user as well as group for a file or directory you need to use this command that is try them on terminal let us change the file ownership for the file command right now it shows that the owner of the file is guru 99 by running the town command with sudo we would be able to change the owner of this file to root as you can see the new owner for the file commands is root now let's try changing the user group and group ownership of the same file right now the owner of the file is root and the user group of the file is also root we will change it to guru 99 for this we would need to run the command sudo shower on the owner name then the group name and then the name of the file let us see the changes in the user and group ownership as you can see here the commands file is now owned by guru 99 and it also belongs to the same user group in case you want to change only the group owner of a file you will need to run the following command here we will again change the group owner of the file commands to root the chgrp command stands for change group now let us go through some important tips on user groups the file etc' group contains all the groups defined in the system in order to reach this file you need to go to the file system click on EDC directory and then search for the group file upon opening this file you would be able to see all the groups present on your Linux system you can use the command groups to find all the groups you are a member of so it shows here that the guru 99 user is a member of the following groups you can use the command new GRP to work as a member of a new group other than your default group let's see how it works let us now change the user group for the user guru 99 to cd-rom let's create a new file as test upon checking the detailed information for this file you will find that they use a group for the test file is cd-rom instead of the default guru 99 the next step says that you cannot have two groups owning the same file the one group can be a subgroup of another which can own a file let's now quickly summarize what we have learnt the next being a multi-user system uses permissions and ownerships for security they are free user types on a Linux system user group and other Linux divides the file permissions in to read write and execute denoted by are W and X the permissions on a file can be changed by ch mod command which can be further divided into absolute and symbolic mode the CH o W and command can change the ownership of a file or a directory use the following command for changing the user or the user and the user group at the same time the chgrp command can change the group ownership the command is chgrp group and the file name thank you for watching I will see you in the next tutorial
Info
Channel: Guru99
Views: 269,586
Rating: undefined out of 5
Keywords: ubuntu, linux, unix, os, tutorial, file permissions, file permission in linux, linux permissions, linux file permissions, permissions in linux, linux commands with examples, linux basic commands with examples, unix tutorial, linux commands for beginners, guru99 linux, guru99 linux youtube, linux guru99, guru99 unix, linux/unix tutorial for beginners, linux/unix, linux/unix operating systems, linux tutorial, command line
Id: D-VqgvBMV7g
Channel Id: undefined
Length: 13min 30sec (810 seconds)
Published: Thu Jan 31 2013
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.