Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Use 'useradd' instead of 'adduser' to create user account. #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion DistroLauncher/DistributionInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down