1 00:00:06,540 --> 00:00:09,330 - In this video, we are going to explore the use of su. 2 00:00:09,330 --> 00:00:11,850 Su is for switch user. 3 00:00:11,850 --> 00:00:15,510 It allows you to open a shell as any specific user. 4 00:00:15,510 --> 00:00:17,940 For instance, if you use su Lisa, 5 00:00:17,940 --> 00:00:19,740 then it'll prompt for a password 6 00:00:19,740 --> 00:00:22,110 and open a shell as user Lisa. 7 00:00:22,110 --> 00:00:24,210 Notice that it will only prompt for a password. 8 00:00:24,210 --> 00:00:26,550 If you are doing this as an ordinary user, 9 00:00:26,550 --> 00:00:29,250 user root can open a shell as any user 10 00:00:29,250 --> 00:00:31,620 without entering a password. 11 00:00:31,620 --> 00:00:35,730 If you just use su, then it'll prompt for the root password 12 00:00:35,730 --> 00:00:37,233 and open a root shell. 13 00:00:38,460 --> 00:00:42,960 You use su without any further arguments to open a subshell. 14 00:00:42,960 --> 00:00:45,810 Subshell means that not all environments 15 00:00:45,810 --> 00:00:48,090 are set as the target user. 16 00:00:48,090 --> 00:00:51,450 If you use su -, you open a login shell. 17 00:00:51,450 --> 00:00:53,610 In a login shell, environment variables 18 00:00:53,610 --> 00:00:55,714 are set as the target user. 19 00:00:55,714 --> 00:00:58,890 The result is that su - is the better solution 20 00:00:58,890 --> 00:01:00,030 because it guarantees 21 00:01:00,030 --> 00:01:03,060 that you are in the appropriate environment. 22 00:01:03,060 --> 00:01:06,409 The user root can use su to become any other user 23 00:01:06,409 --> 00:01:08,370 without entering a password. 24 00:01:08,370 --> 00:01:10,950 And a regular users can use su as well, 25 00:01:10,950 --> 00:01:14,103 but they need to enter the target user password. 26 00:01:15,090 --> 00:01:16,413 Let's go check this out. 27 00:01:18,600 --> 00:01:22,170 So as you can see, I'm in a shell, su is a student. 28 00:01:22,170 --> 00:01:25,710 And in the shell su student, I can type su - 29 00:01:25,710 --> 00:01:27,630 and it'll prompt for a password. 30 00:01:27,630 --> 00:01:30,870 And right now, I'm in a root shell. 31 00:01:30,870 --> 00:01:32,430 You can recognize the root shell 32 00:01:32,430 --> 00:01:35,820 because I have a root@centos with a hash 33 00:01:35,820 --> 00:01:38,253 and that is showing that I'm in a root shell. 34 00:01:39,180 --> 00:01:41,460 So if I type whoami, for instance, 35 00:01:41,460 --> 00:01:43,999 then I can see that I'm root. 36 00:01:43,999 --> 00:01:46,860 This is one way to open a temporary root shell. 37 00:01:46,860 --> 00:01:50,130 Disadvantages that in order to use su -, 38 00:01:50,130 --> 00:01:53,703 you need to know the root password. 39 00:01:54,660 --> 00:01:58,050 Now as a root, I can use su Linda 40 00:01:58,050 --> 00:01:59,700 to open a shell as user Linda. 41 00:01:59,700 --> 00:02:01,350 As you can see, I'm not prompted 42 00:02:01,350 --> 00:02:03,810 for any password whatsoever. 43 00:02:03,810 --> 00:02:06,270 To exit from the shell you type exit. 44 00:02:06,270 --> 00:02:08,940 I just did, and that brings me back to the root shell. 45 00:02:08,940 --> 00:02:12,453 And if I type exit again, then I'm back in my student shell. 46 00:02:13,290 --> 00:02:15,060 Now I want to show you what is happening 47 00:02:15,060 --> 00:02:17,610 if I use su - linda. 48 00:02:17,610 --> 00:02:21,060 Again, I would advise you always to use su - 49 00:02:21,060 --> 00:02:23,190 because really you want to set the environment 50 00:02:23,190 --> 00:02:24,360 the right way. 51 00:02:24,360 --> 00:02:26,370 So su - linda doing what, 52 00:02:26,370 --> 00:02:28,200 it's prompting for the password Linda. 53 00:02:28,200 --> 00:02:29,070 And you know what? 54 00:02:29,070 --> 00:02:30,540 Linda doesn't have a password 55 00:02:30,540 --> 00:02:32,460 so I can try whatever I want. 56 00:02:32,460 --> 00:02:34,623 This is not going to work. 57 00:02:35,820 --> 00:02:37,773 Now, let's also do this on Ubuntu. 58 00:02:39,750 --> 00:02:40,653 So here we go. 59 00:02:41,490 --> 00:02:44,010 I am user student right now, 60 00:02:44,010 --> 00:02:46,590 and what is happening if I use su -, 61 00:02:46,590 --> 00:02:48,900 well it's prompting for the root password. 62 00:02:48,900 --> 00:02:51,420 And what is the root password? 63 00:02:51,420 --> 00:02:54,090 Well, that is exactly the problem. 64 00:02:54,090 --> 00:02:57,482 The root user on Ubuntu does not have a password. 65 00:02:57,482 --> 00:03:01,470 Su and su - straight like this on Ubuntu 66 00:03:01,470 --> 00:03:02,760 is not a good option. 67 00:03:02,760 --> 00:03:05,040 On Ubuntu, you go for sudo. 68 00:03:05,040 --> 00:03:08,103 And that is what is going to be discussed in the next video.