6 ms·
A peer of mine was exiting their SSH sessions with 'exit'. One time apparently they already typed 'systemctl', probably in an attempt to check the status of a s
by TimWolla 5y ago
A peer of mine was exiting their SSH sessions with 'exit'. One time apparently they already typed 'systemctl', probably in an attempt to check the status of a service, changed their mind and then later wanted to close the session using 'exit', actually executing 'systemctl exit'. This translated into a shutdown of the machine in question.
After being able to piece together what happened with the machine's logs and the bash history I recommended to simply exit all programs/sessions with Ctrl+D. It works almost everywhere and would have prevented this exact issue.
- Denvercoder9 5y agoI recommend not using root privileges unnecessarily. `systemctl status` and most other querying commands don't need root, while the dangerous things like `systemctl exit` do.
- usr1106 5y agoSure, but some systems do poweroff without being root. Has happened to me, don't remember the details. Maybe a polkit thing because users are supposed to shut down their own laptop?
- CraigJPerry 5y agoYeah true, if the user is logged on via a physical tty or local X session (i.e. the policykit subject.local attribute == true) then in some distros they will get permission to shutdown or reboot. They won’t have the permission if connected remotely though.
- TimWolla 5y agoI can't say what they had in mind when typing `systemctl`. Even they couldn't. Because of the delay in the shutdown to cleanly stop the services, they had already forgotten that they just exited a SSH session and thus the connection between the machine being dead and typing `exit` was not obvious. Maybe it was `systemctl status`. Maybe it was intended to be a `reload` (which would require elevated privileges).
- AceJohnny2 5y agoGP's point was more that you shouldn't be able to casually do "systemctl exit" in a standard shell session. All privileged operations should require a sudo. One might be tempted to just do a full "sudo shell" to perform all systemctl operations, but GP's point is that many of the "observation" actions don't require sudo in the first place! In the end, the user being able to accidentally run "systemctl exit" may be indicative of a policy issue (ie don't allow root logins).
- Rapzid 5y agoBut may not be. Maybe the policy is fine and changing it based on one machine shutdown is not worth the costs.
- iso1631 5y agoAll sudo actions on my machines are logged to a remote syslog server (and locally to /var/log/auth.log, which is rotated, compressed, and kept far longer than other logs). That certainly used to be standard. You can't log on as root, you have to log on as your own user and elevate to root (even if that's all you do with sudo), so there's a trail there. This article suggests there are ways for programs to issue unaudited commands with elevated privileges to systemd. "Systemd has a D-Bus interface that people can use, there's hardware events that may trigger a reboot, there are various programs that may decide to ask systemd to reboot the system, and under some circumstances systemd itself can decide that a particular, harmless looking process failure or 'systemctl' transaction actually will trigger a reboot through some weird chain of dependencies and systemd unit settings" Complaining about systemd is as old as systemd, and borders on a religious war, a proxy towards "modern linux" and "old school unix" methods.
- usr1106 5y agoI did not even know that systemctl exit exists. Tye man page says it's equivalent to poweroff (for the system manager not running in a container, i.e. the most common case). Having 2 alternative commands for the same functionality is not a good design decision IMHO. But not the most central design decision for systemd.
- dharmab 5y agothere are already multiple commands for turning the computer off without systemd anyway
- iforgotpassword 5y agoAlmost entirely unrelated, but lately I worked with old photos that had missing, incomplete or wrong exif data. While trying to assess and automate fixing the collection via scripts, I used the command line utility "exif" a lot. You can't imagine how many times I typed "exit somefile.jpg" and flinched when the terminal window just closed. Guess I should just have created an alias but that's like resigning to your own stupidity. ;-)
- mike_hock 5y agoAlso, spam Ctrl+C if you're gonna issue a new command after being AFK for a while.
- lathiat 5y agoI can do one better for exit. The Solaris kernel debugger KDB can be used at runtime for inspecting some stats and also to change some global configurable variables. For whatever reason if you type a variable/symbol it assigns it the value 0. If you type exit nothing happens immediately but as soon as the next process exits usually a few seconds to 10s of seconds later the entire system kernel panics on a null pointer de-reference. Kernel paniced our production ZFS filer twice before I cottoned on. Newer releases special cased “exit” not to do that.
- heavenlyblue 5y agoThat sounds like the most amazing UX I have ever encountered :) For those familiar with Solaris, is there any reason they did it this way? How can you possibly set the default behaviour of assigning any symbol a value of 0 by default?
- gpderetta 5y agoThat's of course due to the principle of maximal astonishment, a time honoured software design law.
- saagarjha 5y agoHey, it’s better than what C does for its variables ;)
- ChuckMcM 5y agobecause adb(1) did it that way.
- zaarn 5y agoSolaris is built on some idiosyncrasies (Speaking as someone who, as a Linux person, has to sysadmin Solaris systems). For example, on our Solaris machines, after install, "reboot" does not do a clean reboot, it's a hard reset. If you want a clean reboot you need "init 6". Same story for "shutdown" and "init 5". "killall" also kills all processes. Not the one you specified. Or more specifically it SIGKILLs all processes that have open files (ssh session and server go byebye). If you type "reboot" or "shutdown", this is in fact the binary that gets called do that. Sadly, Solaris is also one of the few systems that support the NFSv4 ACLs (Linux supports NFSv4 but not the ACL Extension, TrueNAS has a patch for that).
- zorr 5y agoYears ago I had the habit of shutting down my laptop with "sudo shutdown -h now" at the end of the workday. Until one day I did that accidentally in a live SSH session. Since then I always shut down my machine using the GUI and I have Tmux configured with different colors for SSH sessions.
- thanatos519 5y agoThere's a package called molly-guard which can help with that.
- qwertox 5y agoIt's a must on my systems. After I once rebooted the wrong server accidentally, I now force myself to go through the pain of confirming the hostname of the machine. Also, it's possible to circumvent it when you have scripts that need to reboot the machine without interaction by issuing `reboot </dev/null` in the script.
- MattConfluence 5y agoOne time I was using my laptop to remote desktop into a computer I was hundreds of km away from physically, I discovered that if I hit the power key on the laptop (yes, the laptop had a key on the keyboard for power, not a separate power button) while having the remote session window focused, it sent the signal over the wire and put the remote host to sleep instead. Whoops. After that I looked up how to enable wake-on-lan and open up a port to be able to do that remotely.
- ahartmetz 5y agoI don't have the best experience with Wake-on-LAN, it stopped working after a BIOS update or something. So now my desktop is set to turn on when power comes back and it's connected to a WiFi switchable power socket. I bought one with the usual app/cloud rubbish and flashed Tasmota on it.
- iudqnolq 5y ago
- genewitch 5y agoOn average, systems are poo. The median modes around. I prefer openRC, and I'll wave a flag or whatever but to each their own. WinNT4 was goat.
- ungamed 5y agoI'll just get off your lawn.
- danesparza 5y ago... eyeing you suspiciously and backing away ...
- koheripbal 5y agoWhat's wrong with just closing the putty window?
- gruez 5y agoalt-f4 is slightly more efforts to do (requires hand contortions) comapred to writing out a word and typing enter. Also, control-D is easier.
- deleted 5y ago[deleted]
- dec0dedab0de 5y agoMaybe they're not using a GUI ssh client, and wanted to return to their local shell.
- dharmab 5y agoctrl+D/exit doesn't close the window in all cases. eg if you're sshed to a remote it returns you to local.
- corney91 5y agoCtrl+D is great, but will still run a command if it's been typed out so I always Ctrl+C and then Ctrl+D.
- TimWolla 5y agoIt does not for me. If the current command line is not completely empty it will not do anything (both with bash and fish). So if the terminal does not close after pressing Ctrl+D I will know that something is wrong and check more carefully.