Skip to content

Instantly share code, notes, and snippets.

@uPaymeiFixit
Last active February 24, 2025 12:59
Show Gist options
  • Save uPaymeiFixit/266493530e96270295a8b367424591d4 to your computer and use it in GitHub Desktop.
Save uPaymeiFixit/266493530e96270295a8b367424591d4 to your computer and use it in GitHub Desktop.
WSL2 Setup Guide (Squid, SSH, and Fish)
################################################
# Guide to configure WSL2 Squid, SSH, and Fish #
################################################
### Run all of this inside an Ubuntu WSL instance (must enable WSL2 and install Ubuntu WSL first)
# Allow us to start ssh and squid without a password
# echo "%sudo ALL=(ALL) NOPASSWD: /etc/init.d/ssh" | sudo tee -a /etc/sudoers.d/password-inits.conf
# echo "%sudo ALL=(ALL) NOPASSWD: /etc/init.d/squid" | sudo tee -a /etc/sudoers.d/password-inits.conf
echo "$(whoami) ALL = (ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/passwordless-sudo
# Install packages
sudo apt update
sudo apt install openssh-server net-tools squid npm
# Generate keys for sshd
sudo ssh-keygen -A
# Change default Squid configuration to allow local network access \
sed -i 's/^#http_access allow localnet$/http_access allow localnet/' /etc/squid/conf.d/debian.conf;
# Install node
install n and node 12.20.1
sudo npm i -g n
sudo n 12.20.1
n
# Enable Chrome Headless
export CHROME_BIN=/mnt/c/Program\ Files/Google/Chrome/Application/chrome.exe
# Install fish and themes
sudo apt-add-repository ppa:fish-shell/release-3
sudo apt update
sudo apt install fish
chsh -s $(which fish)
git clone https://github.com/uPaymeiFixit/dotfiles.git ~/git/uPaymeiFixit/dotfiles
ln -s ~/git/uPaymeiFixit/dotfiles/home/.vim ~/
ln -s ~/git/uPaymeiFixit/dotfiles/home/.gemrc ~/
ln -s ~/git/uPaymeiFixit/dotfiles/home/.editorconfig ~/
ln -s ~/git/uPaymeiFixit/dotfiles/home/.config/.prettierrc ~/.config/.prettierrc
ln -s ~/git/uPaymeiFixit/dotfiles/home/.config/tmux ~/.config/tmux
ln -s ~/git/uPaymeiFixit/dotfiles/home/.config/fish/fish_plugins ~/.config/fish/fish_plugins
ln -sf ~/git/uPaymeiFixit/dotfiles/home/.config/fish/config.fish ~/.config/fish/config.fish
curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher
fisher update
tide configure
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim +PluginInstall +qall
### Run all of this inside Admin Powershell
# Clone this guide
git clone https://gist.github.com/266493530e96270295a8b367424591d4.git ~/git/uPaymeiFixit/gists
# From an admin powershell, schedule this scirpt to run. For example
$trigger = New-JobTrigger -AtStartup -RandomDelay 00:00:15
Register-ScheduledJob -Trigger $trigger -FilePath C:\Users\Josh_G\git\uPaymeiFixit\gists\266493530e96270295a8b367424591d4\wsl2-start-services.ps1 -Name WSL2sshsquid
########################
# Starts Squid and SSH #
########################
# Get IP address of WSL instance
$wsl_ip = wsl.exe -d Ubuntu -e sh -c "ifconfig eth0 | grep 'inet '"
$found = $wsl_ip -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
$wsl_ip = $matches[0];
# NOTE for some reason using 0.0.0.0 doesn't work for me; I have to specify the actual address (10.0.1.8)
# Remove old forwarded ports to be replaced by new IP
iex "netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=22"
iex "netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=3128"
netsh interface portproxy show v4tov4
# NOTE for some reason using 0.0.0.0 doesn't work for me; I have to specify the actual address (10.0.1.8)
# Forward WSL ports to Windows to be used by outside world
iex "netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=22 connectaddress=$wsl_ip connectport=22"
iex "netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=3128 connectaddress=$wsl_ip connectport=3128"
netsh interface portproxy show v4tov4
# Allow ports through Firewall
iex "netsh advfirewall firewall add rule name='WSL2 SSH' dir=in action=allow protocol=TCP localport=22"
iex "netsh advfirewall firewall add rule name='WSL2 Squid' dir=in action=allow protocol=TCP localport=3128"
#Start SSH and Squid
wsl sudo service squid start
wsl sudo service ssh start
echo "###################################"
echo "# Don't forget to start your VPN! #"
echo "###################################"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment