Show which process/program is listening to what port using netstat and lsof

lsof -Pnl +M -i4
lsof -Pnl +M -i6


netstat -tulpn
netstat -npl

There are obviously a number of ways to accomplish this, but these variations will cover a lot of ground. You can also combine this with grep to filter out things you don’t need to see, or to only include specific processes and/or ports.

See post from @geek1968 on Instagram

Filmjölk, Google Translate och Machine Learning

Det pratas mycket om machine learning och deep learning inom IT.

Ibland har man lite otur när man tänker 🙄🤔

Deep learning i sitt esse hos Google Translate:

Filmjölk -> Sour milk
Sour milk -> Surmjölk
Surmjölk -> Sour
Sour -> Sur

Vilket kanske mer poängterar att vi ibland måste tänka lite extra när vi uttrycker oss i “självklara termer”.

Saker som vi upplever som självklarheter kan lätt misstolkas av mottagaren och ge helt andra signaler än de vi tänkt oss.

Apache goodies for WordPress security

The list of things to do to harden a WordPress site with Apache is long, but some things that could be done include:

FileETag None                                                                                                                       
<Files wp-config.php>                                                                                                               
    Require all denied                                                                                                              
<Files xmlrpc.php>                                                                                                                  
    Require all denied                                                                                                              
<LocationMatch "/wp-content/uploads/.*(?i)\.php$">                                                                                  
    Require all denied                                                                                                              

SSH tunnel to use other mailserver than localhost

Because I have a lot of virtual machines, laptops, work environments, and so on, I never seem to find the time to setup SMTP authentication everywhere. I typically use Linux for everything except hardcore gaming, so it’s only natural that I have some sort of mail server installed like Postfix. The problem in using that mail server to send e-mail is that I also quite often have dynamic IP addresses on these machines, which doesn’t work well with “e-mail protection” (well..) like SPF.

So instead of making my life very complicated, I have a trusted server on the Internet through which I send e-mail.

If you were looking for something fancy in this article, you can move along now, there’s nothing to see 🙂

To make all my Linux work instances believe they’re talking to an SMTP server locally, I simply setup a tunnel from the given Linux instance to this trusted server on the Internet using the ever so versatile OpenSSH / SSH. I know there are a lot of ways to do this, but this is what works for me:

Local machine or “where I work”

I have a private/public key keypair on all of these machines. The public key is placed in the /root/.ssh/authorized_keys file on the trusted server that is running the mail server.

On this machine, as root, I setup a tunnel that looks like this:

ssh -N -L 25:localhost:25 -p 2222

This will create a tunnel from “localhost” port 25 (where I work) to “localhost” port 25 on It will connect the end point of the tunnel to on port 2222. If the server is running an SSH server on its standard port (22), you can remove the “-p 2222” part.

Mail server

On this server, I only need to put the public key from the local machine “where I work” into /root/.ssh/authorized_keys to allow the tunnel to come up.

When I access port 25 on my local machine “where I work”, it will be sent through the tunnel and then attempt to access “localhost” port 25 on the mail server. The mail server software, Postfix in my case, will never know this connection did not actually originate from “inside” the machine, but rather through the tunnel.

Closing thoughts

You can (obviously) make this somewhat more automated with tools like AutoSSH, init scripts, and what not. The above only intends to show how uncomplicated it is to create useful SSH/SMTP tunnels 🙂


Securely overwrite unused space on Windows 7, 8, and 10

Overwriting “unused space” on Windows 7, Windows 8, and Windows 10 is quite simple. Open a “Command Prompt” window, and type:

cipher /w:DD

Where “DD” is your drive without a suffix, e.g.

cipher /w:C

to wipe unused space on drive C.

Why is this useful? Well, when you delete files from most modern operating systems, they aren’t really erased, even after you “Empty the trash”. The file system on your drive is simply updated to indicate that the space previously occupied by the file is now available. But the file data is still there. Overwriting such “unused space” with nonsense/garbage data will make it harder to recover the file data.

Setting PHP.INI path (or file) for PHP CLI shell scripts

Running a PHP script from the command-line, or CLI, is quite useful at times and is often used to perform some automated task, like a CRON cleanup script, to send out reminders, etc.

It’s common that these CLI scripts need some, but possibly not all, settings that are similar to the main application’s. I may, for example want to include the database configuration settings shared with the main application. So I often create a separate php.ini file for this purpose.

Running /usr/bin/php -c /my/very/special/path cronScript.php is simple enough, but what if I want to be able to create an “executable” PHP shell script? The obvious answer would be something like:

#!/usr/bin/php -c /my/very/special/path

at the top of the .php file, followed by my PHP code, right? Except that may not do what you want. I could not get the PHP interpreter to load anything in /my/very/special/path by using the above construct, even if it works from the actual command-line. After banging my head against the wall for a while, this turns out to work for these “shell scripts”:

#!/usr/bin/php -c=/my/very/special/path

Note the use of the = (equal) sign between the -c and the path (or file).

Carry on.