Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I logout from a computer using shell?

Tags:

linux

bash

How can I log out of my computer using shell such the log-in window appears again?

I need this functionality in one my Linux script.

Update: I want to replicate the code working behind the Logout button of my Ubuntu.

Desktop Enviroment being used: GNOME

like image 506
Usman Avatar asked Feb 04 '23 04:02

Usman


2 Answers

I think this does the job:

gnome-session-save --logout

Also, take a look at the --help output, maybe you want to use the --force-logout option.

Usage:
  gnome-session-save [OPTION...]

Help Options:
  -h, --help               Show help options
  --help-all               Show all help options
  --help-gtk               Show GTK+ Options

Application Options:
  --logout                 Log out
  --force-logout           Log out, ignoring any existing inhibitors
  --logout-dialog          Show logout dialog
  --shutdown-dialog        Show shutdown dialog
  --gui                    Use dialog boxes for errors
  --display=DISPLAY        X display to use
like image 77
theDmi Avatar answered Feb 05 '23 19:02

theDmi


Your question is a bit vague. Are you trying to log out of a graphical session of a desktop environment (such as KDE/Gnome), as if the user clicked on "log off"?

Then you need to find out if/how the desktop environment supports scripting to log out. On KDE for example you can use kquitapp.

like image 32
sleske Avatar answered Feb 05 '23 17:02

sleske