1 00:00:00,000 --> 00:00:02,610 [No audio] 2 00:00:02,610 --> 00:00:07,080 File Ownership. In this lesson, we will cover how 3 00:00:07,080 --> 00:00:11,040 files and directories are owned, and how we could 4 00:00:11,040 --> 00:00:14,970 change the ownership of those files and 5 00:00:14,970 --> 00:00:19,710 directories. So the file ownerships are created on 6 00:00:20,130 --> 00:00:24,510 user level and a group level. There are two owners 7 00:00:24,540 --> 00:00:28,320 of a file or directory, a user, the one who 8 00:00:28,320 --> 00:00:32,490 creates the file or directory, and the second one 9 00:00:32,520 --> 00:00:38,550 is a group, the user the group that belongs to. If 10 00:00:38,550 --> 00:00:42,930 you are, if you belong to two different group, and 11 00:00:42,930 --> 00:00:45,690 permission applies that second group has read 12 00:00:45,690 --> 00:00:48,960 permissions, or you could delete a file or 13 00:00:48,960 --> 00:00:51,960 directory, as long as you are in that group, then 14 00:00:51,960 --> 00:00:55,860 you will have the right. Command to change file 15 00:00:55,860 --> 00:01:01,260 ownership is change owned, which is also known as 16 00:01:01,650 --> 00:01:08,310 chown and change group, chgrp. chown 17 00:01:08,310 --> 00:01:11,430 changes the ownership of a file, chgrp 18 00:01:11,430 --> 00:01:15,900 changes the group ownership of a file. Recursive 19 00:01:15,930 --> 00:01:19,470 ownership change option. If you are using an 20 00:01:19,500 --> 00:01:24,472 option with chown or chgrp with -R, 21 00:01:24,472 --> 00:01:27,150 it will not only change that 22 00:01:27,150 --> 00:01:31,050 directory, but also all the files and directories 23 00:01:31,110 --> 00:01:35,280 within that parent directory. If you look at the 24 00:01:35,280 --> 00:01:39,810 example of Windows, let's say we have this folder 25 00:01:39,810 --> 00:01:43,890 called Videos, and when I click, when I do right 26 00:01:43,890 --> 00:01:48,630 click and go to Properties, we'll see that under 27 00:01:48,630 --> 00:01:54,300 Security, this file is owned by the SYSTEM, and 28 00:01:54,330 --> 00:01:59,280 iafzal, and Administrators. So you see these two 29 00:01:59,280 --> 00:02:01,830 people here, these are the group and the single 30 00:02:01,830 --> 00:02:05,940 user, one person here is just the user. And again, 31 00:02:05,940 --> 00:02:09,389 the SYSTEM is a group. So group, system, and 32 00:02:09,389 --> 00:02:12,600 administrator own this file or folder called 33 00:02:12,600 --> 00:02:18,414 Videos. And the user who created that folder is iafzal. 34 00:02:18,414 --> 00:02:21,900 And you see at the bottom, it tells you 35 00:02:21,930 --> 00:02:27,060 whether that user has read, write, executable 36 00:02:27,060 --> 00:02:30,030 permission, you can see right here, it has all the 37 00:02:30,030 --> 00:02:34,650 permissions that we talked about. In our Linux 38 00:02:34,650 --> 00:02:37,110 machine when we log into our Linux machine, 39 00:02:37,110 --> 00:02:42,780 [No audio] 40 00:02:42,780 --> 00:02:46,380 again, the first thing we do is see who we are. So 41 00:02:46,380 --> 00:02:51,750 we are iafzal. See what files or directories we 42 00:02:51,750 --> 00:02:55,110 have. These are all the listing of files and 43 00:02:55,110 --> 00:02:59,250 directories we have. Now here, and the first 44 00:02:59,250 --> 00:03:02,490 second, and here the third column. The third 45 00:03:02,490 --> 00:03:07,050 column tells you who owns this file. Let's say we 46 00:03:07,050 --> 00:03:12,300 go to lisa, we created this file lisa, and the 47 00:03:12,300 --> 00:03:17,388 person who owns this file lisa is the user iafzal, 48 00:03:17,388 --> 00:03:22,110 or yourself, yourself in this case. The fourth 49 00:03:22,110 --> 00:03:26,130 column right here is the group name in this case 50 00:03:26,190 --> 00:03:31,200 is iafzal again, because I am part of my own 51 00:03:31,230 --> 00:03:35,070 group, I belong to my own group. I could change 52 00:03:35,070 --> 00:03:38,460 that to a different group. But since I'm a regular 53 00:03:38,460 --> 00:03:41,520 user, not a super user, I won't be able to change 54 00:03:41,520 --> 00:03:44,730 that permission to any other group. The only person 55 00:03:44,730 --> 00:03:47,790 or the only account that could change that 56 00:03:48,870 --> 00:03:55,560 ownership is root, so let's become root su-. 57 00:03:55,560 --> 00:04:06,120 [No audio] 58 00:04:06,120 --> 00:04:10,950 Once you log in, you do pwd and here it will bring 59 00:04:10,950 --> 00:04:13,980 you into /root. Now remember you are not in 60 00:04:13,980 --> 00:04:15,870 your home directory, you are in root directory 61 00:04:15,870 --> 00:04:19,170 because you are root right now. So I want you to 62 00:04:19,170 --> 00:04:23,310 go to your home directory, which is, if you remember 63 00:04:23,310 --> 00:04:30,150 slash home and slash your username. It will take 64 00:04:30,150 --> 00:04:33,420 you to your home directory. You could just do pwd 65 00:04:33,450 --> 00:04:37,440 to confirm and do ls -ltr to confirm another 66 00:04:37,440 --> 00:04:41,730 time that these are your directories and files. If 67 00:04:41,730 --> 00:04:46,590 you want to change the permission of lisa and you 68 00:04:46,590 --> 00:04:52,080 wanted to change it from yourself and you want it 69 00:04:52,080 --> 00:04:55,980 to have this owned by root, what you will do is 70 00:04:56,040 --> 00:05:04,170 chown and if you specify the name of the user 71 00:05:04,170 --> 00:05:08,310 you want to change to and the name of the file, 72 00:05:08,700 --> 00:05:15,570 lisa and then when you do ls -ltr, there you 73 00:05:15,570 --> 00:05:17,121 will see right here, 74 00:05:17,121 --> 00:05:21,668 [No audio] 75 00:05:21,668 --> 00:05:23,987 the file is now owned by root. 76 00:05:25,110 --> 00:05:29,130 You could also do, just to be more specific, so you 77 00:05:29,130 --> 00:05:33,000 don't see all of the files you do ls -l lisa, 78 00:05:33,510 --> 00:05:36,180 and you will see here now the file is owned by 79 00:05:36,180 --> 00:05:42,991 root. You could do the same thing when you do chgrp which is to 80 00:05:42,991 --> 00:05:45,330 change the group, you could do the 81 00:05:45,330 --> 00:05:49,860 group also, there was another group called root, and 82 00:05:49,860 --> 00:05:55,830 you could do lisa again, and go verify it. And now 83 00:05:55,830 --> 00:06:00,360 you will see this file lisa is owned by root, and 84 00:06:00,450 --> 00:06:04,590 and the group who owns this file is also root. Now 85 00:06:04,590 --> 00:06:08,040 what happened when you become yourself again? How 86 00:06:08,040 --> 00:06:10,470 do you get out of this root account? You just 87 00:06:10,470 --> 00:06:14,760 simply type exit, you are logged out, and just 88 00:06:14,760 --> 00:06:20,130 confirm who you are, yourself, which directory 89 00:06:20,130 --> 00:06:24,107 you are in, your new home directory, do ls -ltr, 90 00:06:24,107 --> 00:06:29,730 and you see, there is this file lisa. Now what 91 00:06:29,730 --> 00:06:33,870 happens if you try to delete this file? Let's see. 92 00:06:34,410 --> 00:06:39,900 rm lisa. It will tell you remove write protected 93 00:06:39,900 --> 00:06:46,890 regular of empty file. If you say yes, and do ls 94 00:06:46,890 --> 00:06:50,640 minus ltr, there you go, it is gone. The reason it 95 00:06:50,640 --> 00:06:56,220 is gone now, why, is because, when you go one step 96 00:06:56,310 --> 00:07:00,450 back to your home directory. So your home is right 97 00:07:00,450 --> 00:07:04,410 now is slash home slash yourself. And when you go 98 00:07:04,410 --> 00:07:05,520 one step back, 99 00:07:05,520 --> 00:07:07,529 [No audio] 100 00:07:07,529 --> 00:07:11,849 you are in just slash home and do ls -l. Here 101 00:07:11,849 --> 00:07:14,729 you will see the iafzal directory, which is your 102 00:07:14,729 --> 00:07:18,779 home directory, has the permission of yourself to 103 00:07:18,779 --> 00:07:22,829 read, write, and execute, meaning anything inside 104 00:07:22,829 --> 00:07:25,379 of the directory you could read, you could write, 105 00:07:25,379 --> 00:07:28,229 and then you could execute. So regardless if 106 00:07:28,259 --> 00:07:33,299 whoever puts the file in, whoever owns the file, or 107 00:07:34,319 --> 00:07:36,839 who whichever groups owns it, you could go ahead 108 00:07:36,869 --> 00:07:41,099 and still delete it. Now, if you try to create a 109 00:07:41,099 --> 00:07:45,170 file in, let's say, etc, and you go touch test 110 00:07:45,170 --> 00:07:47,998 [No audio] 111 00:07:47,998 --> 00:07:49,867 and you call touch 112 00:07:49,867 --> 00:07:51,867 [No audio] 113 00:07:51,867 --> 00:07:57,269 testfile. It will tell you Permission denied because 114 00:07:57,269 --> 00:08:01,799 you do not have permission to write to this file. 115 00:08:01,829 --> 00:08:07,439 How do you check that, you do ls -l /. You 116 00:08:07,439 --> 00:08:11,309 could do that, or you could simply go to cd slash 117 00:08:11,729 --> 00:08:15,359 and do ls -l. And you'll see here's a list of 118 00:08:15,359 --> 00:08:18,569 all the directories that are inside of slash. And 119 00:08:18,569 --> 00:08:21,509 the one we were trying to go to is etc. If you 120 00:08:21,509 --> 00:08:24,599 notice here, etc is owned by root and the group 121 00:08:24,629 --> 00:08:28,949 is owned by root as well. Now the root has the 122 00:08:28,949 --> 00:08:32,039 permission to write to it. But what about the 123 00:08:32,039 --> 00:08:34,649 people who are in roots group, they don't have 124 00:08:34,649 --> 00:08:37,019 permission to write to it. What about everybody 125 00:08:37,019 --> 00:08:39,599 else, they don't have a permission to write to it. 126 00:08:40,169 --> 00:08:44,849 So that is why you cannot create a file in etc. 127 00:08:45,328 --> 00:08:48,394 So let's say if you become root again. 128 00:08:48,394 --> 00:08:58,050 [No audio] 129 00:08:58,050 --> 00:09:03,030 Okay, and now you go to etc, and you create a file 130 00:09:03,030 --> 00:09:10,230 touch test123, just verify it, ls -ltr. You 131 00:09:10,230 --> 00:09:14,010 see at the bottom is your file. Now another way 132 00:09:14,010 --> 00:09:16,470 what you could do is while we are working on this, 133 00:09:16,470 --> 00:09:19,950 you could minimize this window and you could open 134 00:09:19,980 --> 00:09:23,280 another window by right clicking and create Open 135 00:09:23,280 --> 00:09:26,310 Terminal. So this way we have a regular account 136 00:09:26,310 --> 00:09:29,490 which is our account and the root account. So this 137 00:09:29,490 --> 00:09:31,770 way we don't have to exit out of all accounts. So 138 00:09:32,070 --> 00:09:37,560 we are here, iafzal, which directory we are in 139 00:09:37,620 --> 00:09:40,260 we are in slash home and we created the file in 140 00:09:40,260 --> 00:09:43,920 etc right as a root. So let's go to etc, and 141 00:09:43,920 --> 00:09:47,100 let's see ls -ltr, and now we're going to 142 00:09:47,100 --> 00:09:52,350 try to remove this file test123, and it's gonna 143 00:09:52,350 --> 00:09:55,440 say remove right protected. It's just a warning 144 00:09:55,440 --> 00:09:59,010 usage. Yes. And it still says Permission denied 145 00:09:59,010 --> 00:10:02,520 now. Why it's saying Permission denied again, 146 00:10:03,000 --> 00:10:07,410 you go to a cd slash name, and you do ls -l. 147 00:10:08,010 --> 00:10:11,640 And you will see right here, that says etc 148 00:10:11,790 --> 00:10:15,150 directory, and it tells you right here, that 149 00:10:15,150 --> 00:10:18,570 group, three bits do not have write permission. 150 00:10:18,990 --> 00:10:21,450 And the other three bits do not have the right 151 00:10:21,450 --> 00:10:25,290 permission as well. So that's how you change the 152 00:10:25,290 --> 00:10:29,910 user of the files, ownership and group ownerships 153 00:10:29,910 --> 00:10:33,750 So the two commands that we learned is changed 154 00:10:34,650 --> 00:10:40,080 ownership, which is chonw, sorry, own, and 155 00:10:40,080 --> 00:10:43,050 the second one is changed group, chgrp. So again, really 156 00:10:43,050 --> 00:10:49,260 want you to do a man on each command and go over 157 00:10:50,040 --> 00:10:52,680 the description, the different options, it has. 158 00:10:52,680 --> 00:10:56,280 Same thing you do with the second command as well. 159 00:10:56,490 --> 00:11:00,120 And also, I want you to practice this command by 160 00:11:00,120 --> 00:11:03,180 changing the permission only in your home 161 00:11:03,180 --> 00:11:07,980 directory. So your home directory is slash home 162 00:11:07,980 --> 00:11:10,200 slash yourself and you could try changing 163 00:11:10,200 --> 00:11:13,740 permission to one of the directory like create a 164 00:11:13,740 --> 00:11:15,840 new file, don't touch the file that you created 165 00:11:15,840 --> 00:11:20,700 and just the permission, testfile, create this 166 00:11:20,700 --> 00:11:25,620 file and just practice your chown and 167 00:11:25,620 --> 00:11:31,504 chgrp command on this file and see how you could change it. 168 00:11:31,504 --> 00:11:35,722 [No audio]