SSL Private Key file recovery

Filed Under (Sysadmin) by Amandine on 08-11-2012

I did something very bad today. I’m ashamed but I’ll tell you because it was interesting.

I had a SSL certificate to renew. I just got the new my.server.crt, and I just had to replace the old one with this new one. Nothing complicated, but the files on the server were named badly, so I started putting everything back in order :

  • my.server.csr for the Certificate Signing Request
  • my.server.crt for the certificate itself
  • my.server.key for the private key

During this basic operation of renaming files, I failed. My brain wasn’t there anymore for a moment, and I renamed 2 files to the same name. Read the rest of this entry »

URL redirections

Filed Under (Sysadmin) by Amandine on 01-07-2012

URL redirections were obvious for me. That was before my husband asked me about the differences between redirecting within htaccess, php, or any other way. Sure I knew how to do it, but I never wondered about the differences between all the ways. So while understanding those will be my goal today, my favorite SEO expert (aka my husband) will explain you how to use the redirections in a proper SEO way (in french for now, soon translated).

Read the rest of this entry »

Sticky bit

Filed Under (Sysadmin) by Amandine on 04-05-2012

I recently had an interview in which I got asked about the sticky bit. Honnestly, I can’t remember what this is. Of course I know it has something to do with access rights on a Linux filesystem, and I remember having checked Wikipedia or man at least 10 times about it but it just doesn’t stick in my head. So I’ll try to dig a little in its behaviour to make it stay up there !

How to set it

chmod +t somefile-or-dir
chmod 1xxx somefile-or-dir

Let’s play
I created 2 directories and 2 files, one with sticky bit set and one without for each type:
Read the rest of this entry »

Apache2 Rewritemap

Filed Under (Sysadmin) by Amandine on 16-02-2011

I love apache mod_rewrite. I often fight with it, but if you really want it you can do whatever you want. This time I wanted to find a way to call a file named after the called subdomain. I have a website called, and there is some subdomains like, and so on for each part of the website (That’s a SEO consideration in the beginning). I have only one virtual host for that website because I find it easier to manage like that, and I didn’t want to put the logic in the files for some reasons (and because working with rewrite rules is fun).

This is what I want :

  • you call -> you get
  • -> index.php?page=somepage
  • -> index.php?page=somepage-the-beatles
  • -> index.php?page=somepage-blahblah

The page parameter will in fact call a different page with name “somepage-blahblah.html”, and I wanted it to work for every single subdomain (if it doesn’t exist it will anyway be redirected to www home page)

The closest way I found was to use %{HTTP_HOST} in my rewriterule :

RewriteCond %{HTTP_HOST} !^www\.yellow-sub\.net$ [NC]
RewriteRule ^/$ /index.php?page=somepage-%{HTTP_HOST} [L]

Read the rest of this entry »

How to resolv .42 domains

Filed Under (Sysadmin) by Amandine on 29-12-2010

I’m sure you heard of the new unofficial domain registry 42registry, who let you register domains like something.42. If you didn’t, go on there website and read, cause I found this very interesting, funny, and it made me want to try :)

So, after registering sysadmandine.42 domain name, I tried to surf on it. But I didn’t want to spend time to configure a secured but open bind on one of my servers, so I opted for the easy way : my local computer is on Ubuntu, Ubuntu is perfectly able to provide me a bind, so let’s go :

$ sudo aptitude install bind9

Read the rest of this entry »

Add disk space to a .img disk image (for use with xen for example)

Filed Under (Sysadmin) by Amandine on 13-08-2010

Sometimes, you need more space on a virtual machine disk than you thought in the beginning. Hopefully, if your domU disk is in a .img file, you can do it quite easily (you can do it easily with lvm partition too, even if it’s a different method). Here’s how to do it, as root of course :

– Check your partitions in your domU :

df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda2             10G  706M  8.8G   8% /
varrun                2.1G   44K  2.1G   1% /var/run
varlock               2.1G     0  2.1G   0% /var/lock
udev                  2.1G   16K  2.1G   1% /dev
devshm                2.1G     0  2.1G   0% /dev/shm

– create empty file of the size we want to add : (10gb here)

dd if=/dev/zero of=/xen/temp_expand bs=1024k count=10000

Read the rest of this entry »

Apache2 mod_rewrite and %{REQUEST_FILENAME}

Filed Under (Sysadmin, Tips) by Amandine on 23-02-2010

I’m trying to develop a new website to increase my php object oriented skills. For this new website, I want every request for any url that doesn’t match a actual file on the disk to be redirected to index.php (to handle parameters in fact). Easy with apache2 rewrite rules :

         RewriteCond %{REQUEST_FILENAME} !-f
         RewriteCond %{REQUEST_FILENAME} !-d
         RewriteCond %{REQUEST_FILENAME} !-l                                                                                                                                                                              
         RewriteRule ^/(.*)$         /index.php?rt=$1 [L,QSA]

This means : if the requested file is not a real file, and isn’t a directory, and isn’t a symlink, then redirect to index.php.

I was really surprised to discover that it doesn’t work. Though, everybody seems to use this syntax ! I checked my apache version : Apache/2.2.9 (Debian), nothing special with this one I guess.
To understand what Apache was doing with my rewrites, I activated the rewrite log :

         RewriteLog /var/log/apache2/rewrite.log                                                                                                                                                                      
         RewriteLogLevel 5

Read the rest of this entry »

My top 20 linux favourite commands

Filed Under (Sysadmin) by Amandine on 12-02-2010

Here’s my linux favourite commands, by type :

1. egrep : aaah… if I had to keep only one, this would be the one I’d choose… can’t spend 10 minutes without using it.
2. sed : because I always need to replace something by something else 10 times on each line in huge files
3. xargs : helps me avoid the for loop, shorter to write, easier to remember and understand when you find it in history
4. awk : for me the most difficult one to use, but I so know that it can do just what I want that I always take the time.
Read the rest of this entry »

htpasswd encryption

Filed Under (Sysadmin) by Amandine on 12-02-2010

I was wondering how crypt does the encryption of passwords. Once I needed to compare two .htpasswd files, I was quite sure that both had the same password for the same user, but the encrypted strings didn’t match. I tried to regenerate the encrypted string several times, and here’s what I got :

$ htpasswd -nb someuser somepwd
$ htpasswd -nb someuser somepwd
$ htpasswd -nb someuser somepwd
$ htpasswd -nb someuser somepwd
$ htpasswd -nb someuser somepwd

Read the rest of this entry »

shell scripting : seq prints a sequence of numbers

Filed Under (bash) by Amandine on 08-02-2010

I often need to execute a loop x times, and I’m just too lazy to write a i++ style algorithm… the command seq is made for me :)

Easy to use, just does what I need from it, here’s a extract from the man page :

       seq - print a sequence of numbers

       seq [OPTION]... LAST
       seq [OPTION]... FIRST LAST

Read the rest of this entry »