Send system emails using gmail as smtp server

I wrote before about sending system emails using sendmail as a smarthost. Here is an alternative approach using Gmail SMTP servers — often simpler to set up for home servers and small VPS.

The software that makes this easy is called ssmtp. It is a lightweight MTA that forwards mail to a configured SMTP relay, perfect for this use case.

Installation and configuration

Install ssmtp:

apt-get install ssmtp

Edit /etc/ssmtp/ssmtp.conf:

root=myAccount@gmail.com
mailhub=smtp.gmail.com:587
hostname=myHostname.com
UseSTARTTLS=YES
AuthUser=myAccount
AuthPass=myPassword
FromLineOverride=YES

And set your address in /etc/ssmtp/revaliases:

root:myAccount@gmail.com:smtp.gmail.com:587

That is it. From now on, system emails are delivered through your Gmail account. If you use two-factor authentication, generate an app-specific password instead of using your main password.

Enjoy!

How to shred/wipe disks/partitions

When you delete a file normally, the data stays on the disk — the filesystem just marks the space as available. The data can be recovered with the right tools. If you need to make sure it is really gone, you can overwrite it securely.

shred -vzf -n 5 /dev/sdb

The -v flag shows progress, -z adds a final overwrite with zeros to hide the fact that shredding took place, -n specifies the number of passes (5 in this example), and the device is the disk or partition you want to wipe.

Be careful with this command — there is no undo. Double-check the device name before running it.

Shredding a single file

If you only need to destroy a specific file rather than an entire disk, use shred on a file directly:

shred -vzu sensitive-file.pdf

The -u flag tells shred to delete the file after overwriting it. Without -u the file remains in place but with its content overwritten.

Wiping with dd for more control

If you want to see exactly what is being written and you know the disk size, dd gives you more control:

sudo dd if=/dev/urandom of=/dev/sdb bs=4096 status=progress

This writes random data in 4K blocks and shows a progress indicator. Replace urandom with zero (if=/dev/zero) for a faster but less thorough wipe. The trade-off is that a single zero pass is detectable — someone with specialised equipment can still read the residual magnetic signature.

Verifying the wipe

After wiping a disk, you can verify that no readable data remains:

sudo xxd /dev/sdb | head

If the output shows consistent patterns (all zeros or all random bytes), the wipe was successful. If you see fragments of old filesystem structures, you might need another pass.

Note on SSDs

Shred relies on overwriting the same physical sectors multiple times. On modern SSDs, wear-levelling and TRIM make this unreliable — the drive may remap sectors and leave old data in place. For SSDs, use the ATA Secure Erase command built into the drive firmware instead. Most Linux distributions include the hdparm or nvme-cli tools for this:

sudo hdparm --user-master u --security-set-pass p /dev/sdb
sudo hdparm --user-master u --security-erase p /dev/sdb

Or for NVMe drives:

sudo nvme format /dev/nvme0n1 -s1

The best defence against needing to wipe a disk securely is full-disk encryption. If the drive was encrypted from day one, a single pass of zeros is enough to make the data unrecoverable — the encryption keys are gone, and the rest is ciphertext.

Enjoy!

Root HTC Wildfire (Android 2.2.1), install Cyanogenmod 7 and fix GPS

I have been using my HTC Wildfire for quite some time now. It is not a bad phone but it is somewhat limited, mainly in memory and speed. Plus, I really wanted to experiment and see what a custom ROM could do.

From my research, SuperOneClick is the most popular tool for rooting the Wildfire. You can find it on the XDA Developers forum — it makes the process very straightforward.

Once rooted, install ROM Manager from the Market and flash a custom recovery. Then download CyanogenMod 7, copy it to your SD card, boot into recovery, and install the zip.

1. Root with SuperOneClick
2. Install ROM Manager
3. Flash ClockworkMod recovery
4. Download CyanogenMod 7
5. Copy to SD card
6. Boot into recovery (Volume Down + Power)
7. Install zip from SD card
8. Reboot

After installing CyanogenMod, if your GPS is not working (a known issue), flash the appropriate GPS fix for your region from the XDA forums.

The difference in performance is night and day. The Wildfire becomes a much more usable device. Give it a try!

Formatting a partition from command line

When you need to format a partition from the command line, a few commands are all you need. Here’s the typical workflow.

First, create the filesystem:

mkfs.ext4 /dev/sdxy

If you want to reserve less space for the root user:

tune2fs -m 0 /dev/sdxy

Check the filesystem for errors before mounting:

fsck.ext4 -fy /dev/sdxy

Then mount it where you need it:

mount /dev/sdxy /wherever/I/want

Replace /dev/sdxy with your actual partition and /wherever/I/want with your mount point.

Enjoy!

Drush intro – Drupal

Drush is a command-line shell interface for Drupal. It lets you do almost anything you would do through the Drupal admin interface — enabling modules, clearing caches, running cron, backing up the site — all from the terminal.

