:::: MENU ::::

Posts Categorized / Linux

  • May 25 / 2018
  • 0

Change the passphrase of your SSH key

Forgot your SSH key passphrase? There’s an easy way to renew it locally if you have access to it:

And then, enter the new passphrase you want to use.

  • Apr 01 / 2018
  • 0
Linux, Python

Using procmail with custom python script

If you want to execute some special commands, log or make an API call when you’re receiving an email onto your server, you can easily set up this by using procmail. Procmail is designed to filter and sort emails but can make any call you want.

Here, as an example, we will set up a simple call to a python script that will read the content of the mail (headers and body) and put the information into a log file.

1. Install procmail

Depending on the OS you’re using, you should find a package pre-compiled in the common repositories.

For example, on a Debian-based:

or on a CentOS-based:

2. Build the python script you want to call to analyze the message

You now have to prepare your script you will execute when receiving an email, that will read and parse the content to log interesting information in a file.

Let’s create a script called procmail_script.py

3. Configure your user to pass the mail to your script

So that you can pass rules you want to execute when receiving an email, you need to create a file (hidden) called .procmailrc that will take place in the home directory of the user you want to use.

For example, for executing rules when receiving email to [email protected], you will have to put that file into the home dir like /home/mailuser/.procmailrc

This will perform multiple steps:

  1. Check that the mail recipient is [email protected] or [email protected]
  2. Put a copy of the email into the procmail-dir directory
  3. Pass the message to our python script procmail_script.py
  4. Discard the message if the script succeeds (remove from queue) or copy it to procmail-failed-dir if failed (so you can process it later)

4. Prepare an email and perform a testing locally

First, create a sample mail that you will use for testing in a file called procmail_test.txt:

Then, you can test it by executing procmail manually:

Now, open the file /opt/mailAnalysis.log and you should have something like:

  • Feb 12 / 2018
  • 0

Execute cron on a specific day of the month (e.g. second monday)

How to execute a cron on a specific day of the week once in the month?

This could look simple as we could think that this line in cron would do the trick:

But this would not work as the ‘2’ for checking the Tuesday will come as a OR condition, and the command would be executed from day 8 to day 14 and on every Tuesday of the month.

As a workaround for that, you can use that command:

Here is the explanation of this cron line:

Doing this check will allow to verify first that we are on the second tuesday before to execute the command. Don’t forget to add a backslash before the ‘%’ character to escape it.

  • Dec 21 / 2017
  • 0

Control services on Linux (systemV, systemd, initctl…)

On Linux, there’s many ways to control services that can run on your system. Here are the main and most known init systems that you can find on the common distros, depending on their version.


That system is one of the oldest and one of the most common. Its init scripts are stored in /etc/init.d/

To list all the available services, you have to use that command:

To perform an action on one of those services, you will be using:

Upstart (initctl)

Upstart is a successor of SystemV scripts. It works asynchronously, and its scripts are stored in /etc/init/

To list all the available scripts, you have to use that command:

To perform an action on one of those services, you will be using:


Its name SystemD means System Daemon. It manages daemons that can be running on a system. It’s a successor of upstart and allows a more flexible management for the services. Init scripts are stored in /etc/systemd/system/

To list all the available scripts, you have to use that command:

To perform an action on one of those services, you will be using:


Finally, SupervisorD is a supervisor focusing mainly on the applications more than the system. It allows management of applications execution and control their life like you could do with system services.

To display all the applications managed by supervisord:

To control those processes, you will be using:

  • Nov 21 / 2017
  • 0

Generate a CSR with openssl

Generate a CSR (Certificate Signing Request) on your server when you want to get a certificate from a certified provider is often a mandatory step, very easy to execute.

Here are the different steps to execute:

  1. Create a specific directory where you will put all your files
  2. Generate a private key of 2048 bits
  3. Now generate a CSR with openssl and with the private key you just generated

    Many information will be asked during the creation:
  4. You now have your CSR and your private key

It’s up to you to get your signed certificate from an official provider using those files.

  • Nov 02 / 2017
  • 0

Change or remove password expiration for linux user

It can happen that you’re getting that message when trying to connect to your linux server:

The message is quite explicit and you need to update your password right now.

If you don’t want to update your password too many times, you can update the frequency of the expiration to 90 days for example:

Or you can completely disable the expiration by pushing the max value for expiration date to 99999 days:

Question ? Contact