Force logout Mac users

Yet another one of those write this down Jan, it will come up again posts. There’s almost certainly a better way to force log out absent users on a Mac but heck, this works for me.

To kill off all the processes of a user named joe who’s left logged in but used the user switcher, open up the Terminal app and run these commands.

sudo su -
ps aux | grep ^joe | awk '{ print $2; }' | xargs -I{} kill -9 {}

In my kitchen is the community iMac and I have set up accounts for my whole family. Sometimes people come over and forget to log out but used fast user switching to go to the login screen or a different user.

That’s not too bad, but some software combinations I’m running often take up lots of CPU needlessly. Yes, Firefox and Adobe Flash I mean you. The whole iMac becomes slow and unresponsive.

That makes for a sad Mac. More importantly at 5:30 AM it makes for a sad me. As long as you know Joe’s user id then this will zap all of his processes and log him out as a result.

If some of those processes are stubbornly cling to life then rinse and repeat.

2 thoughts on “Force logout Mac users

  1. Thanks for the command! It works well, except the output of ‘w’ still shows that they are logged in. I use w to remotely check the Macs in the lab to see if anyone has forgotten to logout. However, when I run ps aux |grep ^ it shows no running tasks. Any idea how to tell w that the users are no longer logged in?

    1. Hi Darryl, sorry for not replying sooner. Busy with the impending Christmas holiday. 🙂

      It works well, except the output of ‘w’ still shows that they are logged in.

      I’ve never been able to sort that out and I see the same thing as you do. For me it’s not a problem as I was concerned with the CPU and memory usage. But I’d like to get the users out of the logged in list too and that command doesn’t take care of that issue.

      If I do find a better way I’ll update the post here.

Comments are closed.