How to properly end a KDE session from shell without root privileges
You can send a logout command via dbus to KDE, which should (if it can) terminate the session. qdbus org.kde.ksmserver /KSMServer logout 0 0 0 dbus is a messaging system that lets applications communicate with each other, and the qdbus command is a utility for sending dbus messages to applications.
https://superuser.com/questions/395820/how-to-properly-end-a-kde-session-from-shell-without-root-privileges