1 00:00:06,660 --> 00:00:10,070 Another topic that is related to users is session management. 2 00:00:11,269 --> 00:00:16,429 There's a couple of commands that allow you to manage what's going on for your users. 3 00:00:16,980 --> 00:00:21,820 To start with, there's the old commands who and W, which is showing who is logged in. 4 00:00:22,780 --> 00:00:29,705 W, in fact, is the shortest command on Linux. It's showing who is logging in and also what they are doing as 5 00:00:29,705 --> 00:00:36,630 a part of the system. The manager of everything, Login CTL has been introduced and Login CTL allows for current session management. 6 00:00:37,509 --> 00:00:42,239 You can use Login CTL List Sessions for a list of sessions currently 7 00:00:42,239 --> 00:00:46,969 active and Login CTL show session for more details about a session id. 8 00:00:47,890 --> 00:00:54,253 There is show user, which is giving more information about the user id. And there is login CTL Terminate session, 9 00:00:54,253 --> 00:01:00,616 which allows you to actually stop a session right now that's pretty convenient if you are figuring out that some 10 00:01:00,616 --> 00:01:06,980 session is active where you don't know what is going on so you want to stop it immediately. 11 00:01:07,579 --> 00:01:10,659 Use loginctl terminate to terminate it right now. 12 00:01:11,780 --> 00:01:16,459 Now, Login CTL is a part of systemd and it might not be 13 00:01:16,459 --> 00:01:21,139 available in your environment. If systemctl is not available, you'll also not have 14 00:01:21,140 --> 00:01:25,819 login ctl, but if it's there, it's a convenient command. I'll show you. 15 00:01:27,260 --> 00:01:31,700 Let me start by using W and W is showing everybody who's logged in right now. 16 00:01:32,329 --> 00:01:36,269 Now I want to log in in a different terminal. 17 00:01:36,930 --> 00:01:40,430 Let me show you the virtual terminal. I'm using CHVT6. 18 00:01:41,549 --> 00:01:47,680 This is opening virtual terminal number six. I do need sudo superpowers. 19 00:01:48,730 --> 00:01:50,200 So what is that bringing me? 20 00:01:51,420 --> 00:01:52,049 Okay, good. 21 00:01:53,170 --> 00:01:57,400 So this is giving me a login prompt and I'm going to log in 22 00:01:57,400 --> 00:02:01,629 as user Anna and I'm providing the very secret password of user Anna. 23 00:02:02,469 --> 00:02:09,074 Now I need su student to open a shell as user student and I 24 00:02:09,074 --> 00:02:15,680 need as user student sudo chvt2 to get back to virtual terminal number two. 25 00:02:16,219 --> 00:02:22,599 And now I'm using W. And look at that. We have user Anna on TTY6 that is shown as well. 26 00:02:23,840 --> 00:02:28,134 I really like W because it's also showing the current activity of the user. 27 00:02:28,134 --> 00:02:32,430 And that's not happening for the who command, which is much more compact. 28 00:02:33,189 --> 00:02:37,129 I also like login ctl. So sudo login CTL 29 00:02:37,129 --> 00:02:41,069 list sessions is showing sessions that are currently active. 30 00:02:41,669 --> 00:02:46,959 And I can also use other commands that login ctl. Let's do a 31 00:02:46,959 --> 00:02:52,249 sudo login CTL tab tab where we can see all the different command 32 00:02:52,250 --> 00:02:57,539 line options like list users, which is just showing me the current users. 33 00:02:59,560 --> 00:03:05,247 Now I want to know what is going on for this user Anna. So let 34 00:03:05,247 --> 00:03:10,935 me use a sudo login CTL show user Anna and there we can see current 35 00:03:10,935 --> 00:03:16,622 settings for my user Anna. Hey, if my user Anna is a user that I 36 00:03:16,622 --> 00:03:22,310 don't expect to be here then I can terminate sessions for user Anna. 37 00:03:22,830 --> 00:03:29,662 I can see the sessions currently open for this user that is 89 and 88 but probably 38 00:03:29,662 --> 00:03:36,495 we want to have a look at list sessions again and there we can see user session 39 00:03:36,495 --> 00:03:43,327 88 with the TTY TTY6. That's probably the one that I need to manage. So I am 40 00:03:43,327 --> 00:03:50,159 going to use sudo login CTL terminate session and that allows me to terminate session number 88. 41 00:03:51,930 --> 00:03:52,750 And there we go. 42 00:03:53,560 --> 00:03:59,954 Session 88 is removed and session 89 is still there. Well we probably need to terminate it as well if we 43 00:03:59,954 --> 00:04:06,349 have no idea what this user is doing on the system. And that's how you can manage current user sessions.