microsoft / windows-dev-box-setup-scripts

Scripts to simplify setting up a Windows developer box
MIT License
1.5k stars 367 forks source link

Deploy WSL with a regular user #90

Open kousu opened 3 years ago

kousu commented 3 years ago

It would be nice if, instead of

https://github.com/microsoft/windows-dev-box-setup-scripts/blob/d488050/README.md#how-to-run-the-scripts

If you are using WSL there's a followup step we recommend after running the setup script. When the script finishes you will only have a root user with a blank password. You should manually create a non-root user via $ sudo adduser [USERNAME] sudo with a non-blank password. Use this user going forward. For more info on WSL please refer to the documentation.

there was a way to auto-install with a regular user. I've opened an issue about this 'upstream': https://github.com/microsoft/WSL-DistroLauncher/issues/90, but there's a workaround that maybe you could apply temporarily: https://github.com/microsoft/WSL/issues/3369#issuecomment-403481209:

$username = "ubuntu"
$password = "ubuntu"

ubuntu1804 install --root

wsl -u root useradd -m "$username"
wsl -u root sh -c "echo "${username}:${password}`n" | chpasswd" # wrapped in sh -c to get the pipe to work
wsl -u root  chsh -s /bin/bash "$username"
wsl -u root usermod -aG adm,cdrom,sudo,dip,plugdev "$username"

$uid = (wsl -u root id -u $username)

$distro = (Get-ItemProperty -Path Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss -Name DefaultDistribution).DefaultDistribution
$cur_id = (Get-ItemProperty -Path Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss\$distro -Name DefaultUid).DefaultUid
Set-ItemProperty -Path Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Lxss\$distro -Name DefaultUid -Value $uid

With this, you can just say

If you are using WSL take note that the login is "ubuntu:ubuntu".