LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

How to Create and Display QR Codes From Shell Scripts

QR (“quick response”) codes are nearly 25 years old.  They first appeared on the tech scene in 2000 and were invented by Japanese automotive components giant Denso as a way to identify parts in production.

Although most people think of QR codes as “that box I scan with my phone’s camera to go to a web site,” you can actually encode a LOT more in a QR code.  If you’re using the Latin upper-case alphanumerics and common punctuation (0–9, A–Z, space, $, %, *, +, -, ., /, :) you can store 4,296 characters.  And if you do, the QRs get mighty dense.  Here’s 3,000 characters of Lorem Ipsum:

QR Lorum

For numbers only, you can store 7,089 characters!

All info in a a QR code is stored in the image itself.  There’s no “registered” a QR code or central QR code authority.  If you encode a text to a QR code and someone on the other side of the world encode it, you’ll get the same image.

Shell Scripts

A while ago, we did a tutorial entitled “Using Google Authenticator for SSH and Console Connections to Your VPS“.  This showed you how to setup your VPS so that when someone logged in, they were prompted for 2FA (Google Authenticator).

As part of that setup, the google-authenticator script displays a QR code in your terminal that you scan with your phone.  Pretty neat.  But that code is done via C code written by Google.

Is there a way mere mortals can do the same?

Yes!  Via qrencode, which is in most distro’s package managers.

After a simple

apt install qrencode

you’ll have the ability to generate QR codes to your heart’s content.

Not only can qrencode spit out QRs in image formats like PNG, but it can produce text output QR codes that display in your terminal.

For example:

qrencode -m 2 -t utf8 <<< "https://www.lowendbox.com"


The -t flag sets output to text.  You could do something like “-t png -f output.png” to save it as an image.

The -m flag sets the margin width.  Default is 4 and here I’ve made it a little more snug for a smaller image.

And that’s all there is to generating QR codes easily from shell scripts.


No Comments

    Leave a Reply

    Some notes on commenting on LowEndBox:

    • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
    • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
    • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

    Your email address will not be published. Required fields are marked *