1
0 Comments

I am having difficulty in setting a user password from Windows 10 using a script that contains the desired password. I have attempted to create a PowerShell .ps1 file with the command “wsl passwd” and “wsl testPassword” but this still prompts for the password. Additionally, I have tried using the pipe command twice with the passwd command, but it returned an error.

I am currently using Windows 10 Pro N 64-bit (desktop) version 1709, build 16299.192, with WSL Ubuntu 16.04.2 LTS installed.

I have also tried a method which includes the following steps:

  • Setting the default user to root using the command “lxrun /setdefaultuser root /y”
  • Creating a new user and setting it as the default user using the command “lxrun /setdefaultuser testuser /y”
  • Executing a command as the new user to initialize any necessary settings in WSL, for example “wsl echo “hello world””
  • Switching back to the root user using the command “lxrun /setdefaultuser root /y”
  • Setting the path to the passwd file, which can be found at /etc/passwd using the command “wsl set path /etc/passwd”
  • Changing the password for the non-root user using the command “wsl echo ‘testusername:newpasswd’ | chpasswd”

However, this resulted in an error message that ‘chpasswd’ is not recognized as an internal or external command, operable program or batch file.

Askify Moderator Edited question May 4, 2023