Skip to content

arm-moodys/wsl_tricks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

WSL Tricks

Dev Setup Environment

Table of Contents

Required Steps

  1. wsl --update

  2. wsl --install -d Ubuntu-24.04

  3. Create initial user.

  4. Setup your init.sh (One Command Setup) script.

  5. Clone this repo to your home directory.

  6. sudo su -

  7. Move the cloned repo under /opt/

  8. Copy the /opt/dev_env_setup/wsl_u24.04/wsl.conf file under /etc/

  9. (Optional): Copy the required certificates to the WSL intance:

    1. Copy the required certs from Windows to the WSL instance:

      cp /mnt/c/cert_for_wsl/* /usr/local/share/ca-certificates/ ; chmod 644 /usr/local/share/ca-certificates/* ; ll /usr/local/share/ca-certificates/
    2. Update and Upgrade:

      apt update ; apt upgrade
    3. Refresh all the certs:

      update-ca-certificates --fresh
  10. Now run the setup script:

1. Login again and udpate the dns server names:

 ```bash
bash /opt/dev_env_setup/wsl_u24.04/01_run_as_root.sh SKIP_ROOT_PASS ; unlink /etc/resolv.conf ; echo -e "nameserver 1.1.1.1\nnameserver 1.0.0.1" > /etc/resolv.conf
  1. Exit and shutdown the WSL instance:

    wsl --shutdown
  2. Wait 10 seconds.

  3. Now you can start using your fully setup WSL instance.

Using Company Certificates When Working on a Corporate Network

When using WSL (or any VM that is provisioned by the user and not the company) on a corporate machine/network we usually need to import the company's certificates on the WSL instance, this is because companies usually implement SSL MITM to monitor all traffic to prevent get malware into the company's network.

  1. On the WSL machine, clone this repo under /opt/
  2. On the Windows machine:
    1. Create a folder directly under the c drive using powershell:

      New-Item -ItemType "directory" -Path "c:\cert_for_wsl"
    2. Copy the company certificates to c:\cert_for_wsl

Importing Company Certificates (Ubuntu)

Important

The steps below are provided so the user know what's the process to do so but this should be part of the automation setup process.

  1. On the Ubuntu WSL instance
    1. Log in as root.

    2. Update certs:

      sudo update-ca-trust
    3. Copy the required certs from Windows to the WSL instance:

      cp /mnt/c/cert_for_wsl/* /usr/local/share/ca-certificates/ ; chmod 644 /usr/local/share/ca-certificates/*
    4. Refresh all the certs:

      sudo update-ca-certificates --fresh

Importing Company Certificates (RHEL)

Important

The steps below are provided so the user know what's the process to do so but this should be part of the automation setup process.

  1. On the RHEL WSL instance:
    1. Log in as root.

    2. Update certs:

      update-ca-trust
    3. Copy the required certs from Windows to the WSL instance:

      cp /mnt/c/cert_for_wsl/* /etc/pki/ca-trust/source/anchors/ ; chmod 644 /etc/pki/ca-trust/source/anchors/*
    4. Refresh all the certs:

      update-ca-trust extract`

General Tips

  • Completely Uninstall Docker from Ubuntu:

    dpkg -l | grep -i docker ;  sudo apt-get purge -y docker-engine docker docker.io docker-ce docker-ce-cli ; sudo apt-get autoremove -y --purge docker-engine docker docker.io docker-ce ; sudo rm -rf /var/lib/docker /etc/docker ; sudo rm /etc/apparmor.d/docker ; sudo groupdel docker ; sudo rm -rf /var/run/docker.sock
  • Load scripts from /etc/profile.d/ by Adding the following to the ~/.bashrc of the 1st created user:

    Note: This is not needed as automation takes for this but leaving here just in case

    if [ -d /etc/profile.d ]; then
    for i in /etc/profile.d/*.sh; do
        if [ -r $i ]; then
        . $i
        fi
    done
    unset i
    fi

WSL - Use Corporate Certificates (RHEL)

  1. Go to Manage User Certificates
  2. Trusted Root Certification Authorities
  3. Certificates
  4. Open the root CA certificate you are interested in
  5. Details
  6. Copy To File
  7. Next
  8. Select "Base64 encoded X.509"
  9. Important: Save the certs using the .crt extension to a share location
  10. Go to the RHEL machine
  11. sudo update-ca-trust
  12. sudo cp <path_to_crt_file>/* /etc/pki/ca-trust/source/anchors/
  13. update-ca-trust extract
  14. Now let's verify we can reach https websites curl https:///example.com

WSL - Use Corporate Certificates (Ubuntu)

  1. Go to Manage User Certificates
  2. Trusted Root Certification Authorities
  3. Certificates
  4. Open the root CA certificate you are interested in
  5. Details
  6. Copy To File
  7. Next
  8. Select "Base64 encoded X.509"
  9. Important: save the certs using the .crt extension to a share location
  10. Go to the Ubuntu machine
  11. sudo update-ca-trust
  12. sudo cp <path_to_crt_file>/* /usr/local/share/ca-certificates/
  13. sudo update-ca-certificates --fresh
  14. Now let's verify we can reach https websites curl https:///example.com

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published