Skip to main content
added 196 characters in body
Source Link
Human
  • 125
  • 1
  • 6

If you ever want to terminate all active ssh sessions you can use this command (assuming that only ssh is connected to port 22):

kill `sudo lsof -Pni :22 | tail -n1 | grep -wv sshd | awk '{print $2}'`

This command finds all processes connected on port 22, removes the banner of lsof command output, ignores the ssh daemon process and gets all the PIDs, then terminates those PIDs.

If you ever want to terminate all active ssh sessions you can use this command (assuming that only ssh is connected to port 22):

kill `sudo lsof -Pni :22 | grep -wv sshd | awk '{print $2}'`

If you ever want to terminate all active ssh sessions you can use this command (assuming that only ssh is connected to port 22):

kill `sudo lsof -Pni :22 | tail -n1 | grep -wv sshd | awk '{print $2}'`

This command finds all processes connected on port 22, removes the banner of lsof command output, ignores the ssh daemon process and gets all the PIDs, then terminates those PIDs.

Source Link
Human
  • 125
  • 1
  • 6

If you ever want to terminate all active ssh sessions you can use this command (assuming that only ssh is connected to port 22):

kill `sudo lsof -Pni :22 | grep -wv sshd | awk '{print $2}'`