Posey's Tips & Tricks
Lessons Learned About Windows Subsystem for Linux Accounts, Part 2: Refresh
In my previous article, I explained that if you fail to provide a UNIX username and password when deploying the Windows Subsystem for Linux, the action will result in the creation of a Linux deployment that is missing a required default account. Since I have already shown you how to fix the problem by resetting the Linux environment, I wanted to revisit the topic and show you how you can manually create the missing account without having to reinstall Linux in the process. Later on, I will show you how to enable automatic logon for the account.
Creating the Missing Default Account
If your default account is missing, then you should currently be logged in as root. From the root prompt, create a user account by using the adduser command, followed by the username that you want to use. Keep in mind that Ubuntu requires usernames to be entered in lowercase. You can see what this looks like in Figure 1.
As you look at the figure, you can see that Ubuntu prompted me to enter and confirm a password to be used with the user account. Ubuntu also prompts you to enter some optional values such as full name, room number, and work phone. However, you can just press Enter as opposed to providing the requested data.
Although the technique shown above will indeed create the missing user account, the resulting account is treated as a standard account and lacks any administrative privileges. If you need for the account to receive administrative privileges, then you can grant those privileges by entering this command:
usermod -aG sudo <username>
You can see what this looks like in Figure 2.
Even though the commands listed above will indeed cause a user account to be created, that account is not used by default. If you want to log into the account, you can do so by using this command:
su - <username>
In Figure 3, you can see how I used this command to sign into the account that I created earlier.
Ignoring the Password
One thing that you might notice about the figure above is that when I logged into the account that I created, Ubuntu did not prompt me for a password. The reason for this is because Ubuntu won't prompt you for a password until you try to do something that requires administrative privileges (meaning that you use the sudo command).
It is possible to make a modification to the Linux environment that removes the need for entering a password. To get started, go back to the root environment by entering this command:
sudo -i
Now, enter this command:
visudo
This command causes Ubuntu to load the sudoers.tmp file into a text editor. Scroll to the bottom of the file and add this line of text, as shown in Figure 4:
<username> ALL=(ALL) NOPASSWD:ALL
When you finish, you can save your changes by pressing Ctrl+x, followed by Y and Enter.
Enabling Automatic Login
The last thing that I want to show you is how to make it so that your account is logged in automatically. To accomplish this, you will need to edit the .bashrc file. Enter the following command to load this file into the Nano editor:
nano /root/.bashrc
Now, add these three lines of text to the end of the file:
if [ "$USER" = "root" ]; then
su - <username>
fi
You can see what this looks like in Figure 5. Once again, you can save your changes by pressing Ctrl+x, followed by Y and Enter.
To test your configuration, just close and reopen the Windows Terminal. When you launch an Ubuntu session, you should be automatically logged into the account that you have specified.
About the Author
Brien Posey is a 22-time Microsoft MVP with decades of IT experience. As a freelance writer, Posey has written thousands of articles and contributed to several dozen books on a wide variety of IT topics. Prior to going freelance, Posey was a CIO for a national chain of hospitals and health care facilities. He has also served as a network administrator for some of the country's largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has spent the last several years actively training as a commercial scientist-astronaut candidate in preparation to fly on a mission to study polar mesospheric clouds from space. You can follow his spaceflight training on his Web site.