Doing this apparently[0] breaks using `wsl --manage <distro> --set-default-user` (in my test, wsl says it completed successfully, but actually doesn't do anything at all). Since we set the default UID in wsl-distribution.conf, the default default user will be UID 1000, which we expect to create anyway. While it's nice to support old versions of WSL, I think it's also reasonable to require users to update to ensure things work. For example, most things in Fedora expect cgroups v2, but WSL only removed cgroups v1 in 2.5. If users report an issue and note they're not using the latest WSL stable release I'm just going to tell them to reproduce it on the latest, and if they can't I'm not going to spend any time trying to make it work. [0] https://github.com/microsoft/WSL/pull/13094#issuecomment-2971990351 Signed-off-by: Jeremy Cline <jeremycline@linux.microsoft.com>
45 lines
1.4 KiB
Bash
45 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
# The Fedora WSL out of box experience script.
|
|
#
|
|
# This command runs the first time the user opens an interactive shell if
|
|
# `cloud-init` is not enabled.
|
|
#
|
|
# A non-zero exit code indicates to WSL that setup failed.
|
|
|
|
set -ueo pipefail
|
|
|
|
DEFAULT_USER_ID=1000
|
|
|
|
if systemctl is-enabled cloud-init.service > /dev/null ; then
|
|
echo 'cloud-init is enabled, skipping user account creation. Waiting for cloud-init to finish.'
|
|
cloud-init status --wait > /dev/null 2>&1
|
|
exit 0
|
|
fi
|
|
|
|
echo 'Please create a default user account. The username does not need to match your Windows username.'
|
|
echo 'For more information visit: https://aka.ms/wslusers'
|
|
|
|
if getent passwd $DEFAULT_USER_ID > /dev/null ; then
|
|
echo 'User account already exists, skipping creation'
|
|
exit 0
|
|
fi
|
|
|
|
# Prompt from the username
|
|
read -r -p 'Enter new UNIX username: ' username
|
|
|
|
# Create the user
|
|
/usr/sbin/useradd -m -G wheel --uid $DEFAULT_USER_ID "$username"
|
|
|
|
cat > /etc/sudoers.d/wsluser << EOF
|
|
# Ensure the WSL initial user can use sudo without a password.
|
|
#
|
|
# Since the user is in the wheel group, this file can be removed
|
|
# if you wish to require a password for sudo. Be sure to set a
|
|
# user password before doing so with 'sudo passwd $username'!
|
|
$username ALL=(ALL) NOPASSWD: ALL
|
|
EOF
|
|
|
|
echo 'Your user has been created, is included in the wheel group, and can use sudo without a password.'
|
|
echo "To set a password for your user, run 'sudo passwd $username'"
|