close
close

Insights into the Windows Subsystem for Linux Accounts, Part 2: Updating – Redmondmag.com

Insights into the Windows Subsystem for Linux Accounts, Part 2: Updating – Redmondmag.com

Posey’s Tips and Tricks

Insights into the Windows Subsystem for Linux Accounts, Part 2: Updating

In my previous article, I explained that if you don’t specify 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 already showed you how to fix the problem by resetting the Linux environment, I wanted to revisit the topic and show you how to manually create the missing account without having to reinstall Linux in the process. Later, I’ll show you how to enable automatic login for the account.

Creating the missing default account
If your default account is missing, you should currently be logged in as root. At the root prompt, create a user account using the adduser command followed by the desired username. Note that Ubuntu requires usernames to be entered in lowercase. You can see what this looks like in Figure 1.

(Click on the image to enlarge it.) Figure 1. I created a user account with the name “Brien”.

If you look at the screenshot, you can see that Ubuntu asked me to enter and confirm a password to use with the user account. Ubuntu also asks you to enter some optional values ​​such as full name, room number, and work phone number. However, you can also just press Enter instead of entering the requested data.

Although the technique shown above actually creates the missing user account, the resulting account is treated as a standard account and does not have administrative privileges. If you need administrative privileges for the account, you can grant those privileges by entering this command:

usermod -aG sudo 

You can see what this looks like in Figure 2.

(Click on the image to enlarge it.) Figure 2. I granted administrator rights to the newly created account.

Although the commands listed above will actually create a user account, by default that account is not used. If you want to log in to the account, you can do so using this command:

su - 

In Figure 3you can see how I used this command to log into the account I created earlier.

(Click on the image to enlarge it.) Figure 3. You can use the “su” command to log in to the account you created.

Ignoring the password
You might notice in the image above that Ubuntu didn’t ask me for a password when I logged into the account I created. The reason for this is that Ubuntu doesn’t ask you for a password until you try to do something that requires administrative privileges (which means using the sudo command).

It is possible to make a change to the Linux environment that eliminates the need to enter a password. To start, go back to the root environment by entering this command:

sudo -i

Now enter this command:

visudo

This command will cause 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:

 ALL=(ALL) NOPASSWD:ALL

When you’re done, you can save your changes by pressing Ctrl+x, then Y and Enter.

(Click on the image to enlarge it.) Figure 4. You can modify the sudoers.tmp file.

Enable automatic login
Lastly, I want to show you how to make your account log in automatically. To do this, you need to edit the .bashrc file. To load this file into the Nano editor, enter the following command:

nano /root/.bashrc

Now add these three lines of text to the end of the file:

if ( "$USER" = "root" ); then
su -
fi

You can see what this looks like in Figure 5. You can save your changes again by pressing Ctrl+x, then Y and Enter.

(Click on the image to enlarge it.) Figure 5. I enabled automatic login by editing the .bashrc file.

To test your configuration, simply close the Windows Terminal and reopen it. When you start an Ubuntu session, you should be automatically logged in to the account you 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 freelancing, Posey was CIO of a nationwide chain of hospitals and healthcare facilities. He has also served as a network administrator for some of the nation’s largest insurance companies and for the Department of Defense at Fort Knox. In addition to his continued work in IT, Posey has been actively participating in Commercial Scientist-Astronaut Candidate training for the past few years in preparation for a mission to explore polar mesospheric clouds from space. You can follow his spaceflight training on his website.



Leave a Reply

Your email address will not be published. Required fields are marked *