8

Hi I have 2 problems with my WSL2

first of all, it always runs as root

and the second problem that I have is that it runs without any password.

so here are my questions:

1- how to change my default User

2- how to make wsl2 ask for password on startup.

Pouya Samie
  • 183
  • 1
  • 1
  • 5

2 Answers2

8

To change the default user, please see this answer. The recommended way has already been covered in the comments.

As for trying to get WSL to ask for a password, I think you are trying to solve a problem that doesn't exist. Because the WSL instance runs under your Windows credentials, there's nothing that a potential attacker can do in WSL that they wouldn't already be able to do if they had access to your logged in Windows session. Even the Linux/WSL root cannot elevated privileges beyond that of the logged in Windows user.

The password will be requested when accessed remotely, however. For instance, if you have an SSL server running in the WSL instance, and you attempted to connect to that instance through ssh, a valid username and password (or associated private key) would be validated before granting access.

You mentioned trying to secure files against a domain admin who might access your account. Again, a domain admin could access your files in Windows. Even if you were running a Linux virtual machine with a "real" user that required a password, if someone access your Windows account, they could access the virtual disk for that VM.

The way to secure files inside the WSL instance is mostly the same way that you would protect files in a VM (or in Windows itself). Secure the files themselves with some level of encryption. Options include:

  • GPG
  • Create an encrypted container for the files, using something like LUKS. Note that I haven't tried this myself, but it does look like there's some additional effort required to enable this under WSL2.
NotTheDr01ds
  • 28,025
-2

Sorry for the necro, but for others wanting to do this -

I think you could set up a default user and in /etc/passwd set it's login shell to /usr/bin/login

I mean it still wouldn't be more secure than the windows box it sits on but if you really want to see the login prompt...