Ad

Logout A User From The System Using A Function In Python

- 1 answer

I am developing a GUI. I have a button that upon clicking it, the system reboot off using:

os.system(reboot now -h)

Now I want a similar button that will logout the user.

logout is not a command in Linux and exit just closes the terminal. Is there a way to logout the user completely back to the login screen?

Ad

Answer

You can use the following Linux command line:

pkill -KILL -u {username}

So if you want to logout the user "ahmed", the command will be like this:

os.system('pkill -KILL -u ahmed')
Ad
source: stackoverflow.com
Ad