Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to view and remove currently logged in users by Linux

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to Linux view and remove currently logged-in users", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to Linux view and remove currently logged-in users.

How to view the currently logged-in users under Linux and kick out the users you think should be kicked out?

Look at some examples in the network. Let's sum it up here. The main commands used are, wQuery whorepkill pkill.

View the currently logged in user:

Node8:/home # who

Root: 0 2009-11-04 16:26

Root pts/0 2009-11-05 13:52

Linfengfeiye pts/1 2009-11-07 06:32 (118.113.209.13)

The first column is the user name

The second column is the connected terminal, tty for monitor and pts for remote connection

The third column is the landing time

View the behavior of logged-in users:

Node8:/ # w

07:46:35 up 2 days, 15:35, 6 users, load average: 0.03, 0.07, 0.02

USER TTY LOGIN@ IDLE JCPU PCPU WHAT

Root: 0 Wed16? xdm? 35:59 0.26s / opt/gnome/bin/gnome-session

Root pts/0 Thu13 21VR 12m 0.07s 0.49s gnome-terminal-- working-direct

Linfengf pts/1 06:32 0.00s 0.49s 0.00s sshd: linfengfeiye [priv]

Users says the total number of users logged in to the system is 6.

LOAD AVERAGE, together with the following numbers, indicates the load degree of the system in the past 10 minutes. The smaller the number, the lighter the system load.

A table is formed from the second row, with a total of eight columns showing what each user is doing and the system data occupied by the user.

USER: displays the login user account name. If the user logs in repeatedly, the account will also be repeated.

TTY: the terminal used by the user to log in.

FROM: shows where the user logs in to the system.

LOGIN@: means LOGIN AT and indicates the time when you log in and enter the system.

IDLE: the idle time of the user, starting from the end of the user's last task.

JCPU: a terminal code that indicates the CPU time spent by all process tasks associated with the terminal in a certain period of time.

PCPU: refers to the CPU time spent after the task of the WHAT domain is executed.

WHAT: indicates the currently executed task

When there are many users logging in to the system, you can add a user name after W, and you will check how the user performs the task.

View tasks performed by linfengfeiye users

Node8:/ # w linfengfeiye

07:40:45 up 2 days, 15:29, 6 users, load average: 0.07, 0.08, 0.02

USER TTY LOGIN@ IDLE JCPU PCPU WHAT

Linfengf pts/1 06:32 0.00s 0.48s 0.00s sshd: linfengfeiye [priv]

View the history of logged in users

Node8:/ # last

Linfengf pts/1 118.113.209.13 Sat Nov 7 06:32 still logged in

Root pts/1 118.113.209.13 Sat Nov 7 06:12-06:32 (00:20)

Root pts/4 118.113.209.13 Sat Nov 7 05:15-06:11 (00:55)

Root pts/2 118.113.209.13 Sat Nov 7 04:21-06:41 (02:20)

Sc pts/5 222.211.247.164 Fri Nov 6 22:16-22:36 (00:20)

Root pts/2 222.211.247.164 Fri Nov 6 21:53-22:36 (00:42)

Root pts/4 222.211.247.164 Fri Nov 6 19:59-23:08 (03:08)

Sc pts/8 222.211.247.164 Fri Nov 6 19:57-22:16 (02:18)

Root pts/7 222.211.247.164 Fri Nov 6 19:42-22:36 (02:53)

Root pts/6 222.212.68.214 Fri Nov 6 19:39-21:40 (02:00)

Sc pts/5 222.212.68.214 Fri Nov 6 19:36-21:39 (02:03)

View sc user login history

Node8:/ # last sc

Sc pts/5 222.211.247.164 Fri Nov 6 22:16-22:36 (00:20)

Sc pts/8 222.211.247.164 Fri Nov 6 19:57-22:16 (02:18)

Sc pts/6 118.113.236.146 Fri Nov 6 16:39-16:43 (00:03)

Sc pts/4 10.3.2.40 Fri Nov 6 11:30-13:42 (02:12)

Want to kick out the user linfengfeiye and all his open programs

Pkill-u linfengfeiye

Note: this command is actually very dangerous, you should be very careful to execute the reason, refer to http://www.blogguy.cn/

The safe way is to check the terminal number first, and then check all the processes executed by the terminal, and stop the service according to the process number.

Safely culling users

Ps-ef | grep pts/0

It is executed after the user logs in to the corresponding process number pid.

Kill-9 pid

Reference:

Http://heidou.bloghome.cn/posts/132821.html

Http://www.blogguy.cn/

[gpadmin@gpdb-sandbox pts] $ls

[gpadmin@gpdb-sandbox pts] $lsof | grep pts | more

[gpadmin@gpdb-sandbox pts] $w

23:02:02 up 29 days, 1:02, 11 users, load average: 0.00, 0.00, 0.00

USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

Root pts/0 172.16.255.1 Tue23 101m 0.11s 0.02s-bash

Root pts/1 172.16.255.1 22:50 0.00s 0.02s 0.00s w

Root pts/2 172.16.255.1 12:49 10 11m 0.00s 0.00s-bash

Root pts/3 172.16.255.1 Sun19 4days 1VR 30m 6:38 / usr/java/jdk1.8.0_121/bin/java-Dgfsh=true-Dlog4j.configurationFile=classpath:log4j2-cli.xml-classpath / home

Gpadmin pts/5 gpdb-sandbox.loc 27Dec16 9days 0.02s 0.02s-bash

Gpadmin pts/7 gpdb-sandbox.loc 26Dec16 10days 0.01s 0.01s-bash

Root pts/8 172.16.255.1 22:56 5:03 0.00s 0.00s-bash

Gpadmin pts/10 gpdb-sandbox.loc 27Dec16 9days 0.00s 0.00s-bash

Gpadmin pts/12 gpdb-sandbox.loc 27Dec16 9days 0.00s 0.00s-bash

Gpadmin pts/14 gpdb-sandbox.loc Mon04 3days 0.01s 0.01s-bash

Root pts/16 172.16.255.1 Mon06 2days 0.03s 0.03s-bash

[gpadmin@gpdb-sandbox pts] $ps-ef | grep 44324

Gpadmin 44324 10 2016? 00:00:00 / usr/bin/ssh-o BatchMode=yes-o StrictHostKeyChecking=no-Q-l gpadmin gpdb-sandbox

Gpadmin 95960 95443 0 23:02 pts/1 00:00:00 grep 44324

[gpadmin@gpdb-sandbox pts] $kill 44324

[gpadmin@gpdb-sandbox pts] $ps-ef | grep 44324

Gpadmin 95962 95443 0 23:03 pts/1 00:00:00 grep 44324

At this point, I believe you have a better understanding of "how to Linux view and remove currently logged in users". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report