How to Encode and Decode Base64 Strings With Mac OS or Linux

Tremaine Eto
The Startup
Published in
3 min readSep 9, 2020

--

Photo by James Orr on Unsplash

One pretty common task that I need to do during with my day-to-day software engineering is to either encode or decode base64 strings; it comes up when I’m working with things like private keys or Kubernetes secrets, which are base64 encoded. To do so, you can easily memorize one command for each that you can run in your terminal.

First of all, I would be remiss if I didn’t mention that you don’t necessarily have to do this in your command line interface. There are two sibling websites, Base64 Decode and Base64 Encode, that achieve this task. I’m not affiliated with them in any way, but I’m quite certain that many, many developers are familiar with them.

However, there are various reasons why you may not use those sites; for one, perhaps you’re offline and can’t access them. Second, perhaps you don’t fully trust your secret data going to the server of someone you don’t know. Both are really valid points, and that’s why I suggest the methods I’m about to go over.

Encode in base64

First, to encode in base64, run the following command in your terminal:

echo -n 'username' | base64

Let’s go over the different components to this.

  • echo: This command writes a string to standard output…

--

--

Tremaine Eto
The Startup

Senior Software Engineer @ Iterable | Previously worked at DIRECTV, AT&T, and Tinder | UCLA Computer Science alumni | Follow me for software engineering tips!