Setup SSH Tunnel for SytemD

The what:

There are several cases when you just need some SSH tunnel to another system with some port redirections.
If the tunnel fails for whatever reason, it should reset itself. Setting up a SSH tunnel with port redirection as a service is the answer!

The How:

Creating SystemD config

The setup is a “user defined” config. When the user is logged on to the system, the service will become active.
You need to setup SSH password less login setup (with keys) to be able to use this.

First you need to created some directories (if not present)

Then create a SystemD service definition file inside this location
Name the file:

The content….:

After creating the file, SystemD needs to know that this file is present. You need to do a reload of SystemD

Almost done…..

Define the tunnels

To define a tunnel, add the following lines to your ~/.ssh/config file. If not present, create the file.

More tunnels? just duplicate the block with other params.
If you need more option for SSH, take a look at man ssh_config

Running the tunnels

Lets get your hard work up and running!
Use the systemctl command to start/stop/status you’re tunnel

To set-up autostart, use the same command but replace start with enable
This will start the tunnel when you log-on to your system.

Thats it! you’re up and running!

Checking / Stopping the tunnel

For status checking, use the systemctl command

To stop the tunnel



MySQL Search and Replace Query

You need to change some data or whatever inside a table, but you don’t want to edit every row by row. Just use this query to search for a string in a table column and change it!

When Should I use MySQL Search and Replace?

Doing a Search and Replace via SQL could be dangerous if you have links that you’re unaware of which shouldn’t be changed. You should Search and Replace only when you’re convinced that you have to change the text in your Database. You should always perform a Database backup before proceeding with any manual changes. This can easily be done through phpMyAdmin:

Search Puppet file bucket for a changed file(s)

When you use Puppet to manage your infrastructure, it’s common to manage several files on a system with a template or something. The default setting when a file is changed, it gets a backup on the client system in a filebucket

You can use to command ‘puppet filebucket’ with a lot of options to hopefully get what you want…. Or…. just search the filesystem 🙂

The location below holds the directory structure were the files are physically stored! with a lot of hashes added 😐

A directory structure could look like this:

The files content and paths hold the magic information about original file and its location. YES!!

Use the following command the search your filebucket to get you’re long lost files back!!

This only works when the file is managed through the ‘file’ resource type.

Files changed by augeas or not to be found here…. Bummer!

Rename all files in directory from $file to $newfile

The what?

Dead simple.
How do I rename


I think it’s simple, but it’s hard to Google for this kind of thing unless you already know.

The how…..!

You can do this with a simple one-liner with bash