Quote:
Originally Posted by LAPIII
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