Closed kousu closed 3 years ago
Ah, I read the docs: there's
wsl -u root
which partially helps. If, say, you generalized --root
to --user
which worked so that, given --user someone
, DistroLauncher runs useradd -m someone
instead of using adduser
then it won't prompt, and I can later use wsl -u root passwd someone
to set the password, or echo 'someone:pass' | wsl -u root chpasswd
to set it noninteractively.
..and now I just noticed ubuntu1804 config --default-user username
. Which pretty much covers everything I want.
DistroLauncher could make this smoother maybe with more obvious flags, but this works fine:
<distro>.exe install --root
wsl -u root -d <distro> useradd -m "$username"
wsl -u root -d <distro> sh -c "echo "${username}:${password}" | chpasswd"
wsl -u root -d <distro> chsh -s /bin/bash "$username"
wsl -u root -d <distro> usermod -aG adm,cdrom,sudo,dip,plugdev "$username"
<distro>.exe config --default-user "$username"
Or, this is even better:
Given that you've grabbted the .appx link for a distro:
$distro = "ubuntu1804"
$distro_link = "https://aka.ms/wsl-ubuntu-1804"
$username = "ubuntu"
$password = "ubuntu"
Invoke-WebRequest -Uri $distro_link -OutFile ~/${distro}.appx -UseBasicParsing
Add-AppxPackage -Path ~/${distro}.appx
& $distro install --root
& $distro run useradd -m "$username"
& $distro run sh -c "echo "${username}:${password}" | chpasswd"
& $distro run chsh -s /bin/bash "$username"
& $distro run usermod -aG adm,cdrom,sudo,dip,plugdev "$username"
& $distro config --default-user "$username"
I want to be able to do an unattended install as if from the Microsoft Store. There is
install --root
, which you document prominently:and this is what is used by
https://github.com/microsoft/windows-dev-box-setup-scripts/blob/a0d80679847fc668bdc1706ae29b45da7a65772b/scripts/WSL.ps1#L10
but that team knows they should be installing with a regular user, but declined to explain fully how to actually to implement https://github.com/microsoft/windows-dev-box-setup-scripts/blob/d488050/README.md#how-to-run-the-scripts
From https://github.com/microsoft/WSL/issues/3369 I learned that I make an almost fully-automatic user account by:
But this is really fragile:
I wish this section of code was just slightly different:
https://github.com/microsoft/WSL-DistroLauncher/blob/2ed9a9335fc89a688a5150c95eff4fbdbc830f25/DistroLauncher/DistroLauncher.cpp#L39-L53
or maybe this one:
https://github.com/microsoft/WSL-DistroLauncher/blob/2ed9a9335fc89a688a5150c95eff4fbdbc830f25/DistroLauncher/DistributionInfo.cpp#L12-L14
Could there be a
--unattended
or--default-user
flag that does a clean unattended install? Or, awsl set-user
that would let me change the default user after initially installing with root?