LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/)
-   -   How do I log out via terminal? (https://www.linuxquestions.org/questions/ubuntu-63/how-do-i-log-out-via-terminal-928183/)

TobiSGD 05-06-2013 05:47 AM

If you are using Lubuntu it is no wonder that this doesn't work, this advice is meant for systems that run Gnome 3.

Doogie256 05-11-2013 09:59 AM

works eveywhere
 
# pkill -KILL -u username

Telo 06-30-2017 11:50 PM

Quote:

Originally Posted by andrew.comly (Post 4945834)

sudo pkill -u username
sudo service lightdm restart

Thanks! Works w/ Debian 9.0 Cinnamon 3.2 also, but note: these will not save any work in any windows you have open, i.e. Firefox won't get shutdown properly.

PsychotriaViridis 12-05-2019 11:12 AM

Of course, there is still the option to kill the X-server: ctrl + alt + backspace.
This brings you right to the login screen.

cameronlanders 04-29-2022 01:51 PM

Bash script to create a logout command
 
Quote:

Originally Posted by LAPIII (Post 4596453)
I know how to sudo reboot & sudo shutdown -h now, but not logout!

This answer is for implementing a logout command that you can use from within a terminal, that will logout completely, returning you to the login prompt. Since there is no "built-in" logout command, the best thing to do for a permanent solution that works for all users on your linux machine is to write a simple bash script. Here's how:

1. Create a new file called "logout". In it, place the following:

!# /usr/bin/bash
loginctl terminate-user $(whoami)

2. Save the file to your hoke directory for now.

3. Mark the file as executable:
sudo chmod +X logout

If all went well, when you do an ls -l you should see that the file now has execute permissions.

4. The final step is to move the file to the /usr/bin folder:
sudo mv ~/logout /usr/bin/logout

You should now be able to simply type logout from any terminal to completely logout.

How this works:
The command in the bash script simply calls the loginctl command and feeds it the name of the currently-logged-in user. This creates a single-word command to logout without having to specify your user name.It just works, no matter which terminal, window manager or linux distro you use.

Cheers,
-=Cameron


All times are GMT -5. The time now is 10:55 AM.