Encode or Decode base64 from the Command Line

If you have ever needed to quickly decode or encode base64, Linux has a command line utility called base64 that works great. I’ll show you how it works!

To encode text to base64, use the following syntax:

$ echo -n 'codediary.net rocks' | base64

To decode, use base64 -d. To decode base64, use a syntax like the following:

$ echo -n Y29kZWRpYXJ5Lm5ldCByb2Nrcw== | base64 -d
codediary.net rocks

Note: if on OS X, use capital D:

echo -nY29kZWRpYXJ5Lm5ldCByb2Nrcw== | base64 -D

Access MySQL Without Password

For MySQL you can specify your user and password in local config file (.my.cnf). This file should be in your home directory (i.e. ~/.my.cnf).



How do you gunzip a file and keep the .gz file?

You’re looking for:

gzcat x.txt.gz >x.txt

The gzcat command is equivalent to gunzip -c which simply writes the output stream to stdout. This will leave the compressed file untouched. So you can also use:

gunzip -c x.txt.gz >x.txt

Note that on some systems gzcat is also known as zcat so run like this instead:

zcat x.txt.gz >x.txt

How to gzip and keep original file on Unix or Linux command line

I would like to compress a log file using gzip Unix command line utility, and I would also like to keep the original file. However, when I use the gzip my-app.log command, results in modifying my log file and renaming it my-app.log.gz. How do I force the gzip command to keep original file while maintaining the original file on Linux or Unix-like system?

The gzip program compresses and decompresses files on Unix like system. You need to pass the -c or --stdout, or --to-stdout option to the gzip command. This option specifies that output will go to the standard output stream, leaving original files intact.

Continue reading

Routing to allow SSH over a specific interface

Sometime when you have two network interfaces (say eth0 and eth1) on the client and for some reason there is a need to SSH to the server over a specific a specific interface. By default the primary interface will be used. To use eth1 we just need to add a route:

route add -net netmask gw eth1

The route is removed upon reboot. Use -p to permanently add the route to the table. To delete the route:

route del -net netmask gw eth1


Simplify Your Life With an SSH Config File

If you’re anything like me, you probably log in and out of a half dozen remote servers (or these days, local virtual machines) on a daily basis. And if you’re even more like me, you have trouble remembering all of the various usernames, remote addresses and command line options for things like specifying a non-standard connection port or forwarding local ports to the remote machine.

Continue reading

How To Enable HTTP/2 in Apache on Ubuntu 16.04

Here’s a simple guide showing how you can enable HTTP/2 in Apache on Ubuntu 16.04.

Today’s internet connections are amazingly fast. You younglings might not believe this, but there was a time when we actually had to sit and wait for a website to appear. If you want to experience the internet speeds of the past, give 56k Emulator a try. It will give you the basic idea. And keep in mind that 56K modems were freakin’ fast when they became available.

Even though today’s internet connections are fast, the technology used to push propaganda around inside the tubes is old and slow. HTTP/1.1 was never intended to be used with the kind of content-heavy website we have today. Thankfully, there’s a new option available, the marvelous RFC-7540. Or HTTP/2, if you will.

Continue reading

What’s the difference between .tar.gz and .gz?

In Unix and Unix-like systems (like Ubuntu), archiving and compression are separate.

tar puts multiple files into a single (tar) file.

gzip compresses one file (only).

So to get a compressed archive, you combine the two, first use tar or pax to get all files into a single file (archive.tar), then gzip it (archive.tar.gz). If you only have one file you need to compress (notes.txt), there’s no need for tar, so you just do gzip notes.txt which will result in notes.txt.gz. There are other types of compression, such as compress, bzip2 and xz which work in the same manner as gzip (apart from using different types of compression of course)

Source: http://askubuntu.com/questions/122141/whats-the-difference-between-tar-gz-and-gz-or-tar-7z-and-7z

L2TP / IPSEC VPN on Ubuntu 16.04

LT2P IPSEC vpn works simple and easily with iOS/Android and Windows 10. Unfortunately as many people likely know (after a few google searches it seems) the client for this is pretty crap in Ubuntu 16.04.

Our setup uses a shared PSK, and a username and password.

I’ve tried a bunch of the quick setup guides, but many were for older versions of Ubuntu and thus didn’t work very well. Finally I stumbled across this guide: https://gist.github.com/psanford/42c550a1a6ad3cb70b13e4aaa94ddb1c

which was used to connect with a meraki router over vpn. There were some minor tweaks in my case, but I managed to get it work.

Continue reading