Installation

The preferred way to install Drush is via the official PEAR channel, but it can also be installed manually on a shared server.

Backup and restore

archive-dump backs up the codebase, files, and database into a single file:

drush archive-dump
drush archive-restore

Common commands

drush pm-download 
drush pm-enable 
drush pm-disable 
drush cc all
drush cron
drush sql-dump
drush uli

Enjoy!

XBMC 11 (aka Eden) stable release download available

XBMC Media Center (formerly Xbox Media Center) is a free and open source cross-platform media centre and HTPC application. I have been using it for just a few months but I never tried any media centre as good and configurable as this one.

Version 11, codenamed “Eden”, was a significant release. It introduced a new skin engine that made it easier for designers to create custom interfaces. Library management was overhauled — scraping metadata for movies and TV shows became more accurate and faster. Hardware acceleration was improved, making HD playback smoother on a wider range of hardware.

Eden also added support for more audio formats, better UPnP streaming, and an improved add-on system. The PVR (live TV) integration, while still marked as a beta feature, was a promising addition for those looking to replace their set-top box entirely.

If you have a home theatre PC or even just a computer connected to your TV, XBMC turns it into a proper media centre — movies, TV shows, music, pictures, all with a beautiful interface designed for a remote control. It supports almost every file format you can throw at it and runs on Windows, Mac OS X, Linux, and even the original Xbox.

Download your free version and give it a try!

Download the free version and give it a try!

Give it a try!

Accelerate downloads with lftp

lftp is a versatile command-line file transfer tool. What makes it stand out is its ability to open multiple connections for a single download, which can significantly improve transfer speeds on servers that limit bandwidth per connection.

Parallel downloads with pget

The command I use most is pget with the -n option for parallel connections:

lftp -e 'pget -n 3 http://example.com/file.zip'

If the server limits each connection to 100KB/s, three connections will give you roughly 300KB/s.

Resuming interrupted downloads

If a download fails halfway through, pget continues from where it left off when you run the same command again:

lftp -e 'pget -c -n 3 http://example.com/file.zip'

Mirroring directories

lftp can mirror entire directory structures:

lftp -e 'mirror --parallel=3 /remote/path /local/path'

Queue management

lftp http://example.com
queue pget file1.zip
queue pget file2.zip
run

Enjoy!

PHP UK Conference 2012 slides – London

As mentioned in the last post, I was going to go to the PHP Conference in London.
Well, I have been! :-)
It was the first time for me but was exactly as expected. Very interesting, entertaining, and absolutely inspiring…
Unfortunately the slides are not always easy to find as I haven’t found a single place where to find them all.
Here I will list all slides (or resources in general) found about a particular talk.
If you know where to find some of those marked as “not found yet” don’t hesitate to write to andrea [at] opensourceisbetter.com or leave a comment.

A look at PHP in 2012
(Rasmus Lerdorf)
Slides

Big Data web – Big Data science – Big Data mining
(James Littlejohn)
Slides

Powering your website with real-time data
(Bert Van Hauwaert)
Slides

The journey towards Continuous Integration
(Sebastian Marek)
Slides

Data abstraction in large web applications
(Brandon Savage)
Slides

Develop & deploy using hybrid cloud strategies
(Thijs Feryn)
Slides

PHP 5.4: the new bits
(Davey Shafik)
Slides

Creative Coding – why “doing nothing” doesn’t mean you’re not working
(June Henriksen)
Slides

Security audits as an integral part of PHP application development
(Sijmen Ruwhof)
Slides

To a thousand servers and beyond: scaling a massive PHP application
(Nikolay Bachiyski)
Slides

Distribute the workload
(Helgi Þorbjörnsson)
Slides – Day 1Slides – Day 2

Profiling PHP applications
(Derick Rethans)
Resources

Scaling communication with Continuous Integration
(LB Denker)
Slides

Building and deploying applications with Phing
(Michiel Rook)
Slides

Teaching your machine to find fraudsters
(Ian Barber)
Slides

Try {getting people to come to a talk about exceptions}
(Ed Van Beinum)
Slides

Challenges at scale: extreme data and platforms at eBay
(Hugh Williams)
(not found yet)

Masterizing PHP Data Structure 102
(Patrick Allaert)
Slides

Monitoring your back-end for speed and profit
(Andy ‘Bob’ Brockhurst)
Resources

Open source search: an analysis
(Justin Finkelstein)
Slides

Cheat your way with UX
(Stephanie Troeth)
Slides

MySQL update
(Dave Stokes)
(not found yet)

Recognizing smelly code
(Harrie Verveer)
Slides – PDF file

HTML5 for PHP developers
(Andrew Betts)
(not found yet)

Introduction: MongoDB with PHP
(Derick Rethans)
Resources

PHP under the hood
(Johannes Schlüter)
Slides

The Misguided Manager
(Zoë Slattery)
Slides

Hope you find this useful. :-)
Enjoy!