3

I have an Ubuntu distribution running on WSL. Every load, it opens my user lraj22 by default. Using an /etc/wsl.conf file, I set

[user]
default=

It still opens up my user profile. If I set it to root, it opens the root profile, and if I set it to some non-existent user notarealuser, it errors and goes back to mine.

If it's possible, how do I disable the auto-login feature on WSL distributions (specifically Ubuntu)?

Note: For reference, the question How to set default user for manually installed WSL distro? shows how to set the default user. I'm trying to unset the default user, so that it asks for a username/password in order to access the system.

  • There may be workarounds, but can you help me understand why you want to do this? If you are thinking that it's a security issue, then see this question for my explanation of why I don't believe it is (even in root form). While I can probably give you a way to force a login, it wouldn't change the security aspects. But if you have a different reason for wanting to change it, maybe there's a workaround. Thanks! – NotTheDr01ds Dec 11 '22 at 00:51
  • @NotTheDr01ds I was testing out WSL/Ubuntu (pretty new to those topics), and I noticed that one difference between an Ubuntu VM and WSL Ubuntu is that WSL Ubuntu auto-logged in to my user. The /etc/gdm/custom.conf file from Google searches didn't apply to WSL. When I finally found out about wsl.conf, it didn't work either, so I asked here on SU. I didn't expect this to increase security, but rather free me from constant user switching (apparently su isn't the equivalent to sign out & sign in on Windows... you can exit to go back, and commands are logged as the invoking user). – Lakshya Raj Dec 11 '22 at 01:48

2 Answers2

1

I don't know of such a method - it doesn't seem to exist. You may use the Feedback Hub to signal the problem to Microsoft.

As a very weak workaround, you could set the default user to be an extremely limited guest user account. This will force to do the real login using the command su - username, which will require a password.

harrymc
  • 480,290
  • I had a similar idea with the limited guest user, but that won't be too helpful in my specific use case. Thanks for clarifying, though! – Lakshya Raj Dec 10 '22 at 21:02
1

There's always going to be one "default" user for a WSL distribution. This is because WSL distributions are "containers". A container doesn't have the concept of a "login", but rather is "entered" from the parent namespace. Docker works the same way.

There are several possible workarounds. From your comments, your issues with the current situation are:

... constant user switching
... su isn't the equivalent to sign out & sign in on Windows...
... [with su], you can exit to go back, and commands are logged as the invoking user

With that in mind, you can:

  • Specify the username on the wsl commandline

    Launch WSL with:

    wsl ~ -u <username>
    

    This will enter the WSL distribution as another user. You can even have multiple terminals open at the same time with different users.

    This is similar to the way the docker exec --user <username> form would work (see this answer).

    After exiting the shell that was started this way, you'll actually exit the distribution itself (rather than being returned to a parent user).

  • Not Recommended: Use the login command directly when starting WSL

    wsl -u root -e login
    

    Advantage: Runs all normal login activities, such as /etc/profile.d and PAM modules.

    Disadvantage: Because a login goes through PAM, the environment variables that WSL itself sets are not available. This includes:

    • The PATH that WSL provides with the Windows path appended. So when running through login, you won't have access to code, powershell.exe, and other Windows commands without specifying their full path.

    • DISPLAY for running GUI applications in WSLg.

    • WSL_xxx variables

    • WT_ information from Windows Terminal

    • And more.

    As a result, some WSL functionality will be degraded.

NotTheDr01ds
  • 21,923