User Creation and Set as Default in WSL

Aditya ThoratAditya Thorat
3 min read

Table of contents

Introduction: In Ubuntu, creating and managing users is important for controlling access to the system. This guide will show you how to add a new user, give them admin privileges, and set them as the default user when you log in. We will explain two ways to create a user and how to make changes to set them up as your main account. This helps you manage who can use the system and what they can do.

Step 1: Create user in ubuntu

There are two steps to add a user in Ubuntu:

  1. adduser command

  2. useradd command

    1. adduser command

To create the user, we use the adduser command

     sudo adduser username

Using adduser command you will add user with all details.

For example:

     root@LAPTOP-U5U0ADKN:~# sudo adduser adityathorat
    info: Adding user `adityathorat' ...
    info: Selecting UID/GID from range 1000 to 59999 ...
    info: Adding new group `adityathorat' (1000) ...
    info: Adding new user `adityathorat' (1000) with group `adityathorat (1000)' ...
    info: Creating home directory `/home/adityathorat' ...
    info: Copying files from `/etc/skel' ...
    New password:
    Retype new password:
    passwd: password updated successfully
    Changing the user information for adityathorat
    Enter the new value, or press ENTER for the default
            Full Name []: Aditya Thorat
            Room Number []: 01
            Work Phone []: 9797979797
            Home Phone []: 9111111111
            Other []: 0
    Is the information correct? [Y/n] y
    info: Adding new user `adityathorat' to supplemental / extra groups `users' ...
    info: Adding user `adityathorat' to group `users' ...
  1. useradd command

To create a user, we use the useradd command.

    sudo useradd username

Using this command, you only add the user. To set a password and add more details for a user, there are additional commands.

For example:

    root@LAPTOP-U5U0ADKN:~# sudo useradd adi

Step 2: Add the user in group

To add the user in any group we use usermod command

sudo usermod -aG sudo username
  • -aG: This option appends the user to the group(s) specified without removing them from other groups.

  • sudo: This is the group that grants administrative privileges.

For example:

root@LAPTOP-U5U0ADKN:~# sudo usermod -aG sudo adityathorat

Step 3: Set new user as a default

To set new user as a default, we follow following steps.

Step 1: Open the ubuntu terminal.

Step 2: Change the directory to etc and Open the file wsl.conf

nano /etc/wsl.conf

Step 3: Add or Modify the User Section: If the file already exists, you may just want to add or modify the user section. If it doesn't exist, you can create it. Add the following lines:

[user]
default = your_username

Replace your username with the actual username you want to set as the default

For example:

[user]
default = adityathorat

Step 4: Restart WSL: After editing the file, you need to restart WSL for the changes to take effect. Run the following command in Command Prompt or PowerShell:

wsl --shutdown

After doing those steps your default user get set

For example:

adityathorat@LAPTOP-U5U0ADKN:~$

Git-Hub Repository

https://github.com/AdityaThorat679/User-Creation-and-Set-as-Default-in-WSL.git

0
Subscribe to my newsletter

Read articles from Aditya Thorat directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aditya Thorat
Aditya Thorat