Ori Levy
Ori Levy

Reputation: 111

logout a user from the system using a function in python

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?

Upvotes: 1

Views: 806

Answers (1)

Ahmed Arafa
Ahmed Arafa

Reputation: 500

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')

Upvotes: 2

Related Questions