Login logout in linux

How to Log Out from Ubuntu Session [Beginner’s Tip]

The answer depends on whether you are using Ubuntu server or desktop. I’ll show you steps for both.

Logout Ubuntu from terminal (for server)

If you are using Ubuntu server and you are confined to the terminal screen, you can use the exit command:

Yes. That’s the way to logout from terminal because there is no logout command in Ubuntu or any Linux distribution. You have commands for shutdown Ubuntu but there is no separate log out command.

You may wonder if there is command for shutdown, command for restart then why there is no Linux command for logout?

The answer lies in the way Linux works. You probably know that Linux is only kernel and you need a shell to interact with the kernel. When you use a terminal or if you log in to an Ubuntu system via SSH, you open a shell session.

If you want to logout from your session, you simply exit the shell. This is why the exit command is equivalent to log out command in Linux.

Log out from Ubuntu desktop (GUI method)

If you are using Ubuntu desktop, you have a graphical interface (called desktop environment). You can use your mouse here.

I am showing the screenshot for the default GNOME desktop but if you are using some other Ubuntu desktop variants like Kubuntu, Lubuntu etc, there should also be a logout button or logout option in the power menu.

To log out from Ubuntu desktop session, go to the top right corner and click to bring the system tray. You should see Power Off / Log Out option. Click on it and it will show the Log Out option.

Log Out Ubuntu

When you click on the Log Out button, it will open a dialogue box and ask for your conformation. If it receives no input from you, you’ll be logged out in 60 seconds.

Читайте также:  Linux froze what to do

Log Out Confirmation Ubuntu

That’s it. Now that you know how to log off from Ubuntu session let me tell you a secret tip.

You can use Ctrl+Alt+Del keyboard shortcut in Ubuntu to bring the logout menu. Cool, isn’t it?

Источник

What happens first when you login or logout from the system in Linux

Being a noob in Linux and not into real system admin kind of job, so it was difficult for me to answer. Is there any particular tutorial on such concepts or can somebody explain what exactly happens while logging in or logging out from the Linux System? Assume it is console terminal not GUI.

1 Answer 1

In Linux, the flow of control during a boot is from BIOS, to boot loader, to kernel. The kernel then starts the scheduler (to allow multi-tasking) and runs the first userland (i.e. outside kernel space) program Init (which is mostly responsible to run startup scripts for each runlevel), at which point the kernel goes idle unless called externally.

init (short for initialization) is a program for Unix-based computer operating systems that spawns all other processes. It runs as a daemon and typically has PID 1. The boot loader starts the kernel and the kernel starts init. If one were to delete init without a replacement, the system would encounter a kernel panic on the next reboot.

When init starts, it reads a file called inittab, usually located in /etc. This file tells init which programs should be run under which conditions. Not only does init run the startup scripts that bring the rest of the system up, but init also takes care of shutting the system down. Commonly, init will start a program called «getty» to spawn a new terminal (or tty), and «login» for login prompt. This configuration is set inside inittab. In recent version of linux, inittab is replaced with /etc/init/*.conf and scripts inside /etc/init.d/

On shutdown, Init is called to close down all user space functionality in a controlled manner, again via scripted directions, following which Init terminates and the Kernel executes its own shutdown.

Login: Getty is the process which will take care of complete login process.

  1. Init creates the getty process
  2. getty process initiates login command
  3. login command try to check user credentials
  4. getty creates user shell process
  5. getty read shell property files
  6. getty provides you with PS1 prompt
Читайте также:  Линукс смена прав доступа

On logout, the shell program exits and we return to step 1.

Источник

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 

alt text

(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.

Читайте также:  Linux libc dev ubuntu

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.

Источник

Оцените статью
Adblock
detector