In a previous post, I shared some info on how to connect to your Azure Cloud Shell shared drive, with a particular focus on Bash on Windows. I thought to myself, “How can I make this even easier?”
Here’s how to get started in just two commands!
TL;DR version - run this
# Run the setup script curl https://gist.githubusercontent.com/noelbundick/f03200a4387b4bf4d3eed2d97169fc89/raw/738c3417a2513847dc71dabb844c395616831de9/setupclouddrive.sh | bash # Run the created mount script ~/.mountclouddrive.sh
Make sure that you’ve already gone through the Cloud Shell setup for your selected subscription. That will get you set up with the storage account we’ll connect to here. You’ll also need to get logged into the Azure CLI on Bash on Windows.
All the cool kids these days seem to be piping curl to Bash, so I’m going to have you do the same here.
Seriously, don’t just pipe commands to your shell blindly! Take 10 seconds and go look at what I’m telling you to do here before copy/pasting this.
curl https://gist.githubusercontent.com/noelbundick/f03200a4387b4bf4d3eed2d97169fc89/raw/738c3417a2513847dc71dabb844c395616831de9/setupclouddrive.sh | bash
This script will connect to Azure to get some info about your Cloud Shell storage account. It then uses Windows Interopability to invoke Windows binaries from Bash, securely storing your secrets & keeping them out of your scripts (this might actually be the coolest thing about this whole process). And it drops a mount script in your home folder for everyday use.
2. Everyday usage
Because only root can use the
--types option on
mountclouddrive.sh script needs sudo access. You should look at the script to make you understand what it’s doing - never take my word for it. Check it out with
Looks legit to me! And to connect during your normal dev/admin activities, use
Putting that all together, you’ll get something like the following
Easy! 2 commands and you’re up and running!
Notes on the Code
Wow, you’re still reading! I wanted to explain some of the code so it wasn’t magic voodoo - I want you to learn this stuff and go build bigger & better things. There are a few interesting things going on here I’ll point out.
I’m using built-in JMESPath query support to filter storage accounts to only get the ones in the
cloud-shell-storage resource groups, which is the convention used per the Cloud Shell docs. Should there be multiple of those, I’m also getting just the first one. This is a super handy way for extracting simple JSON properties from complex objects & arrays without needing to use a separate tool.
Specifying TSV output gives clean strings that make it easy to use with other commands.
So cool. This lets me invoke
cmdkey.exe from inside Linux to save secrets in Windows, and I don’t have to worry about secrets in files.