- command to log the current user out of the system?
- 2 Answers 2
- You must log in to answer this question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- 4 Ways to Log Out of a Ubuntu Desktop Session
- Method 1: Log Out Using the UI
- Method 2: Log Out Using Keyboard Shortcut
- Method 3: Log Out Using the Application Launcher Search
- Method 4: Log Out Using the Terminal
- Search
- About This Site
- Latest Tutorials
- How can you log out via the terminal?
- 16 Answers 16
- 11.10 and above
- 11.04 and previous versions
- 11.10 and above
command to log the current user out of the system?
I often use reboot -n and shutdown -t now commands to restart and shutdown my system. Is there something similar to log out of the current user account? That is logout of my user session for the whole session. I’m using Ubuntu server with i3 so maybe I’m looking for an Ubuntu specific answer(?)
@jeffschaller :p maybe I should be, I don’t know much about zsh but I seem to see it mentioned in a lot of places 🙂
just (indirectly) pointing out that while bash is a common shell, it’s not your Everything — it has some built-in commands, but reboot and shutdown are not bash commands.
@JeffSchaller interesting I didn’t realize that. What exactly counts as standard bash is it the commands available on all posix systems?
2 Answers 2
logout is used by users to end their own session
Assuming you have default shellopts i.e ignoreeof is false. On a blank line Ctrl + d will exit you out of login shells and ssh sessions.
You must log in to answer this question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533
Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
4 Ways to Log Out of a Ubuntu Desktop Session
If you are using an Ubuntu system with multiple users and one of the other users asks you to use the system, you have two options for giving the system to him. One is to switch users, and the other is to log out of your user session for the other person. The difference between the two is that when you switch users, your current session continues to run in the background and you can restore your applications to the same state when you log back in. However, when you log off, your current session is terminated and all running applications are stopped. So when you log back in, you will have to reopen all the applications you need. You can choose between switching users and logging off, whichever suits you at the time.
In this article, we will describe four ways using which a user can log out of his/her Ubuntu session:
- Using the UI
- Using the Keyboard shortcut
- Through the application launcher search bar
- Through the Ubuntu command line, the Terminal
We have run the commands and procedures mentioned in this article on a Ubuntu 20.04 LTS system.
Method 1: Log Out Using the UI
One of the simple ways to log out of your Ubuntu session is to use the menu accessible through the downward arrow located at the top right corner of your Ubuntu screen. This is the menu you will see when you click this arrow:
Click your username and you will be able to see the following two main sub-menu items: Log Out and Account Settings. Click on the Log Out option in order to log out of your current Ubuntu session. The following dialog will display if you do so:
This dialog lets you log out right then by clicking the Log Out button. Otherwise, the system automatically ends your session after 60 seconds unless you press the Cancel button.
Method 2: Log Out Using Keyboard Shortcut
Ubuntu comes with a set of default keyboard shortcuts that allow you to perform commonly used Ubuntu operations with keyboard shortcuts. Logging out, a very common operation is also assigned such a keyboard shortcut. When you press the key combination Ctrl+Alt+Del, the same logout dialog we described above is displayed.
You can see all of these keyboard shortcuts and even create your own using the System Preferences utility. Open the Preferences utility directly from the Keyboard view by typing the word “keyboard shortcuts” into the search bar of your application launcher as follows:
Click on the Keyboard search result and you will be able to see the following view:
Method 3: Log Out Using the Application Launcher Search
Another quick method to log out of your session is to use the very useful application launcher search bar. This bar can be accessed by hitting the Super/Windows key on your keyboard.
Enter the keyword “logout” in this search bar and you will see the Log Out utility in the search result as follows:
Click on the Log Out search result and you will be presented with the same Log Out dialog that we described above.
Method 4: Log Out Using the Terminal
For a Terminal-savvy person, the Ubuntu command line also provides a way to log out of your Ubuntu user session.
Open the Ubuntu command line, the Terminal, either through the application launcher search or the Ctrl+Alt+T shortcut.
Then enter the following command in order to end the current user’s login session:
When you run this command, a dialog appears that lets you log out right then by clicking the Log Out button. Otherwise, the system automatically ends your session after 60 seconds unless you press the Cancel button on this dialog.
If you want to directly log out without having to see this dialog, you can make use of the following command:
$ gnome-session-quit --no-prompt
So, these were some ways you can use to safely log out of your Ubuntu user session so that another user can use the system after you.
Search
About This Site
Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.
Latest Tutorials
How can you log out via the terminal?
Is there a terminal command that will log you out of your current desktop session and take you back to the login screen?
16 Answers 16
11.10 and above
11.04 and previous versions
dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1
(via DoR, see his answer to «Reboot without sudoer privileges?» for more dbus goodness!)
or alternatively, you can use
gnome-session-save --force-logout
—force-logout in contrast to just —logout will not ask the user to deal with unsaved documents and so on.
is this the easiest way? no simple one line command like sudo logout?? I will never remember all that.
Yes, there is a command called logout, but it concerns the Terminal. gnome-session-save is the program that actually quits the gnome-session , which you can of course kill, but that wouldn’t qualify as logging out. 🙂
Notice as well that these commands don’t require you to be root.
You can always add an alias to your system if you want to have a shorter command.
Open ~/.bash_aliases with a text editor, or create it if it isn’t there, and add something like this to it:
alias logout-gnome="gnome-session-save --force-logout"
(.bashrc is a script that is run every time a new virtual terminal is started up, you should set up all your permanent aliases there, see also: How to create a permanent «alias»?)
Well, there’s always Ctrl-Alt-Backspace (if you enable it), but again that’s killing the session rather than logging out from it.
You might want to add DISPLAY=:0.0 or similar when trying to log out of a session from ssh or another terminal.
It seems to me that «—force-logout» doesn’t quite work, as it gives this error: WARNING **: Unable to start: Unknown option —force-logout. After digging around with man gnome-session-quit , I found that «—force» and «—logout» are actually meant to be different arguments. Therefore, «—force —logout» (two minus sings before «force» and «logout», with a space between) would be better as you won’t have errors. At least, that’s the case with Ubuntu 13.04 and Linux Mint 15. IDK about other/older versions of either distro.
aaronfranke@aaron-xub16desk$ dbus-send —session —type=method_call —print-reply —dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1 Error org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
I had installed mate desktop and none of the menus worked, even the f-keys didn’t work. I managed to get xterm through browsing with file manager.
The only thing that worked was :
I also did an alias out of it for me alias ulogout=»sudo pkill -KILL -u $1″ . Might come in handy for someone. Usage: ulogout user_name
Is there a reason you need the sudo ? Also, I think this is different than logging out, since it will kill all of your processes (for instance, if you have another remote session, it will also be killed). I’m also not sure that it will necessarily kill all of your processes (I can imagine it might kill itself first?) Do you know if that is possible?
11.10 and above
Here’s my personal solution!
alias log-out="gnome-session-quit"
to the file! Now you just have to run log-out!
Looks like gnome-session-save was renamed to gnome-session-quit for 11.10. Everything else in the main answer should still work with that single change.
For gnome sessions, gnome-session-quit works well. By default it asks for confirmation and then logs you out (i.e., the —logout argument is assumed unless overridden with —power-off explicitly). You can also tell the command to not prompt for confirmation on logout:
--no-prompt End the session without user interaction. This only works with --logout.
gnome-session-quit is still valid in 12.04.
Since the OP didn’t specify the window/desktop manager, and the gnome-session-quit might not work with all possibilities, here’s a generic X-windows way to return to the login screen or chooser which I’ve used several times over the last several releases:
From a terminal (invoked with, variously, ‘Alt-F2 + xterm, or Ctrl-T, or Crt-Alt-F1, or by right-clicking on the desktop in Nautilus and using the «open in terminal» shortcut, etc.) type
This is generally overkill for most situations. I tend to use it when I’ve got a hung process or when I’ve got to log out quickly. When I’ve done this, Ubuntu has politely returned me to the login screen by re-spawning X-windows.
I’ve not yet used the power-off feature of the gnome-session-quit , as I typically use shutdown -P now for that purpose.