Backup Home Directory with rsnapshot

Backing up data is important. rsnapshot is a simple tool you can use to take snapshots of your home directory (or other data) automatically on a schedule.

Prerequisites

Before starting it is assumed you have an external hard drive or secondary hard drive that snapshots will be copied to. This should automatically mount upon startup and you should know the mounting point of the device.

Installing rsnapshot

Open up a terminal window and ensure that your packages list is up to date by running the following command:

sudo apt-get update

After this has completed, install rsnapshot and rsync with the following command:

sudo apt-get install rsnapshot rsync

Configuring rsnapshot

Once the install has completed edit the configuration file in the text editor of your choice. The config file is located at /etc/rsnapshot.conf

Note: Use tabs rather than spaces when editing the rsnapshot.conf file.

To edit this in Vim run the following command:

sudo vi /etc/rsnapshot.conf

First of all modify the location where the snapshots will be stored. Scroll through the config file to find the line beginning with snapshot_root

Note: In Vim you can use search mode after pressing a forward slash (/). Type in the text string you’re looking for i.e. snapshot_root and press enter. You will be taken directly to that line. If a string appears multiple times you can cycle through them by pressing the letter N.

Modify this to read where the snapshots will be stored. This should match the location of the drive listed in prerequisites. i.e.

snapshot_root /mnt/snapshots

Note: If you are using Vim you can navigate the text file using the arrow keys or the letters H (left), L (right), J (down), K (up). To enter insert mode (so you can type text) Press I. To delete a character (when not in insert mode) Press X.

Now scroll down (or search) until you reach the backup levels section. The lines will start with retain alpha, retain beta, etc. Modify this so that it a little more user friendly.

retain hourly 24
retain daily 7
retain weekly 4
retain monthly 12

Scroll down further to the lines starting with backup. This is where you chose the folders that you wish to create snapshots of. In this case only the home folder is being backed up, comment out all the lines except the following:

backup /home/ localhost/

Note: To comment out a line simply put a # at the beginning of a line.

Save your configuration files and close the text editor.

Note: If you are using Vim save the file by pressing the ESC key, and then the letter W (write file), the letter Q (quit), and then press Enter.

Testing the Configuration

After the configuration file has been modified, the syntax of the file can be checked by running the following command:

/usr/bin/rsnapshot configtest

If all goes well the output will say Syntax OK. If there are any issues you will need to investigate further.

rsnapshot also allows for a test run of the backup. It outputs to the screen what would happening during a backup, but doesn’t actually touch any files. This can be run with the following command:

/usr/bin/rsnapshot -t hourly

If you are noticing anything in the output that shouldn’t happen, double check your configuration file.

If everything looks good, the initial backup can be run using the following command:

/usr/bin/rsnapshot hourly

Automating the backup

Now that rsnapshot is configured we want to configure a cronjob to automate the backup. To do this open crontab using the following command:

sudo crontab -e

Note: If this is the first time you are using crontab you will be asked to choose an editor. Pick whichever editor you are most comfortable with.

Add the following lines to the bottom of the file.

0 * * * * /usr/bin/rsnapshot hourly
30 3 * * * /usr/bin/rsnapshot daily
0 0 * * 1 /usr/bin/rsnapshot weekly
30 2 1 * * /usr/bin/rsnapshot monthly

Save the file and exit.

In the configuration section we’ve set how long backups are going to be kept. To break this down:

  • A snapshot is taken every hour over a 24 hour period
  • A snapshot is taken daily at 3:30 am
  • A snapshot is taken every Monday at 12:00 am
  • A snapshot is taken on the first day of the month at 2:30 am

The older versions will be removed as per the retention policy in the configuration policy.

And that’s it – you have an automated system that takes snapshots of your home directory and stores those files on a local drive.

Now that you’ve automated your backups with rsnapshot, you’ll have plenty of time to browse my other blog posts!

Python 3 KeePass Dictionary Attack

Github: https://github.com/0x6A6F7368/KeePassDictionaryAttack

A few years back I created a python script for a class I was teaching on password security. It is a basic script to run a dictionary attack against a KeePass database. Being that Python 2.7 EOL date is quickly approaching, I thought I might change my script to suit Python 3 – and do a quick blog post on how to run the new script.

First of all you will need to download and install the libkeepass module. This can be done using pip. If you haven’t installed pip3 you will need to do this first.

sudo apt-get install python3-pip
pip3 install libkeepass

Create a directory to store the script, and then change into the newly created directory.

cd ~ && mkdir keepassdictionaryattack
cd keepassdictionaryattack

You can supply your own password list as password.txt or download one of the many available online. I am using the 500 worst passwords list I found on Daniel Miessler’s GitHub.

Download the passwords and rename the file to passwords.txt

curl -O https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/500-worst-passwords.txt

mv 500-worst-passwords.txt passwords.txt

Now, download the KeePass Dictionary Attack script.

curl -O
https://raw.githubusercontent.com/0x6A6F7368/KeePassDictionaryAttack/master/KeePassAttack.py

Copy a KeePass database into ~/keepassdictionaryattack and then run the script.

python3 KeePassAttack.py

If the KeePass database is using a weak password, you may gain access to the database and all the goodies inside.

Installing and Using Git and GitHub on Ubuntu

GitHub is a web-based hosting of the version control system, Git. It allows for teams to easily work on projects, share code, and monitor versions. GitHub has both free and paid services depending on your needs.

This is just a simple tutorial to show you how to install and Use Git and GitHub on Ubuntu.

Notes: Before we get started if you are using GitHub with 2FA, you will need to setup a Personal Assess Token. This can be generated at https://github.com/settings/tokens

Also, if you do not wish to share your email address publicly, you can use your GitHub noreply email address. It will be in the form of [email protected] and can be found at https://github.com/settings/emails

You email address will also need to be verified. Information on this can be found at: https://help.github.com/articles/verifying-your-email-address/

Installing and Using Git and GitHub on Ubuntu

To get started we will need to install Git on Ubuntu. To do this enter the following command into terminal.

sudo apt install git

Once completed, you will now need to set your username and email address. These are your GitHub username and your GitHub noreply email address.

git config --global user.name "username"
git config --global user.email "[email protected]"

Now change to the Home Directory and create your first Git Repository.

cd ~ && git init MyFirstGit

If successful you should see the message: Initialized empty Git repository in /home/owner/MyFirstGit/.git/

Change into the newly created directory

cd MyFirstGit

Create a simple README file and add some text. This can be done with an editor of your choice. A quick sample is shown below.

echo "This is MyFirstGit" > README

Now you can add the file to the index and record changes to the repository

git add README
git commit -m "First commit to GitHub"

Now you need to create a repository on GitHub. This can be done via: https://github.com/new

The repository will need to share the same name as the folder you created earlier, i.e. MyFirstGit. You can leave Initialize this repository with a README unchecked as we have already created this file.

This is a fairly simple procedure but if you get stuck detailed steps can be found here: https://help.github.com/articles/creating-a-new-repository/

Upon creating a new repository you will be given the links to the repository, which should be similar to: https://github.com/username/MyFirstGit.git

We can now add the files to GitHub

git remote add origin https://github.com/username/MyFirstGit.git
git push -u origin master

You will be prompted to enter your username and password (or Personal Access Token if you are using 2FA).

You will now be able to share code and monitor versions the way Linus Torvalds intended.

Change the default editor for Visudo

Visudo is a tool used to safely edit the sudoers file. Visudo locks the sudoers file to ensure multiple users are not trying to edit the file, as well as performing basic sanity checks, and checks for parse errors.

The sudoers file is where you edit the options for sudo. Such as allowing a user to use sudo for all programs – or a handful of programs they require.

To make things easier for people new to Linux, the default editor for Visudo on some Linux distros (i.e. Ubuntu) is Nano. I’ve never really got used Nano. So to make things easier for me I like to swap it back to Vim.

To make changes, we will first have to enter the following command to safely edit the sudoers file.

sudo visudo

This of course will open with nano. Replace the line:

Defaults        editor=/usr/bin/nano

with

Defaults        editor=/usr/bin/vi

and save your file.

Visudo will now open with Vi, the way the greybeards of old intended.

Quit a program on Ubuntu with Alt + Q

It has been just over 3 weeks since I  started using Linux as my daily driver. It hasn’t been an unpleasant experience – although there have been tweaks and fixes along the way.

Instead of bringing over something from Windows that I am so used to having; today’s tweak comes from the Mac – where you can use Command (⌘) + Q to quit a program. This is mush more elegant than Alt + F4 on Windows and Ubuntu.

On my Microsoft 600 Keyboard Alt + Q feels very much like Command (⌘) + Q on the Mac – so I will go with that.

First of all I will remove the old keybinding for Close Window. This can be done by entering the following into a Terminal window.

gsettings set org.gnome.desktop.wm.keybindings close "@as []"

Now I will add the keybinding for Alt + Q. This can be done by entering the following into a Terminal window.

gsettings set org.gnome.desktop.wm.keybindings close "'<Alt>q'"

You can now quit programs on a PC running Ubuntu the way the Apple Corporation running under Steve Jobs intended.

Or close enough to it!

Minimise windows on Ubuntu 18.04 with Super + M

This has turned somewhat into a series of blog posts outlining my transition to Linux as my daily driver. I’m not new to Linux, and have run various variants of Linux on servers (Slackware and Ubuntu mostly). The desktop experience has been a little different as there are certain things I have been so used to on Windows – and I don’t like too much change all at once!

These steps may carry over to other versions of Ubuntu. I will now show you how to Minimise windows on Ubuntu 18.04 with Super + M.

This post will go though changing the ‘minimise all windows’ keyboard shortcut from Control + Super (Windows Key) + D to Super (Windows Key) + M.

Super + M by default on Ubuntu 18.04 opens the Message Tray. The Message Tray can also be opened with Super + V.

First up I will remove the key bindings for ‘toggle message tray’. To do this open Terminal and run the following command:

gsettings set org.gnome.shell.keybindings toggle-message-tray "@as []"

This will  remove the key bindings for both Super + M &  Super + V. We can re-add Super + V so we still have a keyboard shortcut for the message tray with the following command.

gsettings set org.gnome.shell.keybindings toggle-message-tray "['<Super>v']"

Now to add Super + M to minimise windows.

gsettings set org.gnome.desktop.wm.keybindings show-desktop "['<Super>m']"

You can now minimise all open windows the way the 90’s Microsoft Corporation intended.

Fixing the Calculator Key in Ubuntu 18.04

Recently I decided to give Ubuntu 18.04 a go as my daily driver. I have slowly been finding things that do not work as expected, and will blog about them here.

So far I’ve found there was no date in the top bar, my printer doesn’t work, and sudo didn’t curse me if my password was entered incorrectly.

This time my issue is the calculator keyboard shortcut on the Microsoft Wired Keyboard 600, doesn’t open the Calculator. I use this key many times a day, and eventually got sick of searching calc in the Application menu.

I did a bit of Googling and found this post on askubuntu.com, It appears to be a common issue on Ubuntu 18.04 – and fortunately it is a simple fix. Here is a link to the bug report.

The issue looks to be with the gnome-calculator snap package. To fix the issue, first we need to remove gnome-calculator and reinstall it using apt. Type the following commands into a terminal window.

sudo snap remove gnome-calculator

followed by

sudo apt install gnome-calculator

The keyboard shortcut for the fancy abacus will now work as the mighty Sumerian and Egyptian empires intended.

Turn on Sudo Insults

As part of using Linux as my daily driver, there are certain things I like having on my Servers that I can now have on the Desktop. i.e. Sudo Insults.

‘Sudo insults’ swaps the ‘incorrect password message’ for a funny one-liner, or better – an insult – when you have incorrectly entered your password using sudo.

To enable insults we need to edit the sudoers file. This should always be done using visudo. To edit the sudoers file enter the following command:

sudo visudo

Add the following line under Defaults env_reset

Defaults insults

Save your file and exit.

You will now be insulted when you incorrectly enter your password, just as the Unix beards of old intended.

Show date in Ubuntu 18.04 top bar

I have recently starting running Linux as my daily driver. Of course, after using Windows almost every day of my working life, there are things that I am used to just having. In this case a quick option to look at the date along with the time.

By default, Ubuntu 18.04 shows just the time. You can click on it to view a calendar and see the day. Sometimes you just want a way to quickly see the date (for the 11th time that day and you still cant remember what the date is). To enable the date I have installed Gnome Tweak Tools and then used dconf to see what has been changed when I use the GUI to make changes, so that it can just be done easily in Terminal.

Start by opening Terminal and then enter the following commands:

sudo apt-get update
sudo apt-get install gnome-tweak-tool

GNOME Tweak Tool will now be installed. You can open the GUI for GNOME Tweak Tool by clicking the Show Application button at the bottom left of the screen and selecting Tweaks

The Date can easily be added to the top menu by running the following command:

gsettings set org.gnome.desktop.interface clock-show-date true

You now have the date displayed alongside the time – Just as Chronos intended.

Linux as my daily driver

I recently retired the first Linux server I had ever configured. It was only a simple server – Slackware running Samba as a network share. It was pretty low maintenance, but it was where I had learned and practiced my Linux skills.

I found myself in a position where Windows Servers now outweigh my Linux servers, and as a way to keep my Linux skills sharp – I thought, why not run Linux as my daily driver?

I picked Ubuntu 18.04 LTS. I have used Ubuntu before, but mostly Ubuntu Server. Last time I used Ubuntu Desktop, the distribution was still using Unity. It was not my cup of tea. Ubuntu 18.04 uses GNOME Shell instead – which I do find is a little better.

So far I was off to a good start. Many programs I use work on Windows, Linux, and Mac. So these things moved over smoothly. One major issue I had right off the bat, was my printer doesn’t work, and drivers for my fax modem (yes I still need to send the odd fax), wouldn’t work either. I’m sure this is something I will sort out over time.

So wish me luck as I go down the new path of Linux on the desktop. I will keep this post updated with my experiences on making Linux my daily driver.

 


Quit a Program on Ubuntu with Alt + Q

Minimise Windows on Ubuntu 18.04 with Super + M

Fixing the Calculator Key in Ubuntu

Turn on Sudo Insults

Show Date in Ubuntu 18.04 Top Bar