Hello, Short of rebooting, how to close an open session of a user who is logged in? Thank you, James
On Tuesday 08 August 2006 19:27, James D. Parra wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in?
How are they logged in? console? X? ssh? ...
Thank you,
James
-- "The man who strikes first admits that his ideas have given out." (Chinese Proverb)
On Tuesday 08 August 2006 2:27 pm, James D. Parra wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in? If the user is logged in either via text mode or remotely, there is a controlling terminal. The who(1) command will tell you the controlling terminal of that user. All you need to do is to find out the top level shell and kill it:
[me@olduvai me]$ who me pts/1 Aug 3 08:01 (sys254.aaa.bbb.ccc.com) user1 pts/2 Aug 3 11:01 (bart.ddd.com) user2 pts/3 Aug 5 02:47 (pool-141-149-182-8.bos.east.verizon.net) [gaf@olduvai gaf]$ ps ax | grep pts/2 6224 ? S 0:00 sshd: user1@pts/2 6225 pts/2 S 0:00 -bash 407 pts/1 R 0:00 grep pts/2 As root you can kill either process 6224 or 6225. This will force that user off. If you want to log out the user who logged in via the x session on the console, then kill the entire x session. I prefer using the 'init 3' approach, but you can also kill the X session: 5196 tty7 Ss+ 55:34 /usr/X11R6/bin/X -br -nolisten tcp :0 vt7 -auth /var/lib/xdm/authdir/authfiles/A:0-WXGTlf $ kill -TERM 5196 -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
On Tuesday 08 August 2006 2:27 pm, James D. Parra wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in? You rarely ever need to reboot linux.
-- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
On 8/8/06, James D. Parra <Jamesp@musicreports.com> wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in?
Here is what we use on one of our LTSP servers. It's not a good way to do it, there must be better way to logoff users than killing all the processes belonging to that user. Linux being multisuser system, there must be simpler way of doing this if there already isnt. Till then this one works -J #!/bin/bash echo -n "enter username to log out:" read user ps U $user | cut -d "?" -f 1 > /tmp/killuser.txt find /tmp -user $user ? /tmp/usertmpfiles.txt cat /tmp/killuser.txt | \ while read pid do kill -9 $pid done cat /tmp/usertmpfiles.txt | \ while read filename do rm -f $filename rm -f /tmp/killuser.txt rm -f /tmp/usertmpfiles.txt done echo "User logged off"
Jigish Gohil wrote:
On 8/8/06, James D. Parra <Jamesp@musicreports.com> wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in?
Here is what we use on one of our LTSP servers. It's not a good way to do it, there must be better way to logoff users than killing all the processes belonging to that user.
Linux being multisuser system, there must be simpler way of doing this if there already isnt. Till then this one works
What's wrong with "killall -u"?
On Wed, 2006-08-09 at 11:11 +0530, Jigish Gohil wrote:
On 8/8/06, James D. Parra <Jamesp@musicreports.com> wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in?
Here is what we use on one of our LTSP servers. It's not a good way to do it, there must be better way to logoff users than killing all the processes belonging to that user.
Linux being multisuser system, there must be simpler way of doing this if there already isnt. Till then this one works
-J
#!/bin/bash echo -n "enter username to log out:" read user ps U $user | cut -d "?" -f 1 > /tmp/killuser.txt find /tmp -user $user ? /tmp/usertmpfiles.txt cat /tmp/killuser.txt | \ while read pid do kill -9 $pid
Not good. Use "kill -1" first and then "kill -9" if there are still processes left running. Using kill -9 will no doubt leave you with an unstable system sooner then later. -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998
On Tuesday 08 August 2006 20:27, James D. Parra wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in?
Would that be you, logged in more that once (perhaps using one or more different logins), or would that be another person? If it's you, wel, you know best... ;) If it's another person, perhaps "man shutdown" could be of use: it allows you to send a warning to all users who are logged in over a text console, together with specifying a delay (e.g. "Warning: the system will shut down in 5 minutes. Save your work and logout immediately."). I suppose you could come up with nicer messages... ;) Cheers, Leen
On Monday 21 August 2006 2:07 pm, Leendert Meyer wrote:
On Tuesday 08 August 2006 20:27, James D. Parra wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in?
Would that be you, logged in more that once (perhaps using one or more different logins), or would that be another person?
If it's you, wel, you know best... ;)
If it's another person, perhaps "man shutdown" could be of use: it allows you to send a warning to all users who are logged in over a text console, together with specifying a delay (e.g. "Warning: the system will shut down in 5 minutes. Save your work and logout immediately."). I suppose you could come up with nicer messages... ;) The OP stated "short of rebooting". You can easily use the wall(1) command to broadcast a message to all those who are logged in. Or, you can use the write(1) command to send a message to a specific user.
Then, a simple kill(1) directed at the controlling terminal will cause any specific user to be logged out. You could write a simple shell or perl script to look at who is logged in (who), parse it to get the terminal (eg. pts/1 tty1, ttyS1, ...) then do a ps ax and simply kill all processes associated. -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
On Monday 21 August 2006 20:30, Jerry Feldman wrote:
On Monday 21 August 2006 2:07 pm, Leendert Meyer wrote:
On Tuesday 08 August 2006 20:27, James D. Parra wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in?
Would that be you, logged in more that once (perhaps using one or more different logins), or would that be another person?
If it's you, wel, you know best... ;)
If it's another person, perhaps "man shutdown" could be of use: it allows you to send a warning to all users who are logged in over a text console, together with specifying a delay (e.g. "Warning: the system will shut down in 5 minutes. Save your work and logout immediately."). I suppose you could come up with nicer messages... ;)
The OP stated "short of rebooting".
Yes, he did. Your point? :)
You can easily use the wall(1) command to broadcast a message to all those who are logged in. Or, you can use the write(1) command to send a message to a specific user.
Indeed.
Then, a simple kill(1) directed at the controlling terminal will cause any specific user to be logged out. You could write a simple shell or perl script to look at who is logged in (who), parse it to get the terminal (eg. pts/1 tty1, ttyS1, ...) then do a ps ax and simply kill all processes associated.
Why is that better? If I am logged in twice (ssh) on a remote pc, and I issue a "shutdown -h now; exit" on one terminal, then the other terminal gets a warning message, and that connection is closed. So why all the extra work? (I've switched myself into learning mode... ;) Cheers, Leen
On Monday 21 August 2006 21:32, Leendert Meyer wrote:
Why is that better? If I am logged in twice (ssh) on a remote pc, and I issue a "shutdown -h now; exit" on one terminal, then the other terminal gets a warning message, and that connection is closed. So why all the extra work? (I've switched myself into learning mode... ;)
Rebooting just to log out a user? can I interest you in a sidewinder missile, perfect for hunting rabbit
On Monday 21 August 2006 21:34, Anders Johansson wrote:
On Monday 21 August 2006 21:32, Leendert Meyer wrote:
Why is that better? If I am logged in twice (ssh) on a remote pc, and I issue a "shutdown -h now; exit" on one terminal, then the other terminal gets a warning message, and that connection is closed. So why all the extra work? (I've switched myself into learning mode... ;)
Rebooting just to log out a user?
We were not talking about that (rebooting just to log out a user). Cheers, Leen
On Monday 21 August 2006 21:56, Leendert Meyer wrote:
On Monday 21 August 2006 21:34, Anders Johansson wrote:
On Monday 21 August 2006 21:32, Leendert Meyer wrote:
Why is that better? If I am logged in twice (ssh) on a remote pc, and I issue a "shutdown -h now; exit" on one terminal, then the other terminal gets a warning message, and that connection is closed. So why all the extra work? (I've switched myself into learning mode... ;)
Rebooting just to log out a user?
We were not talking about that (rebooting just to log out a user).
"We" weren't, but it sure looked like you were. shutdown -h powers off the machine. What did you intend for it to do? The OP wanted simply to forcibly log out a user (not all users)
On Monday 21 August 2006 22:08, Anders Johansson wrote:
On Monday 21 August 2006 21:56, Leendert Meyer wrote:
On Monday 21 August 2006 21:34, Anders Johansson wrote:
On Monday 21 August 2006 21:32, Leendert Meyer wrote:
Why is that better? If I am logged in twice (ssh) on a remote pc, and I issue a "shutdown -h now; exit" on one terminal, then the other terminal gets a warning message, and that connection is closed. So why all the extra work? (I've switched myself into learning mode... ;)
Rebooting just to log out a user?
We were not talking about that (rebooting just to log out a user).
"We" weren't, but it sure looked like you were. shutdown -h powers off the machine. What did you intend for it to do?
The OP wanted simply to forcibly log out a user (not all users)
Aha! Someone else (Jerry) pointed me at "Short of rebooting", but I did not understand him. That would mean probably something like "up to but not including rebooting". I thought it meant "right before rebooting" or "at the point of rebooting", and actually doing the "rebooting". I was wrong. Ok. Learned something. Thanks. :) (These kind of situations always remind me of the song "Communication Breakdown", Led Zeppelin I, which it was, sort of...) Cheers, Leen
Anders Johansson wrote:
On Monday 21 August 2006 21:32, Leendert Meyer wrote:
Why is that better? If I am logged in twice (ssh) on a remote pc, and I issue a "shutdown -h now; exit" on one terminal, then the other terminal gets a warning message, and that connection is closed. So why all the extra work? (I've switched myself into learning mode... ;)
Rebooting just to log out a user?
can I interest you in a sidewinder missile, perfect for hunting rabbit
I'll take two :-) -- Hans Krueger hanskrueger@adelphia.net registered Linux user 289023 411024
* Hans Krueger <hanskrueger@adelphia.net> [08-24-06 13:07]:
I'll take two :-)
Please remit payment via certified check. Address and recipient and terms will be provided via direct email, forthwith. -- Patrick Shanahan Registered Linux User #207535 http://wahoo.no-ip.org @ http://counter.li.org HOG # US1244711 Photo Album: http://wahoo.no-ip.org/gallery2
On Monday 21 August 2006 20:07, Leendert Meyer wrote:
On Tuesday 08 August 2006 20:27, James D. Parra wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in?
Would that be you, logged in more that once (perhaps using one or more different logins), or would that be another person? ... If it's another person, perhaps "man shutdown" could be of use: it allows you to send a warning to all users who are logged in over a text console, together with specifying a delay (e.g. "Warning: the system will shut down in 5 minutes. Save your work and logout immediately."). I suppose you could come up with nicer messages... ;)
Try, from a console, as root: init S That will drop the system into single user mode, kicking out anyone logged in. From there you can log back in and run: init 3 or: init 5 depending on whether you want console mode (3) or X11 mode (5). -- ----- stephan@s11n.net http://s11n.net "...pleasure is a grace and is not obedient to the commands of the will." -- Alan W. Watts
stephan beal wrote:
On Monday 21 August 2006 20:07, Leendert Meyer wrote:
On Tuesday 08 August 2006 20:27, James D. Parra wrote:
Hello,
Short of rebooting, how to close an open session of a user who is logged in?
Would that be you, logged in more that once (perhaps using one or more different logins), or would that be another person?
...
If it's another person, perhaps "man shutdown" could be of use: it allows you to send a warning to all users who are logged in over a text console, together with specifying a delay (e.g. "Warning: the system will shut down in 5 minutes. Save your work and logout immediately."). I suppose you could come up with nicer messages... ;)
Try, from a console, as root:
init S
That will drop the system into single user mode, kicking out anyone logged in. From there you can log back in and run:
init 3
or:
init 5
depending on whether you want console mode (3) or X11 mode (5). I fully see the point in going to single user mode and then back to X, sort of. I would, similar to the OP, like to know how it is possible to close a login of a single user ie can I use 'kill -9 [pid]', or 'kill [username]'?
And before someone points me there I have RTFM and seen that the above commands cannot be done. I think the OP wants to 'kill' a user and is posibly misguided by the kill command. Can anyone comment on the use of ps to close the login of another user WITHOUT having to logout and in again courtesy of init 3/5? -- ======================================================================== Currently using SuSE 9.2 Professional with KDE and Mozilla 1.7.2 Linux user # 229959 at http://counter.li.org ========================================================================
Hylton Conacher(ZR1HPC) wrote:
stephan beal wrote: I fully see the point in going to single user mode and then back to X, sort of. I would, similar to the OP, like to know how it is possible to close a login of a single user ie can I use 'kill -9 [pid]', or 'kill [username]'?
And before someone points me there I have RTFM and seen that the above commands cannot be done.
I think the OP wants to 'kill' a user and is posibly misguided by the kill command. Can anyone comment on the use of ps to close the login of another user WITHOUT having to logout and in again courtesy of init 3/5?
If it's a remote user, just kill their ssh pid. If it's a local user, just kill their bash pid.
If it's a remote user, just kill their ssh pid.
If it's a local user, just kill their bash pid.
Even if it is a remote user, kill their bash pid (in case it is a shell, otherwise sftp-server or whatever subsystem is on) Jan Engelhardt --
participants (15)
-
Anders Johansson
-
Dylan
-
Hans Krueger
-
Hylton Conacher(ZR1HPC)
-
James D. Parra
-
James Knott
-
Jan Engelhardt
-
Jerry Feldman
-
Jigish Gohil
-
Ken Schneider
-
Leendert Meyer
-
Patrick Shanahan
-
stephan beal
-
suse@rio.vg
-
Troy Schultz