Recovering deleted files

Today I accidentally deleted all files in my /home/Documents directory and had to recover some of them.
Luckily, there’s an easy way with the extundelete program.

First of all, umount the target partition:
sudo umount /home

Note: if you get the ‘device is busy’ message, you can add the lazy option:
sudo umount -l /home

Then install extundelete (if you don’t have it already):
sudo apt-get install extundelete

Now recover the files that were deleted from that directory, for which you need to specify the mount point (use df -h for that):
sudo extundelete --restore-directory /home/Documents /dev/sda5

This will create a RECOVERED_FILES directory with all the file structure of the deleted directory, containing the files that could be restored.

Finally remount the target partition:
sudo mount -o remount,rw /dev/sda5 /home

That’s it!

How to check processes bandwidth consumption

With nethogs you can monitor network bandwidth usage on a per-process basis. Just install it from source to avoid a socket error:
wget -c https://github.com/raboof/nethogs/archive/v0.8.5.tar.gz
tar xf v0.8.5.tar.gz
cd ./nethogs-0.8.5/
sudo apt-get install libncurses5-dev libpcap-dev
make && sudo make install

And execute it as sudo, pointing to the network interface you wish to monitor, for instance:
sudo nethogs wlan0

nethog

Enabling SSL in Nginx

Last year I quickly commented how to enable SSL on Apache. Now I’ll do the same for Nginx, which has been my primary HTTP server choice since then, BTW.

First, create the certificates:
cd /etc/nginx/
sudo openssl genrsa -out localhost.key 1024
sudo openssl req -new -key localhost.key -x509 -out localhost.crt
sudo chmod 600 localhost.*

Then edit /etc/nginx/sites-available/default and put the important parts:
server {
listen 443 ssl default_server;
ssl_certificate /etc/nginx/ssl/localhost.crt;
ssl_certificate_key /etc/nginx/ssl/localhost.key;
}

Finally reload Nginx:
sudo service nginx reload

That’s it!

PS: These tips are for development pruposes. In production you’ll need a chained certificate (aka certificate bundle).

Enabling SSL in Apache

Recently I had to do this task twice in the last month at different localhosts, so I’m writing this post as a personal note (all this blog is meant to be a sort of memo book, though).

This mini-guide is heavily based on pradeepchhetri’s answer on stackexchange and this tutorial from 2012, so credit goes to them.

First, create the certificates:
cd /etc/apache2/
sudo openssl genrsa -out localhost.key 1024
sudo openssl req -new -key localhost.key -x509 -out localhost.crt
sudo chmod 600 localhost.*

Then edit /etc/apache2/sites-available/default-ssl and put the important parts:
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/localhost.crt
SSLCertificateKeyFile /etc/apache2/localhost.key
</VirtualHost>

Finally activate SSL and reload Apache:
sudo a2enmod ssl
sudo a2ensite default-ssl
sudo service apache2 reload

That’s it!

PS: These tips are for development pruposes. In production you’ll need a chained certificate (aka certificate bundle).