How to configure Fedora on wsl2


How to configure Fedora38 on wsl2

This is part 2


In my latest blog post we installed Fedora38 on Wsl2, you can click here to read it.However, there are a few additional steps we need to take:
  1. Install a few neccessary packages to get started
  2. Add a new user and set a password to change user
  3. Add rpmfusion repository and installing some basic packages
  4. Make the new user the default login.

Open powershell and type:

wsl -d <distro-name>

Currently, the prompt displays the user as "root." It is not advisable to use the system as the root user. Therefore, we need to create a new user and add the new user to the sudo group.
dnf update

dnf install sudo passwd nano util-linux git curl wget dnf-plugins-core dnf-utils ncurses rsync which

Installing these packages in root directory (system-wide), make them available for all users. But in genereal, you do not need to install all packages in root directory, because it does increases the attack surface on the root system.

Now, you can add a new user and set a password. By default, you will receive a warning if the password is shorter than 8 characters, but it will still work.

useradd -G wheel <username>
passwd <username>

After creating a new user and password, you can switch to new user by typing:
su - <username>

This will change to the new user's directory and you can proceed to add additional repositories like rpmfusion.

To add both free and nonfree repositories to fedora using dnf:

sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Now, the next step is to set the default user so that Fedora doesn’t boot up in the root directory again. The easier and the recommended way of setting default user is using “/etc/wsl.conf”. But if you followed my last post about installing Fedora manually, there should not be a “wsl.conf” file in your system. In that case, you can create and set the default user:

sudo nano /etc/wsl.conf

Edit/Create wsl.conf

type your password and then inside “wsl.conf” type these lines.

[user]
default=<username>

Edit/Create wsl.conf


And obviously change with your username. Then save it with “ctrl+o” then it prompts if you want to save it as “wsl.conf”, just press enter and then “ctrl+x” to exit.

Now you can exit Fedora by typing exit or “ctrl+d”. In wsl terminal type:

wsl --terminate <distribution name>

And start the fedora again by tyiping:

wsl -d <distribution name>

Now you are logged in as user and not root.


Tags: