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.

Lakshya Raj
  • 165
  • 7

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
  • 498,455
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
  • 28,025