如何关闭在另一台计算机上运行的putty上的其他活动会话?

时间:2021-08-24 11:05:09

I am trying to close a putty session that is running on some other computer.

我正在尝试关闭在其他计算机上运行的putty会话。

1 个解决方案

#1


1  

You kill the process ID of the user's login session:

您终止用户登录会话的进程ID:

kill -9 12345

Try running the w command and looking at the output. Something like:

尝试运行w命令并查看输出。就像是:

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:

将显示通过ssh连接的所有用户。更多脚本和自动化可以帮助您缩小登录会话的进程ID:

pgrep -u w | grep ssh| awk '{print $1}' ssh

pgrep -u w | grep ssh | awk'{print $ 1}'ssh

will give you a list of numbers that are the PIDs 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.

将为您提供一个数字列表,这些数字是登录会话的PID。然后,您可以使用ps来验证这是您要杀死的会话。请参阅kill(1),ps和pgrep手册页。

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):

你可以想象并创建一个脚本或shell别名来打印用户和他们的ssh会话(注意:快速破解插图,不便携):

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.

......以及这个主题的其他变化。如果你以这种方式杀死会话,最好有一个脚本或工具,帮助你在kill -9之前识别正确的会话 - 特别是在繁忙的shell登录主机上。更有用的是跨平台和/或POSIX-ish的工具(其他ps等输出格式略有不同)。这种工具可以用perl,ruby或非常小心的sh和awk编写。

#1


1  

You kill the process ID of the user's login session:

您终止用户登录会话的进程ID:

kill -9 12345

Try running the w command and looking at the output. Something like:

尝试运行w命令并查看输出。就像是:

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:

将显示通过ssh连接的所有用户。更多脚本和自动化可以帮助您缩小登录会话的进程ID:

pgrep -u w | grep ssh| awk '{print $1}' ssh

pgrep -u w | grep ssh | awk'{print $ 1}'ssh

will give you a list of numbers that are the PIDs 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.

将为您提供一个数字列表,这些数字是登录会话的PID。然后,您可以使用ps来验证这是您要杀死的会话。请参阅kill(1),ps和pgrep手册页。

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):

你可以想象并创建一个脚本或shell别名来打印用户和他们的ssh会话(注意:快速破解插图,不便携):

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.

......以及这个主题的其他变化。如果你以这种方式杀死会话,最好有一个脚本或工具,帮助你在kill -9之前识别正确的会话 - 特别是在繁忙的shell登录主机上。更有用的是跨平台和/或POSIX-ish的工具(其他ps等输出格式略有不同)。这种工具可以用perl,ruby或非常小心的sh和awk编写。