LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 10-02-2005, 08:46 AM   #1
mattengland
Member
 
Registered: Nov 2004
Location: Chicago, IL USA
Posts: 42

Rep: Reputation: 15
Convient & policte way to kick users off system?


What's a convenient and polity way to kick users (currently logged in) off a system?

I'm looking for 2 different ways: 1) a "kick everyone off immediately without being nice" capability for emergencies and time-constrained maintenance, and 2) a "I'm killing everyone's login in X secs/minutes" mechanism that does sends out said message and auto-kicks everyone off (instead of just sending a system message and then manually doing it yourself).

Any suggestions?

-Matt
 
Old 10-02-2005, 09:02 AM   #2
felixc
Member
 
Registered: Jul 2005
Distribution: Debian
Posts: 94

Rep: Reputation: Disabled
Hi,

Sorry if I have completely misunderstood your question, I am a complete newbie... But it seems to me like "shutdown" would do this just fine. Try "shutdown now" for killing all logins (including your own unfortunately), and "shutdown time 5 message" (or something similar, look up the syntax in the man pages) for logging everyone out in 5 minutes (or whatever) and giving a message. I hope this helps, and I haven't just made a fool of myself posting a reply that misunderstands your request completely.

-Felix
 
Old 10-02-2005, 09:05 AM   #3
mattengland
Member
 
Registered: Nov 2004
Location: Chicago, IL USA
Posts: 42

Original Poster
Rep: Reputation: 15
Quote:
Sorry if I have completely misunderstood your question, I am a complete newbie... But it seems to me like "shutdown" would do this just fine. Try "shutdown now" for killing all logins (including your own unfortunately), and "shutdown time 5 message" (or something similar, look up the syntax in the man pages) for logging everyone out in 5 minutes (or whatever) and giving a message. I hope this helps, and I haven't just made a fool of myself posting a reply that misunderstands your request completely.
Well, shutdown would logoff everyone...including my login. I want to kick everyone off but myself--I probably should have mentioned that.

This comes up when I have to do maintenance on things (namely databases) such that I know that no transactions are live on such things.

-Matt
 
Old 10-03-2005, 11:45 AM   #4
TigerOC
Senior Member
 
Registered: Jan 2003
Location: Devon, UK
Distribution: Debian Etc/kernel 2.6.18-4K7
Posts: 2,380

Rep: Reputation: 49
The command init 1 will terminate multiuser services to tty's and place you in single user mode. I am not sure how much warning users will have of this. Running at level 1 will prevent anybody logging into the system as well.
 
Old 10-03-2005, 12:06 PM   #5
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
If you would like to be polite, you could warn your users before you shutdown. Put your polite message in the file shutdown_warning
Then execute wall < shutdown_warning; sleep 120; That will give them 2 mintes warning.
 
Old 10-03-2005, 03:44 PM   #6
mattengland
Member
 
Registered: Nov 2004
Location: Chicago, IL USA
Posts: 42

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by TigerOC
The command init 1 will terminate multiuser services to tty's and place you in single user mode. I am not sure how much warning users will have of this. Running at level 1 will prevent anybody logging into the system as well.
Next previously-unmentioned requirement: I want to keep my web services (and other things served by not requiring an ssh login) up and running even after I kick everyone off ssh.

Quote:
Originally posted by tredegar
If you would like to be polite, you could warn your users before you shutdown. Put your polite message in the file shutdown_warning
Then execute wall < shutdown_warning; sleep 120; That will give them 2 mintes warning.
Same problem as above.

I'm quite surprised no one has mentioned some utility/command to run that automatically logs off another user. Some variant of kill(1) that just kicks them off, or something like that. I could run a 'who -q', see who's on, and then just kick off each user (after disabling ssh logins via /etc/ssh/sshd_config), either manually or via script.

I'm confident this exists in some flavor...I just gotta find it.

-Matt
 
Old 10-03-2005, 04:06 PM   #7
felixc
Member
 
Registered: Jul 2005
Distribution: Debian
Posts: 94

Rep: Reputation: Disabled
If all else fails, create this utility yourself.

Sorry if that sounds ridiculous (if you have no experience in programming it may - if you do have experience then ignore this next part) but it shouldn't be too hard. Check out a few tutorials and even just the basics should suffice. For example, something that used who to identify the users, then parsed the return to get their login IDs, and then looped through each one kicking them off would be fairly simple, I believe. Plus it would make you feel all warm and fuzzy to know you are contributing! (assuming of course you make it freely available etc somewhere). Cheers,

-Felix

PS - Of course, if you have no desire to spend time coding, this whole post was pointless. Sorry for the waste, if so.

PPS - This whole post I talk about "programming" because that is all I have experience with, being new to Linux. Maybe even a simple shell script would be able to do this, without need for any actual programming? I don't know, I'm still learning the basics of that myself.

Last edited by felixc; 10-03-2005 at 04:08 PM.
 
Old 10-03-2005, 04:10 PM   #8
mattengland
Member
 
Registered: Nov 2004
Location: Chicago, IL USA
Posts: 42

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by felixc
If all else fails, create this utility yourself.

Sorry if that sounds ridiculous (if you have no experience in programming it may - if you do have experience then ignore this next part) but it shouldn't be too hard. Check out a few tutorials and even just the basics should suffice. For example, something that used who to identify the users, then parsed the return to get their login IDs, and then looped through each one kicking them off would be fairly simple, I believe.
...I just need the part that "kicks them off." What command/thing/magic-potion does this?

