1 00:00:06,600 --> 00:00:09,210 - The preferred way to run administrative tasks 2 00:00:09,210 --> 00:00:10,533 is by using sudo. 3 00:00:11,580 --> 00:00:14,370 That is because sudo is more sophisticated. 4 00:00:14,370 --> 00:00:16,950 It allows you to grant users privileges to 5 00:00:16,950 --> 00:00:21,780 learn specific tasks or all tasks with elevated permissions. 6 00:00:21,780 --> 00:00:24,960 In admin, it's either you are root, or you are not, 7 00:00:24,960 --> 00:00:28,230 and in sudo, you can go for the solution in the middle. 8 00:00:28,230 --> 00:00:30,570 You can create a configuration where a user 9 00:00:30,570 --> 00:00:33,303 just has access to a limited couple of tasks. 10 00:00:34,560 --> 00:00:38,520 The default "admin" user has sudo privileges by default. 11 00:00:38,520 --> 00:00:40,533 But what is this default "admin" user? 12 00:00:41,670 --> 00:00:43,380 Well, this default "admin" user 13 00:00:43,380 --> 00:00:45,360 is a user that may be created 14 00:00:45,360 --> 00:00:48,660 while installing your Linux distribution. 15 00:00:48,660 --> 00:00:50,820 Depends on your installation options. 16 00:00:50,820 --> 00:00:53,040 So watch your installation options to make sure 17 00:00:53,040 --> 00:00:56,730 that you do have an admin user, but normally you should. 18 00:00:56,730 --> 00:00:58,770 On Red Hat, you will be an admin user 19 00:00:58,770 --> 00:01:01,080 if you are a member of the group wheel. 20 00:01:01,080 --> 00:01:02,520 And notice that on Red Hat, 21 00:01:02,520 --> 00:01:05,460 when a root user is created with a password, 22 00:01:05,460 --> 00:01:07,710 there is no default "admin" user. 23 00:01:07,710 --> 00:01:12,182 You need to specifically grant administrator privileges 24 00:01:12,182 --> 00:01:14,700 to a user account while installing 25 00:01:14,700 --> 00:01:16,900 if you wanna have this default "admin" user. 26 00:01:17,851 --> 00:01:21,540 I will show you in one of the next lessons managing users, 27 00:01:21,540 --> 00:01:24,870 how you can create admin users later. 28 00:01:24,870 --> 00:01:28,350 It's not that difficult, but let's not do that now. 29 00:01:28,350 --> 00:01:30,450 On Ubuntu, the default "admin" user 30 00:01:30,450 --> 00:01:32,283 is a member of the group sudo. 31 00:01:33,300 --> 00:01:34,980 As a sudo enabled user, 32 00:01:34,980 --> 00:01:38,310 you use sudo followed by the command that you want to run 33 00:01:38,310 --> 00:01:40,470 with the escalated privileges. 34 00:01:40,470 --> 00:01:44,880 Or alternatively, you can use sudo - i to open a root shell, 35 00:01:44,880 --> 00:01:47,580 which is not recommended, but it's an option. 36 00:01:47,580 --> 00:01:48,750 Let me show you sudo. 37 00:01:51,260 --> 00:01:55,923 So the first thing to investigate sudo is the id command. 38 00:01:55,923 --> 00:01:57,240 What is this command? 39 00:01:57,240 --> 00:01:59,070 Well, this command is showing the groups 40 00:01:59,070 --> 00:02:01,860 that you are currently a member of. 41 00:02:01,860 --> 00:02:04,410 I'm old centos here, and as you can see, 42 00:02:04,410 --> 00:02:06,240 I'm a member of the group wheel, 43 00:02:06,240 --> 00:02:10,740 which means that I can run tasks with sudo privileges. 44 00:02:10,740 --> 00:02:12,180 Just to make sure that you get it, 45 00:02:12,180 --> 00:02:14,427 I'm using ls - l /root 46 00:02:14,427 --> 00:02:15,810 And what is it giving me? 47 00:02:15,810 --> 00:02:18,540 That's giving me permission denied. 48 00:02:18,540 --> 00:02:21,180 I'm using the up arrow to repeat the last command. 49 00:02:21,180 --> 00:02:22,770 And now I'm using control a 50 00:02:22,770 --> 00:02:24,960 to go to the start of the command line, 51 00:02:24,960 --> 00:02:28,290 followed by sudo ls - l. 52 00:02:28,290 --> 00:02:31,980 And I'm prompted for the root password, that is okay. 53 00:02:31,980 --> 00:02:32,813 Here we go. 54 00:02:32,813 --> 00:02:37,050 I can see the contents of the root directory at this point. 55 00:02:37,050 --> 00:02:38,970 Now the thing is that if you use sudo 56 00:02:38,970 --> 00:02:40,770 in front of an ls command, 57 00:02:40,770 --> 00:02:43,290 then only the ls command is executed 58 00:02:43,290 --> 00:02:45,330 with administrative privileges. 59 00:02:45,330 --> 00:02:48,450 And right now I'm back in my ordinary user shell. 60 00:02:48,450 --> 00:02:52,110 And that's exact exactly how I want it to be. 61 00:02:52,110 --> 00:02:54,930 Alternatively, you can use sudo - i, 62 00:02:54,930 --> 00:02:58,980 which is giving you access to a complete root shell. 63 00:02:58,980 --> 00:03:00,570 Not recommended. 64 00:03:00,570 --> 00:03:03,480 But if it's not recommended why would you wanna do it? 65 00:03:03,480 --> 00:03:06,150 Well, sometimes you need to do administration. 66 00:03:06,150 --> 00:03:09,390 And if you are going to work as an administrator, 67 00:03:09,390 --> 00:03:13,080 then you might want to be in a sudo shell 68 00:03:13,080 --> 00:03:16,653 for the entire day and then this is convenient. 69 00:03:18,090 --> 00:03:20,280 At the end of being in a sudo shell, 70 00:03:20,280 --> 00:03:23,130 you need to type exit to get out of there. 71 00:03:23,130 --> 00:03:25,197 An alternative way is sudo su - 72 00:03:26,970 --> 00:03:28,380 Now, what is the difference? 73 00:03:28,380 --> 00:03:32,032 Well, sudo su - is using the su mechanism 74 00:03:32,032 --> 00:03:34,710 to open a root shell, 75 00:03:34,710 --> 00:03:37,533 and effectively the result is the same. 76 00:03:38,640 --> 00:03:40,830 Now, is there any difference on Ubuntu? 77 00:03:40,830 --> 00:03:42,982 Let's go check it out. 78 00:03:42,982 --> 00:03:45,570 On Ubuntu, if I type id, 79 00:03:45,570 --> 00:03:50,370 then I can see that the user is a member of the adm group. 80 00:03:50,370 --> 00:03:54,030 And the user is also a member of the sudo group. 81 00:03:54,030 --> 00:03:58,260 And basically both of them are granting sudo privileges. 82 00:03:58,260 --> 00:04:02,160 So sudo ls - l /root 83 00:04:02,160 --> 00:04:05,100 is prompting for the password, as expected. 84 00:04:05,100 --> 00:04:06,330 I'm entering the password. 85 00:04:06,330 --> 00:04:10,740 And I can see the contents of the directory /root. 86 00:04:10,740 --> 00:04:14,400 And also sudo - i works on Ubuntu 87 00:04:14,400 --> 00:04:18,690 and sudo su - works on Ubuntu. 88 00:04:18,690 --> 00:04:20,910 So between the Linux distributions, 89 00:04:20,910 --> 00:04:24,390 there is no real difference in using sudo. 90 00:04:24,390 --> 00:04:28,170 The only difference is in how you are making sure 91 00:04:28,170 --> 00:04:31,410 that the user is becoming administrative user 92 00:04:31,410 --> 00:04:33,000 but that's more about user groups, 93 00:04:33,000 --> 00:04:34,923 a topic that we will talk about later.