1

Using linux desktop systems (lightdm login manager, openbox, lxde or unity desktops), how can I enter and exit sessions (eg. log in from lightdm and log out from the desktop session) by command line, maybe even over SSH?

For example, I like to log out from an LXDE session and then log into an Unity session on a machine that does not have mouse nor keyboard attached by SSH.

1
  • You should clarify better what is your real case. How can you locally write something by command-line without an input device? If there is another input device, different from keyboard and mouse, you should say. For the second part/question - to graphical login/logout from a machine with keyboard and mouse on a machine that has not - the more appropriate way is a "remote desktop software" as per the answer below. You can also redirect for example the graph session via ssh with ssh -X, xhost +, then let start the session manager sudo service lightdm restart and operate from remote.
    – Hastur
    Sep 3, 2021 at 8:14

3 Answers 3

0

What you are searching for, it is a remote desktop software [rds].
On the machine without keyboard you will run the server, on the other the client.
There are many [1],[2] that can change in time. A good start can be the free version of nomachine [1]

To exit from a simple session instead, you have to find the relative command and invoke it even through an ssh connection, e.g. in gnome:

gnome-session-quit --logout --no-prompt

Remember that you can always make restart the login manager with commands like sudo service lightdm restart, or stop and after start, but this will close the whole lightdm and not only your current session.

Instead to run from remote a graphic application it is enough to connect with ssx -X to enable the X11 forwarding, or -Y, and run the command.

9
  • Ah, so to do a session logout, I have to use a dekstop-specific command? Is there any unspecific variant, like kill the window manager of the current X display :0 or something like that? And how to relogin again? I mentioned that lightdm will do auto login on boot up, but not if a session was closed of course, it presents the greeter then.
    – dronus
    May 4, 2016 at 12:17
  • Install nomachine (or another remote desktop software). That is what you really need. :-). It compresses the flux and allows to effectively use (remotely) that machine. The others are partial variants that will not fulfill your needs. You can always kill the windows manager, better with sudo service gdm restart that with pkill gdm or pkill -9 gdm... but it will remain the problem to do a new login. Again install nomachine (or another remote desktop software), it is what you are searching for.
    – Hastur
    May 4, 2016 at 12:35
  • But would a remote desktop software not be killed if I exit the current session? VNC and Teamviewer for example would exit.
    – dronus
    May 4, 2016 at 13:45
  • A remote desktop software is usually able to suspend your current session and to resume it even from a different location. It is something like if you log in that remote sessions that logs for you in the normal one... choose and try. :-)
    – Hastur
    May 5, 2016 at 11:30
  • The remote session will stay open if I log out of the graphical session, maybe even closing X? Teamviewer and VNC wouldn't do that. The remote deamon runs inside the current session and will exit if the session is closed of course.
    – dronus
    May 5, 2016 at 20:13
0

After days trying all solutions suggests, the only one that worked for me was:

killall Xorg

2
  • This would restart the login I guess, leaving you at the login screen, or going into the default session again, if autologin ist on. So you can't change the session by this alone.
    – dronus
    Sep 2, 2021 at 8:30
  • @Mentor Did you try something like sudo service lightdm stop changing lightdm and stop with your desktop manager and the admitted options (start stop restart...)? BTW it is better to exit before from the session (e.g. under kde you can exit with qdbus org.kde.ksmserver /KSMServer logout 0 0 0... note that changing the numbers you will have a shutdown or a reboot... see the man) .
    – Hastur
    Sep 6, 2021 at 9:22
0

If using systemd, you may use loginctl, the systemd login manager, to log out of any desktop session from the CLI over SSH.

In your example, use loginctl list-sessions to identify ID of the LXDE session, and then loginctl terminate-session ID.

But specifics to then start a Unity (or other) session over CLI SSH I imagine would depend on the desktop manager, e.g. lightdm (which might possibly autostart a greeter depending on the config). Someone else can answer that. Or you could possibly launch the session specific command with the right env vars, e.g. X=:0 openbox-session, but this may lack session management.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .