Linux Command Line QR Codes

You probably know what a QR code is, but if you don’t, you likely used them when you’ve eaten out at a restaurant. Do you know you can generated them at the command line? Did you also know you can can generate wifi login credentials in the form of QR codes at the command line?

A link to Joelle’s author page at medium.com

Generating QR Codes for Arbitrary URLs

While there are a ton of internet sites which will generate QR codes for arbitrary URLs, some of these function as intermediaries, with generated QR codes actually visiting something other than your URL first. Sometimes they advertise this fact (“Track the success of your marketing campaign!”) but if you want a safe way that the QR code just points at your own URL, without any dependencies on other sites, you want to generate your QR code yourself. Fortunately it is easy.

You first need a Linux app: “qrencode”. On Ubuntu, you can install this at the command line with:

sudo apt install qrencode

Once that is installed, you can encode any arbitrary text in the QR code (up to about 4,000 characters). In our case, we want to encode a URL, this one to “https://medium.com/@joellemaslak”.

qrencode -s 20 -o qr.png https://medium.com/@joellemaslak

This generates a file, “qr.png”, with my QR code in it, on a 20×20 pixel grid (the -s option). Of course there are a ton of options for qrencode, including the ability to generate other output types than PNG (such as EPS, which may be useful for print publications).

The output looks like the image at the top of this article.

Generating QR Codes for Wifi Login

What if you want to share your wifi password with customers or guests? Sure, you can create a complex, secure password that you give your house guests , but to save time, you can encode that into a QR code and they can point their iPhone or Android device at the QR code to just login to your network. Assuming your network uses modern standards and a password, you need to generate a QR code in the following format:

WIFI:S:<ssid>;T:WPA;P:<password>;;

Thus, the string for a wifi network named “coffeeshop” with a password of “I love coffee” might be:

WIFI:S:coffeeshop;T:WPA;P:I love coffee;;

To generate a QR code (remember, I mentioned that QR codes can encode anything up to 4000 characters?), you just encode this. So something like:

qrencode -s 20 -o wifi.png ‘WIFI:S:coffeeshop;T:WPA;P:I love coffee;;’

Note the single quotes, which are important (as the semicolon would likely be interpreted by your shell). This generates something like:

A Wifi QR Code

Note that this isn’t an encrypted wifi password. Anyone can decode this QR code and see what your wifi password is, as it is in the plain text representation of the QR code. But what this does is allow your visitors to just point your phone at the QR code and log into your wifi network without a painful process of trying to type a complex password into a phone.

For my home network, I printed out my home’s guest network password onto a large label and stuck that label to my access points. Someone looking around for wifi would likely notice these access points — if they don’t know why there is a QR code, when they ask ask, “Can I use your wifi?” I can just point to the access point and say, “Yes, that QR code will log you into my network.”

Other Uses

Of course you can store any text (up to the maximum size limit of roughly 4,000 characters) in a QR code. What they mean is entirely up to you!

Leave a comment