Which command would terminate all SSH sessions for a given user?

Prepare for the Red Hat Certified Systems Admin Exam EX200. Enhance your skills with interactive quizzes, flashcards, and detailed explanations. Ace your certification exam today!

Multiple Choice

Which command would terminate all SSH sessions for a given user?

Explanation:
SSH sessions are implemented as per-session sshd processes running under the user’s account. To terminate all of that user’s SSH connections, you want to stop those sshd processes that belong to that user. Using pkill with the user filter and the process name filter does exactly that: pkill -u <username> sshd. The -u option selects processes owned by that user, and giving sshd as the process name narrows the kill to the SSH session processes, ending all active sessions for that user. If you used a broad pattern like pkill -f sshd, you could end sshd processes across all users, which is not what you want. Killing a sleep process would terminate something unrelated. The -U variant targets by real UID instead of effective UID, which isn’t necessary here and could behave differently depending on how processes are started.

SSH sessions are implemented as per-session sshd processes running under the user’s account. To terminate all of that user’s SSH connections, you want to stop those sshd processes that belong to that user. Using pkill with the user filter and the process name filter does exactly that: pkill -u sshd. The -u option selects processes owned by that user, and giving sshd as the process name narrows the kill to the SSH session processes, ending all active sessions for that user.

If you used a broad pattern like pkill -f sshd, you could end sshd processes across all users, which is not what you want. Killing a sleep process would terminate something unrelated. The -U variant targets by real UID instead of effective UID, which isn’t necessary here and could behave differently depending on how processes are started.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy