Skip to content

Instantly share code, notes, and snippets.

@shivapoudel
Last active March 14, 2026 18:13
Show Gist options
  • Select an option

  • Save shivapoudel/1de1a384116975a27d6dd5d29d612699 to your computer and use it in GitHub Desktop.

Select an option

Save shivapoudel/1de1a384116975a27d6dd5d29d612699 to your computer and use it in GitHub Desktop.
WSL setup for Ubuntu environment.

Installing Git on WSL

Git appears to come as standard as part of the WSL install. You can test this by running:

$ git --version

If for some reason Git is not installed then you can simply pull it down:

sudo apt-get update
sudo apt-get install git

Setup global configuration settings

git config --global user.name "Shiva Poudel"
git config --global user.email "3774827+shivapoudel@users.noreply.github.com"
git config --global core.autocrlf false

Additionally, follow this documentation to generate new SSH key and add it to your GitHub account.

Sharing an existing configuration and SSH key between Windows and WSL

If you have an configuration and SSH key already setup on Windows you could reuse it rather than creating a new one. (Note that PuTTY keys do not work here). To do this you can just copy the key from the Windows filesystem into the WSL's filesystem. Linux has some rules about how visible the key is. So you need to make sure the access levels are strict enough to meet these requirements:

Configuration settings

cd ~
cp /mnt/c/Users/shiva/.gitconfig .
cp /mnt/c/Users/shiva/.gitignore_global .

SSH Key and Known Host

cd ~
mkdir .ssh
cd .ssh
cp /mnt/c/Users/shiva/.ssh/id_ed25519* .
# Fix **WARNING: UNPROTECTED PRIVATE KEY FILE!**
chmod 600 * # Check the permission with `stat -c "%a %n" *`

Installing Python

Python is probably the easiest to install.

sudo apt install python3
sudo apt-get -y install python3 python3-dev python3-pip python3-venv libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev

Installing PHP

sudo apt-get install -y zip unzip rsync curl php php-cli php-curl php-dev php-mysql php-mbstring php-xmlrpc php-xdebug

Installing Composer

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Installing WP-CLI

curl -SO# https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

Setup Aliases

# Python
echo "alias python='python3'" >> ~/.bash_aliases
source ~/.bash_aliases

Aliasing python3 to python can be dicey if you install something that expects python to be Python 2.

# Make sure your Linux distribution is ready to go run an update and an upgrade:
sudo apt update
sudo apt -y upgrade
# Init .hushlogin
touch ~/.hushlogin
# Install python.
sudo apt-get -y install python3 python3-dev python3-pip python3-venv libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev
# Remove dir background in ls -color output.
dircolors -p | sed 's/;42/;01/' > ~/.dircolors
# Install git
sudo apt-get update
sudo apt-get install git
cd ~
cp /mnt/c/Users/shiva/.gitconfig .
cp /mnt/c/Users/shiva/.gitignore_global .
mkdir .ssh
cd .ssh
cp /mnt/c/Users/shiva/.ssh/id_ed25519* .
# Fix **WARNING: UNPROTECTED PRIVATE KEY FILE!**
chmod 600 * # Check the permission with `stat -c "%a %n" *`
# Install and setup zsh and Oh-My-Zsh
sudo apt update && sudo apt install zsh -y
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Install PHP.
sudo apt-get install -y zip unzip rsync curl php php-cli php-curl php-dev php-mysql php-mbstring php-xmlrpc php-xdebug
# Install Composer.
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
# Install WP-CLI.
curl -SO# https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
# Setup the aliases.
echo "alias python='python3'" >> ~/.bash_aliases
source ~/.bash_aliases
@shivapoudel
Copy link
Copy Markdown
Author

shivapoudel commented May 28, 2020

Turn on Windows Features:

dism.exe /online /enable-feature /FeatureName:Containers-DisposableClientVM /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

@shivapoudel
Copy link
Copy Markdown
Author

shivapoudel commented May 28, 2020

clip.exe < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

For copying ssh key in Github on WSL2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment