Linux查看和剔除當前登入使用者

來源:互聯網
上載者:User

如何在linux下查看當前登入的使用者,並且踢掉你認為應該踢掉的使用者?

看了網路中的一些例子.在這裡總結一下.主要用到的命令有,w,who,ps,kill,pkill查看當前登入使用者:node8:/home # whoroot     :0           2009-11-04 16:26root     pts/0        2009-11-05 13:52 (:0.0)linfengfeiye pts/1        2009-11-07 06:32 (118.113.209.13)第一列是使用者名稱,
第二列是串連的終端,tty表示顯示器,pts表示遠端連線,
第三列是登陸時間,
查看登入使用者行為:
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   21:12m  0.07s  0.49s gnome-terminal --working-direct
linfengf pts/1     06:32    0.00s  0.49s  0.00s sshd: linfengfeiye [priv] 
users 表示當前系統登陸使用者總數為6。LOAD AVERAGE 與後面的數字一起表示系統在過去1,5,10分鐘內的負載程度,數值越小,系統負載越輕。從第二行開始構成一個表格,共有8個欄目,分別顯示各個使用者正在做的事情及該使用者所佔用的系統資料。USER:顯示登陸使用者帳號名。使用者重複登陸,該帳號也會重複出現。TTY:使用者登陸所用的終端。FROM:顯示使用者在何處登陸系統。LOGIN@:是LOGIN AT的意思,表示登陸進入系統的時間。IDLE:使用者空閑時間,從使用者上一次任務結束後,開始記時。JCPU:一終端代號來區分,表示在某段時間內,所有與該終端相關的進程任務所耗費的CPU時間。PCPU:指WHAT域的任務執行後耗費的CPU時間。WHAT:表示當前執行的任務當登陸系統使用者很多的時候,可以在W後面加上某個使用者名稱,則會查看該使用者執行任務的情況
查看linfengfeiye使用者執行任務情況
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] 
查看登陸使用者曆史
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)   
查看sc使用者登入曆史
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)   想踢除linfengfeiye這個使用者和他的所有開啟的程式
pkill -u linfengfeiye
注意:這個命令實際上很危險,要相當小心的執行 原因參考 http://www.blogguy.cn/
安全的做法是先查看終端號,然後查看該終端執行的所有進程,根據進程號來停止服務
安全剔除使用者
ps -ef| grep pts/0
得到使用者登入相應的進程號pid後執行.
kill -9 pid
參考:
http://heidou.bloghome.cn/posts/132821.html
http://www.blogguy.cn/http://blog.csdn.net/linfengfeiye/archive/2009/11/07/4781507.aspxhttp://blog.chinaunix.net/uid-21074389-id-483973.html
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.