Results 1 to 7 of 7

Thread: Switch user from command line

  1. #1
    Join Date
    Jun 2014
    Location
    Moscow, Russia
    Posts
    15

    Default Switch user from command line

    I use LXDE. What I'm trying to achieve is locking a session, but not by means of xscreensaver.
    I can send a dbus message
    Code:
    dbus-send --print-reply --system --dest=org.freedesktop.login1 \
    /org/freedesktop/login1 org.freedesktop.login1.Manager.Suspend \
    boolean:true
    to achieve same effect as when I press "Sleep".
    How do I achieve "Switch user" effect? lxlock is not what I want, it calls xscreensaver and makes it ask for a password, instead of just activating it

  2. #2
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    12,019
    Blog Entries
    2

    Default Re: Switch user from command line

    Not sure what you're describing regarding the screensaver,
    But answering your subject line, the following will switch to another User account at the command line (That command option is a hyphen, letter L for "login" in lower case)
    Code:
    su -l new_user_account
    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  3. #3
    Join Date
    Jun 2014
    Location
    Moscow, Russia
    Posts
    15

    Default Re: Switch user from command line

    Quote Originally Posted by tsu2 View Post
    Code:
    su -l new_user_account
    Hello. Unfortunately, I didn't mean switch the user in command line, but rather from command line.
    Attaching a screenshot of button I want to "press" from command line

  4. #4
    Join Date
    Jun 2008
    Location
    San Diego, Ca, USA
    Posts
    12,019
    Blog Entries
    2

    Default Re: Switch user from command line

    Not sure what you are asking for...

    What I provided enables you to "press that button" from within a running terminal.
    Actually, avoiding the complications from actually running through the GUI code, the command I provided accesses the equivalent functionality behind the GUI.

    TSU
    Beginner Wiki Quickstart - https://en.opensuse.org/User:Tsu2/Quickstart_Wiki
    Solved a problem recently? Create a wiki page for future personal reference!
    Learn something new?
    Attended a computing event?
    Post and Share!

  5. #5
    Join Date
    Sep 2012
    Posts
    5,364

    Default Re: Switch user from command line

    Quote Originally Posted by mekkanizer View Post
    How do I achieve "Switch user" effect?
    User switching is performed by display manager, so you need to know what DM you are using. Here is what happens when you press Switch user button:
    Code:
        if (handler_context->switch_user_GDM)
            g_spawn_command_line_sync("gdmflexiserver --startnew", NULL, NULL, NULL, NULL);
        else if (handler_context->switch_user_KDM)
            g_spawn_command_line_sync("kdmctl reserve", NULL, NULL, NULL, NULL);
        else if (handler_context->switch_user_LIGHTDM)
            dbus_Lightdm_SwitchToGreeter(&err);
        else if(handler_context->switch_user_LXDM)
            g_spawn_command_line_sync("lxdm-binary -c USER_SWITCH", NULL, NULL, NULL, NULL);

  6. #6
    Join Date
    Jun 2014
    Location
    Moscow, Russia
    Posts
    15

    Default Re: Switch user from command line

    @arvidjaar thank you for input, but I don't know where to execute the code you provided, please hint (in bash it produces errors).
    Also, I think I've found a working solution (for LXDE)
    Code:
    dm-tool switch-to-greeter
    @tsu2 It's my bad that I've worded it this way, I meant achieving exactly (and no more) than the "switch user" button does, and that is locks your session without enabling any lock mechanisms in screensavers, which in comparison lxlock does (I don't want to get stuck with other keyboard layout being active, considering xscreensaver freezes for seconds after you type a wrong password).

  7. #7
    Join Date
    Sep 2012
    Posts
    5,364

    Default Re: Switch user from command line

    Quote Originally Posted by mekkanizer View Post
    Also, I think I've found a working solution (for LXDE)
    Code:
    dm-tool switch-to-greeter
    It has nothing to do with LXDE. dm-tool is LightDM utility. You really need to learn difference between display manager and desktop environment.

    If you said from the very beginning you were using LightDM, you may have got answer more soon.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •