我正在尝试关闭在其他计算机上运行的腻子会话。
You kill
the process ID of the user's login session:
kill -9 12345
Try running the w
command and looking at the output. Something like:
w | grep ssh
will show all users connected via ssh
. More scripting and automation is possible to help you narrow down the process ID of the login session:
pgrep -u w | grep ssh| awk '{print $1}'
w | grep ssh| awk '{print $1}'
w | grep ssh| awk '{print $1}'
ssh
will give you a list of numbers that are the PID
s of the login session. You can then use ps
to verify that this is the session you want to kill
. See the kill(1)
, ps
, and pgrep
manual pages.
You can get fancy and make a script or shell alias to print the users and their ssh sessions (NB: quick hack for illustration, not portable):
for u in `w| grep ssh|awk '{print $1}'`
do
echo -e "\n"$u
pgrep -x -l -u $u ssh
done
... and other variation on this theme. If you are killing sessions this way oftne it's a good idea to have a script or tool that helps you identify the correct session before your kill -9
it - especially on a busy shell login host. Even more useful are tools that are cross platform and/or POSIX
-ish ( w
who
ps
etc. vary slightly in their output formats). That kind of tool can be written in perl
, ruby
or very careful sh
and awk
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.