Ubuntu

How to log out from Ubuntu terminal

If you have a multi-user Ubuntu system, and some other users ask to use it then you have two options for granting him access to the system: The first option is to switch users, and in the second option, you can log out of your user session, thinking about which option will be best for you to avail? Let me explain the differences in functionality between these two options. If you go for the first option of switching users, your current session continues to operate in the system background, and when you log back in, you can restore the programs to their previous state. However, if you select the second option of logging out from the user session, your current session will end with all running applications. As a result, you have to re-open all of your applications once again when you log back in.

Selection between logging off and switching users option depends upon your requirements. But if you want to hand over the control of your Ubuntu system to another user, log out of the current session and permit another user to log in. Logging out disallows the other users to access your system without verifying their credentials. Another security aspect that the log-out option covers is that it protects the access of current users and forbids the authorized actions on the current login session. It also ensures that after the login session, the user’s access and credentials are safe.

In Ubuntu, you can log out from your current session using Ubuntu User Interface (UI), the Application’s search bar, and a Keyboard shortcut. Using the Ubuntu terminal to log out of your system is another straightforward method. This post will demonstrate how to log out from the Ubuntu terminal. So let’s start!

How to log out from Ubuntu terminal

To follow the procedure of logging out using the terminal, firstly, open up your Ubuntu terminal by pressing “CTRL+ALT+T”.You can utilize the “gnome-session-quit” command for terminating your current GNOME session. Here is the syntax of the “gnome-session-quit” command:

$ gnome-session-quit [Options]

The “gnome-session-quit” command provides support to the following option:

  • –logout: This option is used to confirm the log-out by displaying a prompt. That’s how things work by default in the “gnome-session-quit” command.
  • –power-off: This option is used to prompt the user for verifying system reboot.
  • –reboot: This option requests the current user to confirm the system reboot through a prompt.
  • –force: This option is utilized to ignore any inhibitors.
  • –no-prompt: If you add the “–no-prompt” option in the “gnome-session-quit” command, the current session will end without any user interaction.

In our case, we only have to log out from the current session. From your current session, you will be logged out by executing below-given command in the terminal:

$ gnome-session-quit

As we have not added any options in the “gnome-session-quit”, this command will display a prompt before log out. Log out from the system while prompting the user is the default behavior of this command:

Here, confirm the log out by clicking the “Log Out” button; otherwise, you will be logged out from your system automatically in 60 seconds:

To log out from your Ubuntu current session, without any user interaction, write out the below-given command in your terminal:

$ gnome-session-quit --no-prompt

After execution, you will be redirected to the following window:

Select the one you want to switch from the available list of system users and then enter the password. You are all ready to use your system!

Conclusion

To allow any other user to use your Ubuntu system, either you can switch users or log out from the current session. The process of logging out of your system maintains every security related to the current user’s access. In Ubuntu, you can log out from your current session using Ubuntu UI, Keyboard Shortcut, Application’s search bar, and terminal. This article showed you how to log out from the Ubuntu terminal using the “gnome-session-quit” command.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.