Make Windows Green Again (Part 2)
Make Windows Green Again (Part 2)
All right, Linux is on your system, so let's get it working how you want it. This walkthrough covers using sudo and zypper to configure your setup.
Join the DZone community and get the full member experience.Join For Free
Learn how to migrate and modernize stateless applications and run them in a Kubernetes cluster.
In the first article of this series, I explained how to get openSUSE Leap 42.2 running within the Windows Subsystem for Linux (WSL) of Windows 10. Now, it is time to make it run properly because it’s not in a state I’d like to see it out there in the wild. In this article, I’d like to focus on correcting the user default login. I said that I would include graphical tools in my next blog, but that would make this blog much too long, so I will cover that topic in part three.
Please give me any feedback you have in the comments.
When we replaced the originally delivered Linux within WSL with openSUSE Leap 42.2, we had to set root as the default user – simply because the openSUSE Leap 42.2 archive we downloaded and unpacked didn’t know about our user. Running Linux with root as default user isn’t a good idea, so let’s change the default user back to <linux_user> – or the user name that you’ve chosen. But before doing so, we need to install a tool called “sudo”, which is not included in the openSUSE container that we extracted by default. For those not familiar with sudo, it’s a program that allows a user to temporarily gain root (aka Administrator) permissions to perform administrative tasks. For security reasons, it’s the default on Linux to use a regular user for daily tasks and only use root when tinkering with the system.
- Open the openSUSE bash (click the Windows button, type “bash” and then hit Enter), enter the following command:
Wait a little while until zypper has fetched all necessary repository information, and confirm the next question by pressing [y] to install sudo. Don’t close the openSUSE bash yet because there are still a couple of commands we have to execute.
$ zypper in sudo
- Now we have to create the regular Linux user within openSUSE bash. Before doing so, we need to understand that the user’s home directory is not stored in the rootfs folder, which we replaced. It’s a separate folder under %localappdata\lxss\home and is already available within openSUSE. While still in the openSUSE bash, you can navigate to the folder /home and check for yourself.
$ cd /home $ ls -la total 8 drwxr-xr-x 2 root root 0 Jan 1 1970 . drwxr-xr-x 2 root root 0 Jan 1 1970 .. drwxr-xr-x 2 1000 1000 0 Jan 20 08:52 <linux_user>
The folder is currently not owned by anyone known to the openSUSE system, which is indicated by the fact that there are only numbers set for user and group (highlighted in red) and not names. Let’s change that by adding the <linux_user> to openSUSE.
$ useradd <linux_user>
- Now, the former Linux and openSUSE Leap use a different default group ID for users. Where the former Linux is using ID=1000, openSUSE is using ID=100. Here’s an example how it looks on both systems:
# former Linux $ grep users /etc/group users:x:1000:
- Although having a proper user (owner) set for the home directory, the group is still off. With the “id” command you can check the user and the group settings for the user.
The group ID is different than the one that’s already set for the home directory
$ id <linux_user>
So let’s get this fixed with this command
# openSUSE Leap 42.2 $ grep users /etc/group Users:x:100
$ chgrp 100 /home/<linux_user> -R
- Before changing the default user back, we need to give root a password so that we can use it properly (more experienced Linux users might want to work with /etc/sudoers instead).
Enter a new password for the root and confirm by entering it again.
- All what is left is to tell WSL to use <linux_user> as default user. Close the openSUSE bash and execute the below command in a cmd window:
lxrun /setdefaultuser <linux_user>
- The output of that command should look quite similar to this one:
Found UNIX user: linux_user Default UNIX user set to: linux_user
And now we are done. Our user is properly set up, and when starting openSUSE bash, you aren’t root any longer, but <linux_user>. When installing software, you now need to put sudo in front of the regular zypper command, such as: “sudo zypper in <software>”. I believe we covered enough ground in this blog. Let look at installing (graphical) software in part three of this series.
Published at DZone with permission of Hannes Kuhnemund , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.