From b2172311ffce970b2fda9b36c1f5eef8fc12e11f Mon Sep 17 00:00:00 2001 From: xyb Date: Wed, 14 Jun 2023 07:55:41 -0700 Subject: [PATCH] Use 'useradd' instead of 'adduser' to create user account. 'adduser' is not a LSB defined command, some distros might not have it. (For example, adduser is removed from ubuntu base 23.04) --- DistroLauncher/DistributionInfo.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/DistroLauncher/DistributionInfo.cpp b/DistroLauncher/DistributionInfo.cpp index 4742f59f..4a838f6b 100644 --- a/DistroLauncher/DistributionInfo.cpp +++ b/DistroLauncher/DistributionInfo.cpp @@ -9,13 +9,22 @@ bool DistributionInfo::CreateUser(std::wstring_view userName) { // Create the user account. DWORD exitCode; - std::wstring commandLine = L"/usr/sbin/adduser --quiet --gecos '' "; + std::wstring commandLine = L"useradd -m -s $SHELL "; commandLine += userName; + commandLine = L"/bin/sh -c \"" + commandLine + L'"'; HRESULT hr = g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode); if ((FAILED(hr)) || (exitCode != 0)) { return false; } + // Input password. + commandLine = L"/usr/bin/passwd "; + commandLine += userName; + hr = g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode); + if ((FAILED(hr)) || (exitCode != 0)) { + return false; + } + // Add the user account to any relevant groups. commandLine = L"/usr/sbin/usermod -aG adm,cdrom,sudo,dip,plugdev "; commandLine += userName;