Logout, reboot and shutdown using the terminal

My workflow is usually very terminal-centric, I prefer to type, rather than click on things. I spend most of my day using Konsole.

When I want to log out of my Plasma session, I run a command:

qdbus org.kde.ksmserver /KSMServer logout 0 0 1

If you replace 0 0 1 in that command with 1 0 1, it will display the logout window giving you the option to cancel it, shutdown or restart your computer. This does exactly the same thing as clicking on the Log out button, saves your session and everything.

Here is what the three numbers do. They are in this order:

ShutdownConfirm ShutdownType ShutdownMode

ShutdownConfirm can take the following values:

-1: default
0: no
1: yes

ShutdownType can take the following values:

-1: default
0: none (log out)
1: reboot
2: halt (shutdown)
3: logout (same as 0? no idea…)

and finally, ShutdownMode can be:

-1: default
0: schedule
1: try now
2: force now
3: interactive

So, if you run the above command with, for example 0 1 1, this will restart your computer without any prompt (if you want a prompt, use 1 1 1). That’s similar to running the systemctl reboot command, but better, because it gracefully ends your Plasma session and logs you out before rebooting.

Similarly, 0 2 1 will shut down your computer, similar to shutdown now command, but again, logging you out from your plasma session.

Of course, that qdbus command is a lot of typing, so I use an alias.

This is how you can set it up. If you’re using Bash, add this to your .bashrc:

alias logout="shopt -q login_shell && logout || qdbus org.kde.ksmserver /KSMServer logout 0 0 1"

Or if you’re using zsh, add this to your .zshrc:

alias logout="[[ -o login ]] && logout || qdbus org.kde.ksmserver /KSMServer logout 0 0 1"

Then you can logout by running:


The alias overrides the normal logout command which you’d use in the TTY to log out of a login session. To retain the original functionality, it first tests whether you’re in a login shell (in which case it runs the normal logout command) or, if you’re not in a login shell, it runs that long qdbus command that logs you out of your Plasma session.

All of this is, of course, applicable to any scripts as well.


I actually happened to be browsing the ksmserver code recently and it appears that this was a mistake and can be ignored. It’ll be removed in Plasma 6.

1 Like

OOrrrrr… :rofl:

1 Like

Using systemclt reboot and systemctl poweroff with Plasma is not ideal, because it doesn’t log you out of your Plasma session, so it does not execute all the logout stuff Plasma does, like saving the current session (if you have that enabled) and running any scripts you have set to run on shutdown.

It is faster, though, because of that.

True. Like you said, I don’t do session save. It’s something I put together once, years ago, since I’m actually an openbox nut and I needed something quick. Nevertheless, been using it in plasma for a good while for ease of use and moreover, no typing. Hate keyboard stuff. Was just foolin’ around. I’ll delete it if you like.

You could modify your script by replacing:

loginctl terminate-user john → qdbus org.kde.ksmserver /KSMServer logout 0 0 1
systemctl reboot             → qdbus org.kde.ksmserver /KSMServer logout 0 1 1
systemctl poweroff           → qdbus org.kde.ksmserver /KSMServer logout 0 2 1

Or you can leave it as it is, I don’t think there is any problem with it, except that it doesn’t properly log you out of your Plasma session.

1 Like

Thanks. I’ll give it a swing. Maybe I’ll try something else instead of ol’ man style zenity. Got jgmenu installed, might as well use a second, rofi styled, one with those commands. :beers:

1 Like

It seems there’s no KSMServer option than can be used instead of the command systemctl reboot --firmware-setup?

When I want to log out of my Plasma session, I run a command:

Please don’t use that.

 qdbus org.kde.LogoutPrompt /LogoutPrompt  org.kde.LogoutPrompt.promptLogout
 qdbus org.kde.LogoutPrompt /LogoutPrompt  promptReboot
qdbus org.kde.LogoutPrompt /LogoutPrompt  promptShutdown

to get a prompt


qdbus org.kde.Shutdown /Shutdown  org.kde.Shutdown.logout


to perform an action without prompt

This works in Plasma 5 since a few years, the ksmserver API will be gone in Plasma 6. I didn’t get rid of it at the time given how much the old API has been copy pasted about the internet.