I had planned to do just what you suggest...if I need the full automation (which I really don't right now)...but either way....I need the command to "kick them off."

If it's so easy...can anyone care to share said Linux command that can work on Redhat9 on up (RHEL, FC-*, etc).

Regards,
-Matt
 
Old 10-03-2005, 04:32 PM   #9
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Quote:
...I just need the part that "kicks them off."
Only you know exactly what you mean by that, but I think I get the idea.
One of the beauties of linux is supposed to be that you can use simple tools to create complicated commands. Perhaps you could start by finding out who is logged in (man who), exclude yourself (man grep), and then kill (man kill) all the other logins by PID (man grep cut etc.).

Or maybe someone has already written a script to do this? I will be interested to see the solution.

HTH
 
Old 10-03-2005, 04:39 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Summary: Kill User is a utmp* base shell login utility. *Meaning after using ku there might still be stuff to kill like database users or connections.
 
Old 10-03-2005, 05:14 PM   #11
imitheos
Member
 
Registered: May 2005
Location: Greece
Posts: 441

Rep: Reputation: 141Reputation: 141
As other people said, Linux contains some very good programs that do miracles.

for example take a look to the following script:

#!/bin/bash
for i in `who | cut -d " " -f1`; do
if [ "$i" != "$LOGNAME" ]; then
echo Killing user $i
skill -9 $i
fi
done

It took me 4 seconds to think it so it may crash your pc or kill your cat
Use it at your own risk. ( I am a very bad shell script programmer )

What it is supposed to do is:
who gives the usernames of the users logged in
cut gets the output of who and cuts the first word (the delimiter is " " white space)
so now we have an output of the following form (user1 user2 user3 user4)
then for every user logged in you check to see if he is not you and then you kill him.

The polite script would have a :
wall Every user will be logged off in 1 minute because the system will be upgraded. Thank you
sleep 60
(before the "for" line)

There maybe a hundred ways to do this.
This is the first one that came to my mind. It worked for me but it is not written with every case in mind and it is far from
complete.

Maybe there are some complete programs (like "ku" unSpawn mentioned). You can visit http://freshmeat.net and find.

I suggest though to do as tredegar said.
See the manpages of who,grep,kill,pkill,pgrep,skill,fuser,cut and write your own. A ready app will work but you if you write your
own you will learn much on the way.
 
Old 10-03-2005, 06:09 PM   #12
mattengland
Member
 
Registered: Nov 2004
Location: Chicago, IL USA
Posts: 42

Original Poster
Rep: Reputation: 15
There's one, simple answer to my question: skill(1)

Yes, I'm quite familiar with scripting automation in uinx/linux/bsd/vms (and yes, I know all of csh, tcsh, sh, ksh, bash in unix/linux/bsd and even DCL in VMS). All I needed to know was a reference to the basic command primitive. My initial tests thus far show that skill(1) does what I desire.

Thanks, I knew we'd get there eventually.

-Matt

Quote:
Originally posted by imitheos
As other people said, Linux contains some very good programs that do miracles.

for example take a look to the following script:

#!/bin/bash
for i in `who | cut -d " " -f1`; do
if [ "$i" != "$LOGNAME" ]; then
echo Killing user $i
skill -9 $i
fi
done
 
Old 10-03-2005, 06:20 PM   #13
mattengland
Member
 
Registered: Nov 2004
Location: Chicago, IL USA
Posts: 42

Original Poster
Rep: Reputation: 15
...and for my (and possibly other's) future reference:

pkill(1), pgrep(1) and fuser(1) can be quite handy, too.

Also, I'm also familiar with the incomplete-transactional-problems with kill user processes in the midst of updates. My systems (attempt, anyway) to use atomic transactions (subversion, wikis, databases, my own proprietary software storage system, etc) to address this--for it's all gotta work when someone yanks the power plug, too.

Thanks, again.

-Matt
 
Old 10-03-2005, 07:39 PM   #14
microsoft/linux
Senior Member
 
Registered: May 2004
Location: Sebec, ME, USA
Distribution: Debian Etch, Windows XP Home, FreeBSD
Posts: 1,445
Blog Entries: 9

Rep: Reputation: 48
are you sitting in front of the machine? because if I understand correctly, you want to kick everyone off of ssh? Why not just kill the daemon?
 
Old 10-03-2005, 08:05 PM   #15
mattengland
Member
 
Registered: Nov 2004
Location: Chicago, IL USA
Posts: 42

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by microsoft/linux
are you sitting in front of the machine? because if I understand correctly, you want to kick everyone off of ssh? Why not just kill the daemon?
That kills my login, too (I think). Not good. I want everyone else off but me (and I'm willing to go through and manually run a skill(1)/pkill(1)) while still keeping all my non-ssh things (services, daemons, etc) running.

Again, I'm quite happy to now know about skill(1) and pkill(1).

-Matt
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sort regular users and system users from /etc/passwd joeyBig Red Hat 9 05-29-2008 12:59 AM
Kick existing connected users loadedmind Linux - Security 4 07-26-2005 07:55 AM
Sharing internet & file system between Windows98 & Redhat9 cjs_pro Linux - Networking 2 07-15-2004 07:25 AM
is there any way to see what Users are on My system? Jengo Slackware 5 07-13-2004 02:28 AM
Kick and log users on SSH Quantum0726 Linux - Security 5 01-02-2004 09:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 08:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration