Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Disconnect users from the terminal System
A question on the Macaddict forums asked how to disconnect other users from an OS X machine using the terminal. One method, courtesy of an experienced UNIX-using friend of mine, is as follows:

1) Type ps aux | grep username, where username is the short name of the user you wish to disconnect.

2) Look for the shell process for the user in question in the 'ps' output. If your users use the standard (tcsh) shell, the process name will be -tcsh (tcsh).

3) Note the process number in the second column. For this example, assume it's 123.

4) Type kill -15 123, where 123 is the actual process number you found in step two. My admittedly poor interpretation of this step is that it attempts to nicely end the processes associated with the user. I'm sure that's not completely correct, but it is the general idea.

5) Type kill -9 123, where 123 is the actual process number from step two. This will end the user's session for certain.

I haven't tried this one myself yet, but I fully expect it will work. Are there other (easier, cleaner?) ways to log out a user from the terminal?
  • Currently 2.00 / 5
  You rated: 2 / 5 (1 vote cast)

Disconnect users from the terminal | 7 comments | Create New Account
Click here to return to the 'Disconnect users from the terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
More info about kill
Authored by: dayfax on Jul 12, '01 01:48:01AM
More than you ever wanted to know about kill can be found at this Linux Journal article.
Some tips : be careful when you are logged into the system as root + use this to kill other user shells. You can accidentally (a) kill off the process that are running your own shell (b) kill off X windows/Aqua, or (c) bring down the entire system.

[ Reply to This | # ]
why ?
Authored by: robh on Jul 12, '01 05:03:46AM

Why on earth would you want to terminate another user's shell ?.
It's not a friendly thing to be doing on a multiuser system.
Root privileges on a multiuser system need to be used responsibly
or you won't be very popular.

[ Reply to This | # ]
why ?
Authored by: robg on Jul 12, '01 10:06:46AM

The question originally came up in response to a crashed machine - the user was still showing up, even though they were no longer there...


[ Reply to This | # ]
why ?
Authored by: robh on Jul 12, '01 01:08:16PM

ah, I see. In that case this is more a question of killing off a rogue process rather than kicking off an unwanted user.

[ Reply to This | # ]
why ?
Authored by: owain_vaughan on Jul 13, '01 11:44:15AM

Yeah, I do something similar to my script on a Solaris machine where the Mac OS 8 NiftyTelnet has timed out, leaving login shells and stale utmp entries lying around.

[ Reply to This | # ]
Try this:
Authored by: owain_vaughan on Jul 12, '01 06:07:15AM

Save this in a file called 'boot' or something similar:


[ $# -lt 1 ] && exit 1
ps -opid,tty,command -U$1 | grep '\-.*sh' | grep -v grep | awk '{ print $1 }' | xargs kill -9

Make it executable with 'chmod 755 boot'
Then type 'boot user' to boot off a user called 'user'

[ Reply to This | # ]
Authored by: sahib! on Jul 13, '01 01:19:28AM
``kill -9'' should only be used as a last resort! Just ``kill xxxx'' where xxxx is the pid (process id) should work in most cases. This allows the process to clean up its own resources before it terminates. ``kill -9'' is the equivalent of "Force Quit" in Mac OS. The process may still leave chunks of memory reserved or stray lock files in the system.

[ Reply to This | # ]