Matteo Mattei

Hello, my name is Matteo Mattei and this is my personal website. I am computer engineer with a long experience in Linux system administration and web software development.

linkedin rss twitter google+ github facebook

Shrink Ext4 partition on VMware player

VMWARE Few days ago I spent some times trying to shrink my Ubuntu 11.04 appliance with root partition formatted with EXT4 filesystem.

The main problem is that the current VMware tools (8.4.6, build-385536) does not support the ext4 shrink. If you run sudo vmware-toolbox, your root partition is formatted in ext4 and you try to execute the shrink, an error message like the following could appear.


Anyway there is a trick to streamline the final vmdk size. Run this command within a shell into the guest system:

sudo dd if=/dev/zero of=/zero.raw bs=20480
rm -f /zero.raw

Then, shutdown the virtual image and download the vdiskmanager tool from VMware website.

Now run the vmware-vdiskmanager with the -k parameter:

vmware-diskmanager -k /path/to/image.vmdk

This operation will take a while, but at the end you will get a considerable smaller vmdk image file.

How to implement MAC_X919 algorithm in Python

Today with my friend Nicola, we were looking in Internet for the implementation of the X9.19 algorithm in Python. Unfortunately we didn’t find it anywhere, so we made it ourself:

How to clone MySQL database schema in PHP


For my client I needed to create a PHP script that can export a full MySQL database schema in another database. This script also need to keep and set constraints.

You only need to configure $DB_SRC_* and $DB_DST_* variables to fit your environment.

Here below you can find the code I created for this purpose:

Update 2016-10-14: The code below has been rewritten using PHP mysqli driver (thanks to Richard Maurer).

Virtual users on vsftpd

VSFTPD logo I am usually to configure vsftp on web servers to allow FTP access based on domains. Few days ago my client asked me to create multiple FTP users for a single domain every one with a different root folder into that domain.

This is my usual configuration of my /etc/vsftpd.conf

ftpd_banner=Welcome to my private FTP service.

and this is my /etc/pam.d/vsftpd

auth required pwdfile /etc/ftpd.passwd
account required

The first time I have created the file /etc/ftpd.passwd in this way:

htpasswd -c -d -b /etc/ftpd.passwd <password>

For the next users simply avoid the “-c” parameter:

htpasswd -d -b /etc/ftpd.passwd <password>

With this simple configuration all users have these credentials:

  • host:
  • username:
  • password: password
  • port: 21
  • Root folder: /var/www/domain1/

Now the point is: how can we create multiple users for a single domain each one with a different root folder? The answer is pretty simple, follow me!

Create the folder /var/www/users and add the following line at the end of /etc/vsftpd.conf


Inside the folder /var/www/users create a file for each virtual user (for example the user containing a line with the root directory for that user:

echo "local_root=/var/www/" > /var/www/users/

Now add the new user/password in /etc/ftpd.passwd as usual:

htpasswd -d -b /etc/ftpd.passwd <password>

Restart vsftpd server and test your new configuration!

How to use google apps in WordPress on Bluehost

In these days I spent a lot of time looking for a solution of changing the admin email address in Bluehost and I found a working solution! The problem is that Bluehost uses Exim as mail server that is configured to require a valid and registered email address.

This is my scenario:

  • Some domains with mx record pointed to google apps (I will take as example).
  • No mailbox created on Bluehost because I have already created some mailboxes with google apps.
  • with as admin email set in Settings -> General inside Bluehost panel.

At this point, every email sent from any comments has this header:

user <>

I want to change it in order to have this address in my comments:

info <>

These are the steps to follow:

  1. Log-in to Bluehost cpanel and go to Mail -> MX Entry. Here select your host (, add these MX records as in the picture below and make sure to set Remote Mail Exchanger:

    MX Google Bluehost

  2. Now the e-mail delivery should just work. However, if you want to change the “From email” field, install the mail from plugin and configure it in this way:
    • Sender Name -> YourName
    • User Name -> info
    • Domain Name ->

    Wordpress Mail From Plugin

That’s all! Now try to post a comment and look at your mailbox.

Update 2013/11/02: As Amanda highlited in the comments below, it’s also necessary to add an account for each address set up in Google Apps. So, go to Bluehost’s cPanel > Email Accounts, then add an account for each address. Adding the addresses to your Bluehost accounts, even though they won’t actually work there, seems to make them trusted, and allows you to send with those addresses.

How to use the european healt card on Archlinux

Since some months the regions are sending the new electronic healt card to the house of the people. These cards are featured with a microchip. The goal to these cards is the same of the previous ones with in addition the possibility to be read by a smart card reader and store, if you want, your electronic healt records.

This let you enter in your region website and look all your medicines taken, your hospital recovers etc…

So let’s start! In this article I will show you how to use this card with the card-reader provided by the Hospital URP with Archlinux and more in general with Linux.

For who does not have the reader, I can suggest to buy the miniLector bit4id directly by the URP of the hospital in your zone because its price is fixed (in Italy) to 4,20 Euros instead of fifteen/twenty Euros that is sold elsewhere.

The first thing to do is to connect the bit4id reader to a free USB port of your pc and type lsusb in a terminal. You should obtain a line like this:

Bus 001 Device 003: ID 072f:90cc Advanced Card Systems, Ltd ACR38 SmartCard Reader

Now install the needing packages:

pacman -Sy ccid pcsclite pcsc-tools pcsc-perl
yaourt -Sy --aur libminilector38u-bit4id libasecnsp11

With root user run pcsc_scan, you should obtain a similar output:

[root@barracuda ~]# pcsc_scan
PC/SC device scanner
V 1.4.17 (c) 2001-2009, Ludovic Rousseau <>
Compiled with PC/SC lite version: 1.6.4
Scanning present readers...
0: ACS ACR 38U-CCID 00 00
Sat Jan  8 17:45:24 2011
  Reader 0: ACS ACR 38U-CCID 00 00
  Card state: Card inserted
  ATR: 3B DF 18 00 81 31 FE 7D 00 6B 15 0C 01 80 01 01 01 43 4E 53 10 31 80 F9

At this point you have to configure Firefox for authentication. Proceed in this way:

  1. Make sure the card reader is connected to the PC and the card is inserted
  2. Run Firefox and select Edit -> Preferences -> Advanced -> Encryption -> Security Devices
  3. Click on Load button and insert EuropeanHealtCard as description and /usr/lib/ as path.
  4. To verify that all works correctly, try to open the link and insert your PIN.

If the authentication is passed, you should see a welcome message.

Now you only need to access to your electronic health records from your region website using your PIN provided during the card activation.

For a guide on configuring the European Healt card with Ubuntu take a look at Andrea Grandi’s blog.

For more informations on Linux and the European Healt Card look at Regione Toscana website.