Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

After using "sudo -u bob" as "alice", how do I start a new logind session for bob?

  1. User

    After using "sudo -u bob" as "alice", how do I start a new logind session for bob?

  2. Assistant

    To start a new logind session for the user 'bob' after using "sudo -u bob" as user 'alice', you can use the 'loginctl' command. Here are the steps to follow:

    1. Assuming you are currently logged in as 'alice', open a new terminal window or tab.
    2. In the new terminal, use the following command to switch to 'bob':
      sudo -u bob bash
      
      This will open a new shell session as user 'bob'.
    3. In the new session, use the 'loginctl' command with the 'enable-linger' option to enable lingering for 'bob':
      loginctl enable-linger bob
      
      This ensures that 'bob' remains logged in even when there are no active sessions.
    4. Next, use the 'loginctl' command with the 'attach' option to start a new logind session for 'bob':
      loginctl attach 9999
      
      The '9999' here is an arbitrary session ID; you can choose any unused number.
    5. Finally, you can check the status of the new logind session for 'bob' using the 'loginctl show-session' command:
      loginctl show-session 9999
      
      Replace '9999' with the actual session ID you used.

    By following these steps, you can start a new logind session for 'bob' after using "sudo -u bob" as 'alice'.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.