CentOS on Windows Subsytem for Linux (WSL)

I read about the Windows Subsystem for Linux a while back, and thought it was only available using Ubuntu. Today I wanted to play around with it and fish shell, but I prefer centos to ubuntu. A quick google found this github project – WSL Distribution Switcher –

Excellent! It allows you to switch from ubuntu to other linux distro’s. I’m not going to pretend I have taken the time to understand how WSL works ‘under the hood’ but as WSL Switcher gets docker layers / images, I’m guessing it based on docker in some shape or form?

I enabled WSL on my W10 1703 (Creators Update) build, started bash and created myself a user. Installed Python 3 (a requirement for WSL Switcher). Then I cloned the WSL Switcher git project and used the following commands to switch to centos and confirm it worked :

  • get-prebuilt.py centos:latest
  • install.py centos:latest
  • bash
  • cat /etc/centos-release

Everything seemed fine, but then I tried to run yum (the centos package manager). It wouldn’t run as a non root user, fine – tried “sudo yum”. Command not found – grrrrrr

Then I tried su – got prompted for password and thought I had made progress – entered the password for my linux user… nope!

Luckily, I’m not the first person to run into this problem 🙂 I found an issue in the WSL Distro Switcher github with the information I needed. I needed to switch the default user that WSL used, enter WSL / bash, change the passwd, then change the default user back to my non root user.

  • lxrun /setdefaultuser root
  • Found UNIX user: root
    Default UNIX user set to: root
  • bash
  • passwd
    • (enter your desired root password)
  • exit
  • lxrun /setdefaultuser *username*

Now when I went into WSL, I was logged in as my normal user – I could “su” and run commands as root – perfect! However, I like to sudo rather than switch to root using su – more to be done…

I thought the next bits would be easy – but alas no. yum wont work, even now I have access to root user – looks like a network issue. Should be simple to figure out right? I wish, no ifconfig, so i tried “ip addr” – neither work. Why do people insist on taking so much stuff out of an OS as to make it almost useless!


I thought that the networking was messed up – it was fine, but DNS resolution was messed up – I ‘resolved’ this by editing resolv.conf, which had a really random IP set for the nameserver! I fixed this and then moved onto to sorting out sudo!

  • yum install sudo
  • exit (to exit su shell back to normal user)
  • sudo yum
    • user is not in the sudoers file. This incident will be reported.
    • so we need to add to the sudoers file
  • su
  • vi /etc/sudoers
    • add a line near the bottom
    • username ALL=(ALL) ALL
  • exit (exit su shell)
  • sudo yum (testing)
    • It works!

Now onto fish commandline…

Its not in the main repos – so I had to first install epel

  • sudo yum install epel-release
  • sudo yum install fish

Now I can enter fish shell after entering WSL bash – i tried a few things to try and set fish as the default shell – but none of them worked. Probably something to do with docker / wsl. I will update this post if i can figure out how to go straight into fish…





Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s