1 00:00:00,000 --> 00:00:04,500 [Intro Music] 2 00:00:04,529 --> 00:00:06,329 We have just successfully created 3 00:00:06,329 --> 00:00:08,429 new user using another command 4 00:00:08,459 --> 00:00:10,709 called 'adduser'. And this command 5 00:00:10,739 --> 00:00:12,719 is much more convenient for use as 6 00:00:12,749 --> 00:00:14,879 'useradd' command, because it has 7 00:00:14,879 --> 00:00:16,768 interactive prompts, and you're able 8 00:00:16,768 --> 00:00:18,269 to set the Working Directory 9 00:00:18,269 --> 00:00:20,429 password and other settings just in 10 00:00:20,429 --> 00:00:22,679 one command. Great. Now let me 11 00:00:22,679 --> 00:00:24,389 demonstrate you how to change 12 00:00:24,449 --> 00:00:26,969 ownership for a specific file or 13 00:00:26,999 --> 00:00:29,339 directory. And let me create a new 14 00:00:29,339 --> 00:00:31,289 file in home directory for this 15 00:00:31,289 --> 00:00:33,719 'bogdan' user, but under 'root' user 16 00:00:33,719 --> 00:00:36,419 account. Let's go back to root 17 00:00:36,449 --> 00:00:38,969 session, 'exit', and here now I'm 18 00:00:38,969 --> 00:00:41,279 logged in as root user. And now 19 00:00:41,279 --> 00:00:44,169 let's create a new file in the '/home/bogdan'. 20 00:00:44,169 --> 00:00:45,539 Let's use the 21 00:00:45,569 --> 00:00:48,509 touch command 'touch /home 22 00:00:48,539 --> 00:00:51,059 /bogdan', and here will be 23 00:00:51,089 --> 00:00:55,529 filename 2.txt. File was created. 24 00:00:55,559 --> 00:00:57,299 Let's now list contents of the '/home 25 00:00:57,329 --> 00:01:00,149 /bogdan' directory. Let's add here 26 00:01:00,149 --> 00:01:03,329 '-la' options. And now I see new 27 00:01:03,329 --> 00:01:07,259 file 2.txt. But username and 28 00:01:07,289 --> 00:01:09,989 group are set to root because I 29 00:01:09,989 --> 00:01:12,479 have just created this file as a 30 00:01:12,479 --> 00:01:15,400 root user. Now let's change to 31 00:01:15,400 --> 00:01:18,600 'bogdan' user. 'su -bogdan'. Let's 32 00:01:18,629 --> 00:01:20,429 clear terminal. And let's list 33 00:01:20,429 --> 00:01:22,229 contents of home directory here 34 00:01:22,319 --> 00:01:24,509 under 'bogdan' user. And now I 35 00:01:24,509 --> 00:01:27,179 still see here this 2.txt file 36 00:01:27,209 --> 00:01:29,249 that we have just created as root 37 00:01:29,249 --> 00:01:31,319 user. And in those columns, you'll 38 00:01:31,319 --> 00:01:33,389 see this information root and root. 39 00:01:33,989 --> 00:01:36,749 Now let's try to modify this file 40 00:01:36,749 --> 00:01:39,149 2.txt under bogdan's 41 00:01:39,149 --> 00:01:41,759 account. Let's use Nano editor, and 42 00:01:41,759 --> 00:01:44,789 type 2.txt as argument. And 43 00:01:44,789 --> 00:01:46,902 here you will see that file 2.txt 44 00:01:46,902 --> 00:01:49,379 is unwriteable, and that is due 45 00:01:49,409 --> 00:01:52,349 to ownership issue. Owner of this 46 00:01:52,349 --> 00:01:55,109 file is 'root'. And of course, when 47 00:01:55,109 --> 00:01:56,309 you have a look at those 48 00:01:56,309 --> 00:01:58,679 permissions, you'll see that only 49 00:01:58,709 --> 00:02:01,709 owner of this file is able to write 50 00:02:01,739 --> 00:02:05,459 this file, here you see this 'w'. Other 51 00:02:05,459 --> 00:02:08,038 users that are members of this 52 00:02:08,038 --> 00:02:10,348 'root' group or other groups are not 53 00:02:10,377 --> 00:02:13,559 able to write this file. That's why 54 00:02:13,589 --> 00:02:15,929 we are not able to modify it. And 55 00:02:15,929 --> 00:02:17,519 in order to solve this problem, 56 00:02:17,639 --> 00:02:19,499 you're able to either change 57 00:02:19,499 --> 00:02:22,379 permissions, or change ownership of 58 00:02:22,379 --> 00:02:25,229 this file. This file is located in 59 00:02:25,229 --> 00:02:27,299 the home directory for bogdan 60 00:02:27,299 --> 00:02:29,939 user. And logically it's better to 61 00:02:29,939 --> 00:02:31,979 change ownership of this file, 62 00:02:32,039 --> 00:02:33,689 because again, this file is located 63 00:02:33,689 --> 00:02:35,400 in the home directory for 'bogdan' 64 00:02:35,400 --> 00:02:37,500 user. Let's do that. For that 65 00:02:37,559 --> 00:02:39,329 you need to use command 'chown', this 66 00:02:39,329 --> 00:02:41,189 one. Let's first have a look at 67 00:02:41,189 --> 00:02:42,719 help options for this command. 68 00:02:43,259 --> 00:02:45,569 Let's scroll a bit up to the beginning 69 00:02:45,599 --> 00:02:47,819 of this output, and you'll see that 70 00:02:47,849 --> 00:02:50,309 this command is used for change of 71 00:02:50,309 --> 00:02:52,859 the owner and or group for a 72 00:02:52,859 --> 00:02:56,069 specific file or files. And you'll 73 00:02:56,069 --> 00:02:57,299 see that first you need to 74 00:02:57,299 --> 00:02:59,009 specify options, if any. 75 00:02:59,309 --> 00:03:01,799 Afterwards, you need to specify new 76 00:03:01,859 --> 00:03:04,349 owner optionally, and new group 77 00:03:04,379 --> 00:03:06,509 optionally, and afterwards comes 78 00:03:06,539 --> 00:03:10,029 file or files. Let's try that in action. 79 00:03:10,029 --> 00:03:11,639 Let's clear terminal, and type 80 00:03:11,669 --> 00:03:14,489 chown. Next comes user name, we 81 00:03:14,489 --> 00:03:16,199 want to change ownership of the 82 00:03:16,199 --> 00:03:18,869 file to, it will be 'bogdan'; and 83 00:03:18,869 --> 00:03:22,139 next comes file name, 2.txt. Let's 84 00:03:22,139 --> 00:03:23,639 try to enter this command here 85 00:03:23,669 --> 00:03:26,579 under bogdan's account, Enter. And 86 00:03:26,609 --> 00:03:28,409 of course I see here error, 87 00:03:28,589 --> 00:03:30,929 Operation not permitted. Could you 88 00:03:30,929 --> 00:03:32,219 guess what is the reason for this 89 00:03:32,219 --> 00:03:34,469 error? Why I am not able to change 90 00:03:34,499 --> 00:03:36,539 ownership of this file under 91 00:03:36,539 --> 00:03:37,500 Bogdan's account? 92 00:03:37,500 --> 00:03:40,100 [Clock Ticking] 93 00:03:40,100 --> 00:03:42,500 You are right, answer is very simple. We are not 94 00:03:42,569 --> 00:03:45,689 able to modify this file under any 95 00:03:45,719 --> 00:03:48,029 other accounts except only root 96 00:03:48,029 --> 00:03:50,399 account. That's why I need to perform 97 00:03:50,429 --> 00:03:52,589 this action on the root account, and 98 00:03:52,619 --> 00:03:54,209 afterwards go back to bogdan's 99 00:03:54,209 --> 00:03:56,339 account, and then I will be able to 100 00:03:56,339 --> 00:03:58,529 modify this file as owner of this 101 00:03:58,529 --> 00:04:01,109 file. All right, let's go back to 102 00:04:01,109 --> 00:04:03,719 'root' account, exit, and let's type 103 00:04:03,749 --> 00:04:05,669 the same command 'chown bogdan', 104 00:04:05,849 --> 00:04:07,949 but now I need to enter a full path 105 00:04:08,009 --> 00:04:10,439 to this 2.txt file because now 106 00:04:10,439 --> 00:04:12,149 I'm the home directory for root 107 00:04:12,149 --> 00:04:14,200 user. So I am typing here 108 00:04:14,200 --> 00:04:18,290 '/home/bogdan/2.txt'. 109 00:04:18,290 --> 00:04:20,646 And now let's verify whether 110 00:04:20,646 --> 00:04:22,829 ownership was changed. 'ls - 111 00:04:22,858 --> 00:04:26,608 la /home/bogdan'. And yes, I see that 112 00:04:26,608 --> 00:04:29,399 now owner of this file 2.txt 113 00:04:29,459 --> 00:04:32,309 is 'bogdan', but group remained 114 00:04:32,399 --> 00:04:35,219 unchanged, it is still 'root', and 115 00:04:35,219 --> 00:04:36,869 that's probably not what you have 116 00:04:36,869 --> 00:04:39,479 expected. If you want to change 117 00:04:39,509 --> 00:04:41,759 group as well, you need to slightly 118 00:04:41,759 --> 00:04:43,739 modify this command. Let's go back 119 00:04:43,739 --> 00:04:45,479 to this command 'chown bogdan', 120 00:04:45,749 --> 00:04:48,539 and here after ':' you need to 121 00:04:48,539 --> 00:04:51,059 specify group name. It will be 122 00:04:51,059 --> 00:04:53,549 'bogdan'. Let's press Enter. And 123 00:04:53,549 --> 00:04:55,829 now let's verify whether something 124 00:04:55,859 --> 00:04:57,929 was changed here or not. And yes, 125 00:04:57,959 --> 00:05:00,839 now I see User and Group equal to 126 00:05:00,839 --> 00:05:02,189 'bogdan', my username. 127 00:05:02,790 --> 00:05:05,190 Let's now go back to 'bogdan' user 128 00:05:05,220 --> 00:05:08,700 'su -bogdan', and let's have 129 00:05:08,700 --> 00:05:09,840 a look at contents of home 130 00:05:09,840 --> 00:05:12,030 directory. And now I see correct 131 00:05:12,060 --> 00:05:14,790 ownership of this file, 2.txt. 132 00:05:15,180 --> 00:05:16,740 And of course, because now I'm 133 00:05:16,770 --> 00:05:19,140 owner of this file, I am able to 134 00:05:19,170 --> 00:05:21,660 write this file, modify it. Let's 135 00:05:21,660 --> 00:05:24,717 try to modify it, 'nano 2.txt', 136 00:05:24,717 --> 00:05:28,470 'Modified file'. Let's save 137 00:05:28,470 --> 00:05:31,590 changes, 'Ctrl + x', Yes, Enter, and 138 00:05:31,590 --> 00:05:33,930 now file was successfully changed. 139 00:05:34,290 --> 00:05:35,430 Let's have a look at contents of 140 00:05:35,430 --> 00:05:38,070 this file, 'cat 2.txt'; and yes, 141 00:05:38,070 --> 00:05:40,200 I see here contents 'Modified file'. 142 00:05:40,800 --> 00:05:42,750 That's how you're able to modify 143 00:05:42,810 --> 00:05:45,660 ownership for a specific file. In 144 00:05:45,660 --> 00:05:47,580 the same way, you're able to modify 145 00:05:47,610 --> 00:05:49,890 ownership for a specific directory. 146 00:05:50,220 --> 00:05:52,140 Let's quickly do that. And let's 147 00:05:52,140 --> 00:05:54,300 create new directory here in 148 00:05:54,300 --> 00:05:56,250 home folder for bogdan user, 149 00:05:56,250 --> 00:05:57,960 and let's do that again as 'root' 150 00:05:57,960 --> 00:06:00,390 user. Let's go back to root account 151 00:06:00,390 --> 00:06:02,700 and here let's create a new folder 152 00:06:02,820 --> 00:06:06,180 in '/home/bogdan'; and let's name 153 00:06:06,180 --> 00:06:09,780 it 'tmp'. And now if I list the 154 00:06:09,780 --> 00:06:13,170 contents of '/home/bogdan', I will 155 00:06:13,170 --> 00:06:15,240 see this new folder here and the 156 00:06:15,240 --> 00:06:17,700 owner is root and group is root as 157 00:06:17,700 --> 00:06:19,800 well. And let's create a new file 158 00:06:19,800 --> 00:06:21,780 in this 'tmp' folder. Let's actually 159 00:06:21,780 --> 00:06:24,780 'cd' to this tmp folder. I'll copy 160 00:06:24,780 --> 00:06:26,910 this folder name like so. And let's 161 00:06:26,910 --> 00:06:29,922 'touch 3.txt', and 4.txt. 162 00:06:29,922 --> 00:06:31,950 I'll create two new files here 163 00:06:31,980 --> 00:06:34,200 in 'tmp' folder. Here they are. And 164 00:06:34,200 --> 00:06:36,720 of course owner of those files is 165 00:06:36,750 --> 00:06:39,060 root. Alright, let's now try to 166 00:06:39,060 --> 00:06:42,180 modify ownership for entire folder, 167 00:06:42,180 --> 00:06:44,880 'tmp' folder. Let's 'cd' to home 168 00:06:44,880 --> 00:06:47,010 directory for root user, and let's 169 00:06:47,070 --> 00:06:50,002 enter 'chown'; next comes 'bogdan 170 00:06:50,002 --> 00:06:51,750 :bogdan'; and here 171 00:06:51,750 --> 00:06:54,101 will be path to this 'tmp' folder, 172 00:06:54,101 --> 00:06:56,310 '/home/bogdan', and 173 00:06:56,310 --> 00:06:58,770 here will be 'tmp' like so. Let's 174 00:06:58,770 --> 00:07:00,690 press Enter. And now let's list 175 00:07:00,690 --> 00:07:03,390 contents of the '/home/bogdan'; 176 00:07:04,200 --> 00:07:06,540 and I'll see the owner of 'tmp' 177 00:07:06,540 --> 00:07:09,090 folder was changed to 'bogdan'. But 178 00:07:09,120 --> 00:07:11,070 if I have a look at contents of the 179 00:07:11,100 --> 00:07:14,220 'tmp' folder, I'll still see owner 180 00:07:14,280 --> 00:07:17,082 'root' for both files, 3.txt 181 00:07:17,082 --> 00:07:19,500 and 4.txt; and that means 182 00:07:19,500 --> 00:07:21,870 that I have just adjusted owner 183 00:07:21,990 --> 00:07:24,780 only of the folder, directory 'tmp'; 184 00:07:25,530 --> 00:07:28,770 and ownership of any included files 185 00:07:28,800 --> 00:07:30,900 or subdirectories wasn't changed. 186 00:07:31,290 --> 00:07:33,420 If you want to change also owner of 187 00:07:33,420 --> 00:07:35,790 the inner files, you need to use 188 00:07:35,820 --> 00:07:37,560 additional options. Let's have a 189 00:07:37,560 --> 00:07:39,930 look at the help for 'chown' command. 190 00:07:39,960 --> 00:07:43,710 'chown --help', and scroll a bit 191 00:07:43,770 --> 00:07:47,310 up, and you'll find here option 192 00:07:47,340 --> 00:07:50,679 '-R', or '--recursive'; 193 00:07:50,679 --> 00:07:51,990 and with this option in 194 00:07:51,990 --> 00:07:54,120 place, you'll be able to modify 195 00:07:54,150 --> 00:07:56,940 ownership of all inner files and 196 00:07:56,940 --> 00:07:59,250 directories. Let's try to use this 197 00:07:59,250 --> 00:08:01,200 option. Let's clear terminal and 198 00:08:01,200 --> 00:08:03,580 type 'chown'; next comes option this 199 00:08:03,580 --> 00:08:06,720 '-R', capital 'R'; next we will type 200 00:08:06,750 --> 00:08:09,180 username and the group name we 201 00:08:09,180 --> 00:08:11,370 want to change ownership to. And 202 00:08:11,370 --> 00:08:13,830 here will be path to folder we want 203 00:08:13,830 --> 00:08:15,780 to change ownership. Here will be 204 00:08:15,780 --> 00:08:19,500 '/home/bogdan/tmp', like so. Let's 205 00:08:19,500 --> 00:08:21,630 press Enter. And now let's verify 206 00:08:21,660 --> 00:08:23,790 whether file's ownership in this 207 00:08:23,790 --> 00:08:25,200 'tmp' folder was changed or 208 00:08:25,200 --> 00:08:28,350 not? Let me copy this path and 'ls 209 00:08:28,350 --> 00:08:31,320 -la', and paste copied path. And 210 00:08:31,320 --> 00:08:33,870 now I see the owner for those files 211 00:08:33,990 --> 00:08:36,270 3.txt, and 4.txt was 212 00:08:36,270 --> 00:08:38,940 correctly changed to 'bogdan'. And 213 00:08:38,940 --> 00:08:41,469 of course, if I go back to bogdan's 214 00:08:41,469 --> 00:08:43,590 account, 'su - bogdan', and 215 00:08:43,590 --> 00:08:45,240 verify contents of home 216 00:08:45,240 --> 00:08:47,190 directory, and list files and 217 00:08:47,190 --> 00:08:49,590 folders in 'tmp' folder, I'll see 218 00:08:49,590 --> 00:08:51,750 correct ownership everywhere. And 219 00:08:51,750 --> 00:08:53,400 that means that now I'm able to 220 00:08:53,400 --> 00:08:55,799 modify those files, 3.txt 221 00:08:55,830 --> 00:08:57,270 or 4.txt. Let's try that 222 00:08:57,270 --> 00:09:00,390 quickly. 'nano tmp/3.txt'. 223 00:09:00,540 --> 00:09:02,460 Here I'm using relative path 224 00:09:02,490 --> 00:09:04,710 without any slashes. Or I'm 225 00:09:04,710 --> 00:09:06,270 actually able to use such 226 00:09:06,270 --> 00:09:08,520 syntax tilde, '~'; and here will be 227 00:09:08,520 --> 00:09:10,500 '/'; it means that I am accessing 228 00:09:10,500 --> 00:09:12,930 specific file inside of the home 229 00:09:12,930 --> 00:09:15,750 directory of this user. Let's press 230 00:09:15,780 --> 00:09:18,450 Enter, and here add 'Hello', save 231 00:09:18,450 --> 00:09:21,090 changes, Yes, Enter, and now let's 232 00:09:21,120 --> 00:09:23,310 read the contents of this file 'tmp/ 233 00:09:23,340 --> 00:09:25,890 3.txt', and I see those 234 00:09:25,890 --> 00:09:28,320 contents here. That's how we have 235 00:09:28,320 --> 00:09:30,630 successfully changed the ownership 236 00:09:30,660 --> 00:09:33,180 for entire directory and all 237 00:09:33,210 --> 00:09:35,400 inner files and directories. 238 00:09:35,760 --> 00:09:37,530 Great. That's all for this lecture. 239 00:09:37,530 --> 00:09:39,450 And now you understand how to 240 00:09:39,480 --> 00:09:41,940 change ownership for specific file, 241 00:09:42,000 --> 00:09:45,120 files, or directories. Next, let's 242 00:09:45,120 --> 00:09:46,860 talk about permissions. And I'll 243 00:09:46,860 --> 00:09:48,240 explain you how to modify 244 00:09:48,240 --> 00:09:50,310 permissions. And I'll actually 245 00:09:50,310 --> 00:09:51,690 demonstrate to you first how to 246 00:09:51,690 --> 00:09:54,060 create executable script in Linux. 247 00:09:54,210 --> 00:09:56,190 And we will create a very basic 248 00:09:56,190 --> 00:09:57,810 simple script that will simply 249 00:09:57,810 --> 00:09:59,610 print 'Hello world' to the terminal 250 00:10:00,000 --> 00:10:01,020 I'll see you in the next lecture, 251 00:10:01,020 --> 00:10:02,000 guys. Bye-Bye. 252 00:10:02,000 --> 00:10:03,840 [no audio]