Archive for the ‘Linux’ Category

Personal SSL Certs PHP Curl

Thursday, December 17th, 2009

Needed to connect to a gateway that used personal pkcs12 (p12) SSL certificates and could not find any decent docs online. The whole SSL thing can be confusing at the best of times so I thought I would note down my experience.

PHP does not like pkcs12 certificates so you need to turn them into pem

openssl pkcs12 -in cert-they-gave-you.p12 -out key.pem -nocerts

openssl pkcs12 -in cert-they-gave-you.p12 -out cert.pem -clcerts -nokeys

If they gave you a password and one is requested here use that.

test at command line with

curl –cert cert.pem –key key.pem https://url-to-service

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://url-to-service');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_SSLCERT, getcwd().'/certs/cert.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'password');
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLKEY, getcwd().'/certs/key.pem');

/**

Word press will not allow me to post the execution command snippet so you need to look it up
**/
echo $result;
curl_close($ch);

PHP 5.2.3
cURL Information libcurl/7.18.2 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.10
Ubuntu 9.04

Skype Video on Linux

Wednesday, December 16th, 2009

I recently set up an Ubuntu 9.10 machine for a customer that wanted to use it for Skype, Web and Email. In my experience Ubuntu is a great desktop in these instances.

This time however I hit a real speed bump with the Video in Skype. Every time the user tried to initiate a Video call Skype would close. This is strange because I have used it before with no problem.

The solution is to turn off video calls by default in the Skype settings, wait for the other person to initiate a video call, click on the video camera icon at the bottom of the picture, set the screen to double size and then turn on your video through the same menu. Not ideal I agree but good enough.

Cloning an Ubuntu Server

Sunday, November 29th, 2009

I recently needed to clone an Ubuntu 9.04 server to another machine for one of my customers thinking that it would be simple. It wasnt. But here’s how I got it to work.

Firstly from searching the net it would seem that there are a lot of different ways of doing this. dd, ddrescue, partimage, ping. They did not work for me for various reasons. I ended up using the tar method.

You will need a LiveCD that you can boot on the machine that you are copying to. And your original Install CD of Ubuntu. Because my original was server which is not a live CD I used Minibuntu. You will also need a USB drive that is big enough to hold the image.

First log in to the machine that you are copying. cd to /. sudo su.

tar -cvpzf backup.tar.gz -–exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media /

Copy the backup.tar.gz to  a USB drive attached to the machine.

mkdir /mnt/usb
mount /dev/sdb1 /mnt/usb

(sdb1 may be different on your machine dmesg | grep -i “SCSI” should list it with sd?)

cp /backup.tar.gz /mnt/usb

Next install a basic Ubuntu Server on the new machine.  Reboot and plug in the USB drive. Mount it as before and copy the backup to the root directory of the new machine. Then extract the archive.

sudo tar -xvpzf backup.tar.gz -C /

Reboot but this time to the LiveCD. If you use Mini Buntu command line LiveCD you need to select another terminal after boot. Ctrl-Alt-F2.

Since you are running from a live cd you need to mount the HDD of the machine. Same way as mounting USB.

Then you need to install grub again to get the boot stuff correct.

sudo grub

will bring up the grub prompt if not

sudo apt-get update

and

sudo apt-get install grub

. Note that you will need the internet for that. If you can not connect to the net just make sure that the LiveCD you use has grub on it. Mine didnt.

at the prompt

find /boot/grub/stage1
root (hd0,0)

(Replace with whatever the find returned)

setup (hd0) 

(Again replace the hd0 with the results of the find)

quit

Now we need to fix up the UUIDs. These are identifiers from the HDD which you have just overwritten. To get the UUID of your drives

ls -l /dev/disk/by-uuid/

or

sudo vol_id /dev/sda1

Note them down and for which partition root and swap. Check them and then check them again.

now change the grub loader and fstab.

sudo nano /mn/etc/fstab

.

update the UUIDs

sudo nano /boot/grub/menu.lst

update the UUIDs

Reboot and you should be a go.

You may get an issue with networking. Because a new card is recognized the ethernet adapter name on my system changed from eth0 to eth1. I worked this out by dmesg | grep eth0. edit the /etc/network/interfaces file and change all instances of eth0 to eth1.

References

https://help.ubuntu.com/community/BackupYourSystem/TAR
http://linux.byexamples.com/archives/321/fstab-with-uuid/
http://stringofthoughts.wordpress.com/2009/05/25/grub-error-15-debianubuntu/