Linux - SecurityThis forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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).
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.
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.
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.
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.
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.
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.
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).
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.
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.
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
...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.
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.