Enable WSL:If not done yet, enable WSL (Windows Subsystem for Linux):
- Enable Developer Mode:
Windows > Settings > Update and Security > For developers > Developer mode;
- Enable the Windows Subsystem for Linux and restart by running this command in an elevated PowerShell:Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
- Run "bash.exe" and complete installation of WSL;
Install Azure CLI on WSL:
- Launch bash
- If not done yet, work around sudo not being able to resolve your machine name by running:sudo chmod 666 /etc/hosts
sudo echo 127.0.0.1 $HOSTNAME >>/etc/hosts
sudo chmod 644 /etc/hosts
- Install (a decent!) NODE package:
curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
sudo apt-get install -y nodejs
NOTE 1: if you try going the "simpler" way of just running "sudo apt-get install node", you'll get a very old node version and when you later run any azure command you'll get an error similar to the one below: (this is after running azure login, which does work even with the broken node!)login@COMPUTER:~$ azure location listinfo: Executing command location list+ Getting ARM registered providers
error: Object https://management.azure.com has no method 'endsWith'error: Error information has been recorded to /home/mad/.azure/azure.err
error: location list command failed
NOTE 2: if you get connectivity problems when running the above commands, try disabling your AV's FW - I ran into some weird problems using Kaspersky and temporarily disabling allowed these to run properly. The errors I'd get would complain of no connectivity from an IPv6 IP address, even though I have IPv6 disabled...
- Install the Azure CLI NPM module: sudo npm install -g azure-cli
- Enable auto-completion: azure --completion >> ~/azure.completion.shecho 'source ~/azure.completion.sh' >> ~/.bashrc
- Exit and re-open bash and you should now have a working install of Azure CLI commands for Linux, running on your Windows Subsystem for Linux.
- Try it out:
- azure login (Follow the on-screen instructions)
- azure account list Don't forget that you have auto completion for azure commands too!
Bonus: Private/Public Keys
- Generate a private/public SSH key pair for easier authentication (replace "mypassword" with a proper password that you'll type when needed) ssh-keygen -t rsa -b 2048 -C "$USER@$HOSTNAME" -f ~/.ssh/id_rsa -N mypassword
- Verify that the ssh-agent is running (you should get a PID value listed):
eval "$(ssh-agent -s)"
- Add the newly created key to ssh-agent:
- If you have already created a VM you can install the new SSH public key to your Linux VM with (replace login@yourvmip with proper values):ssh-copy-id -i ~/.ssh/id_rsa.pub login@yourvmip
- Test the login using keys instead of a password (again, replace login@yourvmip with proper values – this is a single line, split only on the blog!): ssh -o PreferredAuthentications=publickey -o PubkeyAuthentication=yes -i ~/.ssh/id_rsa login@yourvmip
- SSH is successfully configured if you are not prompted for an SSH private key password, or a login password to the VM.
If you need to re-install WSL:(As I did a few times trying to compile and test these instructions)
Run from a command prompt:
lxrun /uninstall /fullNote: the /full will WIPE your home folder, so a new install will be a clean install; if you want to keep those, just omit /full
lxrun /installPlease note that installing will re-download the Linux image from the Windows store again, so beware of internet charges if applicable.
Sources used to compile this information: