WSL setup

Setup WSL on Windows

Jacob Xie published on
3 min, 564 words

Categories: Doc

WSL and Ubuntu download

One line command: wsl --install.

For futher detailed info, visit the official documentation.

Install Windows Terminal

Please follow this step.

Move Ubuntu to another driver

This is an optional step, in case of C driver space insufficient (make sure you have already create directories as following):

wsl --export Ubuntu-20.04 d:\tmp\ubuntu.tar
wsl --unregister Ubuntu-20.04
wsl --import Ubuntu-20.04 d:\wsl\Ubuntu-20.04 d:\tmp\ubuntu.tar

Modify Windows settings.json

To modify Ubuntu's starting directory, we can open Windows terminal, and you'll see Open JSON file button, click it and add a new line called startingDirectory as below:

{
    "commandline": "wsl ~ -d Ubuntu",
    "hidden": false,
    "name": "Ubuntu",
    "source": "Windows.Terminal.Wsl",
    "startingDirectory": "~"
}

Setup wsl.conf

  1. Create a new file called wsl.conf:

    sudo vim /etc/wsl.conf
    
  2. Inside your file (please modify the username):

    # Set default user, otherwise sign as root
    [user]
    default=<username>
    
    # Let’s enable extra metadata options by default
    [automount]
    enabled = true
    root = /mnt/
    options = "metadata,umask=22,fmask=11"
    mountFsTab = false
    
    #Let’s enable DNS – even though these are turned on by default, we’ll specify here just to be explicit.
    [network]
    generateHosts = true
    generateResolvConf = true
    
    #All windows program shoulbe be normally run in wsl. great!
    [interop]
    enable = true
    appendWindowsPath = true
    
  3. Save your file and grant permission:

    sudo chmod -R 775 /etc/wsl.conf
    

New user

  1. Add user:

    sudo adduser jacob
    

    remove user:

    sudo deluser jacob
    
  2. Update sudoers

    add user to sudo group

    usermod -aG sudo jacob
    

Setup Git

git config --global user.name <Your name>

git config --global user.email <Your email>

If the following error occurred:

Warning: Permanently added 'github.com,XX.XXX.XXX.XXX' (RSA) to the list of known hosts.

Open the hosts file:

vim /etc/hosts

Add add the line:

XX.XXX.XXX.XXX  github.com

Generate SSH key and add to GitHub

Execute the following command:

ssh-keygen -t rsa

Copy the public key to your GitHub account:

cat ~/.ssh/id_rsa.pub

Copy SSH key and add to remote server

cat ~/.ssh/id_rsa.pub

Copy the public key to the remote server ~/.ssh/authorized_keys (create one, if doesn't exist). If authorized_keys needs to be create, make sure its permissions are correct:

chown -R $USER:$USER ~/.ssh

Issues may occur

Setup Github Cli (Debian/Ubuntu)

A shortcut:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
sudo apt-add-repository https://cli.github.com/packages
sudo apt update
sudo apt install gh

Then authentication (follow up the indication provided by gh):

gh auth login

Visit Github Token page and generate a new token. Copy this token to the terminal when ? Paste your authentication token: occurs.

Setup Github Cli (CentOS)

  1. Install DNF:

    sudo yum install epel-release
    sudo yum install dnf
    dnf --version
    
  2. Using DNF to install gh:

    sudo dnf install 'dnf-command(config-manager)'
    sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
    sudo dnf install gh
    
  3. Authentication:

    gh auth login