Linux Demo: Managing Ownership

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this demonstration we're going to talk about managing ownership of files and directories in the Linux file system be aware that by default whenever a user creates a new file or creates a new folder that user automatically becomes its owner also the default group that's been assigned to that user automatically becomes the owning group of that file or folder let's see how that works now I'm currently logged in as my our Tracy user and I'm in my home directory I'm going to just create a new file using the touch command enter touch new file all this does is create an empty blank file in the file system press Enter now it's from the LS dash L command when we do we see the new file file that I just created it's zero bytes but here's the important thing I wanted you to see this first field here in the output of the LS dash L command specifies the name of the user that owns this file in this case it is the art Tracy user this second field right here specifies the name of the group that owns this file which is again our Tracy now this is a point of confusion for many gnu/linux administrators now understand that when you create a new user account in some Linux distributions such as the fedora system that we're running here it will automatically create a group with the same name as the user and assign that group to be that users primary group so in this case when I created the art Tracy user account on this system a corresponding group named our Tracy was also created and was assigned to the art Tracy user as our Tracy's primary group hence the you owning user is our Tracy for this file and because the our Tracy group is the our Tracy users primary group this group is also the owning group of that file now that's not the case with all distributions some distributions will create one single group named users and whenever you create a new user account in the system that user is automatically made a member of the users group and you becomes the primary group so you have to check with your particular distribution to see which way it does this more and more distributions are starting to do things this way however where we have a group with the same name as the user by default now even though this user and this group was assigned to new file when we created it we're not stuck with that you can change ownership however there are a few caveats that you have to be aware of first of all only the root user can change which user owns a particular file or directory in the file system no one else can however if we want to change the owning group we actually have two options root of course can change which group owns a particular file or directory but also if you are the owning user in this case I'm logged in as our Tracy and our Tracy is the owning user then that user can actually change the owning group can't change the user itself that owns the file but it can change the owning group so let's go ahead and try doing that let's change the ownership of new file to do this I want to switch to my root user account first and what I'm going to do is actually copy this file from my user accounts home directory to another user accounts home directory so I'm gonna do cpe slash home slash our Tracy new file and let's copy it to the home directory of the Kay Sanders user let's go ahead and switch to that directory now when the LS dash L command and we see the file that was copied over but notice something very important happened during the copy process note who is the owning user and owning group of this copy of the original file it's been changed to root the reason this happened is because when root executed the copy command a new copy of that file was created in the new location in the file system and who created that file with the copy command it was root therefore root becomes the owning user and roots default group which is root became the owning group now because this file is owned by root the case Sanders user will have very limited access to this file even though it exists in case anders home directory let's fix this let's change ownership of this copy of the file to the case anders user so that she can access it in her home directory to do this we run the own command for change owner we then specify the name of the user that we want to change ownership to a Sanders and then we specify the name of the file that we're modifying this case it's new file press Enter now let's run the LS - shell command again and when we do we see that the user that's assigned as the owner of the file has been changed from root up here to case handers however notice over here that the group that owns the file was not changed the route group is still the owning group of new file no more than likely we're going to want to change the owning group for this file as well now that can actually be done in two different ways you can do it with the Choong command enter cholan again and then we specify the name of the group that we want to change the ownership to for that file however we have to specify that this is now a group and not a user that we're changing ownership for so we enter a period first and then the name of the group k Sanders this is very important because remember the name of the user and the name of that users primary group is the same by putting a period before K Sanders we're telling Joan that this is a group name not a username then we had a space and then enter the name of the file new file now let's run LS dash L again and we see that Kay Sanders is now the user that owns that file and the case anders group also owns that file now there's actually a second command you can use to change group ownership of a file it's called a group as its name implies that stands for change group and it's in taxes the same as Joan we enter change group and then the name of the group that we want to change ownership to ok Sanders and then the name of the file new file now notice here that when I used your group I don't have to put the period before the group name that's because your group can only change group ownership therefore there's no need to differentiate it from a user account press ENTER and it changes the group ownership which actually didn't really change because it was already set to case Sanders now before we end this demo there's one other thing I want to show you and that is the fact that you can use two own to actually change both the user and group ownership of a file at the same time we do this by first specifying the name of the user that we want to own a file or directory a period and then the name of the group of the case Sanders again in this case and then the name of the file and when we do that both the user and the group ownership has changed at the same time that's it for this demonstration in this demo we talked about how to manage ownership we first talked about how to change the owner that owns a file and then we talked about how to change the owning group
Info
Channel: The Linux Man
Views: 849
Rating: 5 out of 5
Keywords: Linux
Id: pOMUdQRL2hY
Channel Id: undefined
Length: 7min 29sec (449 seconds)
Published: Thu Nov 24 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.