Help us understand the problem. What is going on with this article?

不要なユーザを強制ログアウトさせる

More than 5 years have passed since last update.

bashでリモート環境へのセッションが残ってしまったなどの不要なユーザを強制的にログアウトさせるコマンドのメモ。

wコマンドでユーザを調べる

wコマンドでログアウトさせたいユーザを探す

$ w
 20:16:19 up 1 day,  5:45,  2 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
imajo    pts/0    6.41.102.121.dy. 20:09    6:47   0.00s  0.00s -bash
imajo    pts/1    6.41.102.121.dy. 20:10    0.00s  0.01s  0.00s w

pts/0をログアウトさせたい(pts/1のyimajoはwコマンドを使っている自分自身)。

sshdを使っているプロセスを表示

psコマンドからsshdを使ってるプロセスを表示

$ ps ax | grep sshd

出力は次のようになる

$ ps ax | grep sshd
26519 ?        Ss     0:00 /usr/sbin/sshd
27126 ?        Ss     0:00 sshd: yimajo [priv]
27128 ?        S      0:00 sshd: yimajo@pts/0
27148 ?        Ss     0:00 sshd: yimajo [priv]
27150 ?        S      0:00 sshd: yimajo@pts/1
27172 pts/1    S+     0:00 grep sshd

27128が終了させたいプロセス番号ですよと。

killでプロセスを終了させる

killコマンドで9(SIGKILL)を送信してプロセスを終了させる。
kill -9 <プロセスID>で指定するだけ

kill -9 27128

最後にもう一度wコマンドを打ってkillできたかを確認しておわり

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした