How to easily encrypt any file or directory with Mcrypt on Linux System

In this config we will show you a number of examples how to use mcrypt tool to easily encrypt files whether the file is large or small in size. We will also use Mcrypt to encrypt and compress files and directories on the fly which can be usefully for a number of backup and scripting purposes.

Mcrypt installation

UBUNTU/DEBIAN
# apt-get install mcrypt
REDHAT/FEDORA/CENTOS
# yum install mcrypt

Creating a testing sandbox

Let’s first create a directory with some files we can work with:

$ mkdir dir1
$ cd dir1/
$ echo "My File to Encrypt" > file1
$ cat file1 
My File to Encrypt
$ fallocate -l 500MB file2
$ md5sum file*
bccd44aaa84c7c9d04a268f670ae92c5  file1
4034379ecc54213fc9a51785a9d0e8e2  file2

Read more

Compress file or directory using RAR archive tool on Linux shell

Here is a quick config tip on how to compress and extract files using RAR archive utility. First let’s see how we can compress directory using RAR. In our example we have a directory called my_files containing five files:

$ mkdir my_files
$ touch my_files/file{1..5}
$ ls my_files/
file1  file2  file3  file4  file5

To compress entire directory using RAR archive tool we use rar’s a command. The below command will create a RAR archive called my_files.rar containing all five above files:

$ rar a my_files.rar my_files/

Creating archive my_files.rar

Adding    my_files/file5                                              OK 
Adding    my_files/file4                                              OK 
Adding    my_files/file3                                              OK 
Adding    my_files/file2                                              OK 
Adding    my_files/file1                                              OK 
Done
$ ls -l my_files.rar 
-rw-rw-r--. 1 lrendek lrendek 307 Nov  3 06:55 my_files.rar

Read more

How to extract a specific file from gzip compressed archive tarball

In order to extract a specific file from gzip compressed archive tarball you first need to know the full path to this file. Consider a following example.

$ tar tzf to-gzip.tar.gz
to-gzip/
to-gzip/file10.txt
to-gzip/file9.txt
to-gzip/file8.txt
to-gzip/file7.txt
to-gzip/file6.txt
to-gzip/file5.txt
to-gzip/file4.txt
to-gzip/file3.txt
to-gzip/file2.txt
to-gzip/file1.txt

Read more

BackupPC installed on Linux

BackupPC tutorial on Linux

BackupPC is a free and versatile backup suite that can run on Linux systems and supports several protocols like NFS, SSH, SMB, and rsync. It can be used to backup numerous Linux, Mac, and Windows machines.

It has a lot of nice features like automatic backups and a web interface as its control panel. It also uses file compression and hard links to try and minimize the amount of space that your backups consume. Thus if a file is present on multiple machines, BackupPC is smart enough to only store a single copy of that file in the backup.

In this guide, we’ll show the step by step instructions for installing BackupPC on popular Linux distributions like Ubuntu, Debian, and CentOS. We’ll also cover some initial configuration so you can understand how to setup backup tasks within the program.

In this tutorial you will learn:

  • How to install BackupPC on various Linux distros
  • Initial configuration of BackupPC
BackupPC installed on Linux

BackupPC installed on Linux

Read more

How to configure smartd and be notified of hard disk problems via email

How to configure smartd and be notified of hard disk problems via email

In the article about checking an hard drive health using smartctl we talked about the smartmontools package, and we saw that it provides two components: a command line utility (smartctl) and a daemon, smartd, we can use to schedule operations. We focused on the usage of the former and we saw what are the S.M.A.R.T tests we can run and how to actually run them.

This time, we will talk about the smartd daemon: we will see how to schedule tests and how to configure it to so to be notified via email when an error is found on a storage device. In the course of the article I will assume the smartmontools package to be already installed. Please refer to the aforementioned article for installation instructions.

In this tutorial you will learn:

  • How to configure the smartd daemon
  • What is the meaning of some of the more used directives that can be used with smartd
  • How to configure msmtp to forward email to gmail smtp server for messages to be delivered externally
  • How to test the configuration
How to configure smartd and be notified of hard disk problems via email

How to configure smartd and be notified of hard disk problems via email

Read more

How to check an hard drive health from the command line using smartctl

How to check an hard drive health from the command line using smartctl

The smartmontools package is generally available in the default repositories of all the major Linux distributions. It contains two utilities useful to check the status of storage with S.M.A.R.T support (Self Monitoring Analysis and Reporting Technology): smartcl and smartd. The former is the utility we use directly to check S.M.A.R.T attributes, run tests, or perform other actions; the latter is the daemon which can be used to schedule operations in the background. In this tutorial we will learn the basic usage of smartctl.

In this tutorial you will learn:

  • How to install smartmontools package on various distributions
  • What are the differences between the S.M.A.R.T self-tests
  • How to use smartctl to check the health of a storage device
  • How to run tests on a storage device from the command line

Read more

How to use a file as a LUKS device key

How to use a file as a LUKS device key

LUKS is the acronym of Linux Unified Key Setup: it is the most used encryption implementation used on Linux systems and can be configured as an alternative to dm-crypt plain setup. Compared to the latter it provides some additional features like password hashing and salting and the ability to store multiple passwords in the so called LUKS header. In this tutorial I will assume the reader has a certain familiarity with LUKS; if you want to know more about this subject, you can check our basic guide about encrypting linux partitions with luks. The most common way to protect a LUKS device is to use a passphrase, however it is also possible to use a file as a key; in this tutorial we will see how to do this. Let’s go!

In this tutorial you will learn:

  • How to create a file with random data to use as a LUKS device key
  • How to add a key to a LUKS device
  • How to automatically decrypt a LUKS device at boot using a file as a key

Read more

How to find file in Linux

How to find file in Linux

If you need to search for one or more particular files, Linux systems have a few powerful methods for locating them, such as the find and locate commands. Searching for a file with a specific name can be done, but you can also search for files that follow certain naming patterns. This can be broadened all the way to finding files based on file size, file extension, or a lot of other options.

It’s also possible to find a particular directory or search for files based on their contents, such as finding all files containing a specific text, but we cover those topics in separate guides.

In this tutorial, you’ll learn how to find a file in Linux by using the command line and GUI. Let’s get started.

In this tutorial you will learn:

  • How to find a file in Linux via command line
  • How to find a file in Linux via GUI

Read more

Use killall to end a process by name on Linux

How to use killall command on Linux

When it comes to killing a running process, there are a few options available on Linux systems. One such option is the killall command, which differs from the kill command, as we’ll see below.

In this guide, you’ll learn how to use the killall command to end running processes on Linux. You’ll also be given various examples that you can apply to your own system.

In this tutorial you will learn:

  • How does the killall command work?
  • killall command examples

Read more

Unzip command on Linux

How to unzip a zip file from command line and GUI

You might think that zip files belong on Windows, not Linux systems. Still, it’s a popular compression method and chances are that you’ll run across them online from time to time. Either that, or your Windows buddy will send you a zip file that you want to open.

In this guide, we’ll show you how to unzip (decompress) zip files on Linux. You’ll learn a command line method as well as a GUI method in the step by step instructions below.

In this tutorial you will learn:

  • How to unzip a zip file via command line
  • How to unzip a zip file via GUI

Read more

Jail ssh user to home directory on Linux

Jail ssh user to home directory on Linux

Jailing an SSH user to their home directory allows you (the administrator) to exercise a lot of control and security over the user accounts on a Linux system.

The jailed user still has access to their home directory, but can’t traverse the rest of the system. This keeps everything else on the system private and will prevent anything from being tampered with by an SSH user. It’s an ideal setup for a system that has various users and each user’s files need to stay private and isolated from the others.

In this guide, we’ll show you the step by step instructions for jailing an SSH user to their home directory.

In this tutorial you will learn:

  • How to jail SSH user to home directory

Read more

Find all files containing specific text

Find all files containing specific text

You probably already know how to use the grep command to search for a text string in a file on Linux. But what if you want to retrieve a list of files that contain the text string? This is a task best suited for grep or the find command. We’ll show you how to do it in this guide.

In this tutorial you will learn:

  • How to use grep and find commands to find all files containing specific text

Read more