This post will show you How to Log Off Another Users ssh Connection by Command Line in Mac OS or Linux. SSH, which is known as Secure Shell, is a popular method to generate remote connections to Mac and Linux machines from the command line. If you have SSH activated on a Mac unexpectedly or you have the authority in the system, you may occasionally need to log off other accounts connection. This topic will help you disconnect shh users with several different methods.
Logging Out ssh User with kill command
Step 1. First off, Launch the Terminal on your device and get the process ID (PID) of the users’ ssh connection by typing the following command line and press enter:
ps aux | grep sshd
Then, determine the specific process of the target users ssh connection and aim that with kill -9. In this case, I desire to end the user Walrus’s ssh connection and the process for ‘sshd: [email protected]’ has a PID of 5821:
kill -9 5821
Once the operation is done, the target users will be disconnected and receive a message saying: “Connection to localhost closed by remote host. Connection to localhost closed.”
Broadly Ending a Users SSH Connection and Related Processes with pkill
Indeed, there is another broader method to kill all processes of a specific user account. The command I would like to introduce is “pkill”. This will give you the ability to target directly the user account instead of a process ID like the previous way:
pkill -u username
By using this command line, you will instantly log out the user ‘username’ and eliminate all of that users processes.
Logging Off SSH User from a Mac with Activity Monitor
If you are owning a Mac and GUI is your favorite, you can take the advatage of Activity Monitor to target the task and expire it. To do so, launch Activity Monitor , look for “ssh” and the users ssh connection you want to operate the termination, then stop that process via Activity Monitor.
Notice: Due to the fact that Activity Monitor is designed specifically for Mac, this utility is not available in Linux operating system.
That’s how you can terminate an SSH user in different ways. I hope that those tips are useful for you and thanks for reading the post.