Category Archives: Ubuntu/Debian

OpenDNS Server

Google’s Public DNS Servers in case you need a public uncensored DNS server you can use these:

8.8.8.8
8.8.4.4

Here is my resolv.conf with the open DNS servers:

nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 94.75.228.2
nameserver 80.237.196.2

The last two are also open DNS Servers but not from Google.

frequently used SSL commands

generate a new private key and matching Certificate Signing Request (eg to send to a commercial CA)
openssl req -out MYCSR.csr -pubkey -new -keyout MYKEY.key

-add -nodes to create an unencrypted private key
-add -config if your config file has not been set in the environment

decrypt private key

openssl rsa -in MYKEY.key >> MYKEY-NOCRYPT.key

generate a certificate siging request for an existing private key

openssl req -out MYCSR.csr -key MYKEY.key -new

generate a certificate signing request based on an existing x509 certificate

openssl x509 -x509toreq -in MYCRT.crt -out MYCSR.csr -signkey MYKEY.key

create self-signed certificate (can be used to sign other certificates)

openssl req -x509 -new -out MYCERT.crt -keyout MYKEY.key -days 365

sign a Certificate Signing Request
openssl x509 -req -in MYCSR.csr -CA MY-CA-CERT.crt -CAkey MY-CA-KEY.key -CAcreateserial -out MYCERT.crt -days 365

-days has to be less than the validity of the CA certificate

convert DER (.crt .cer .der) to PEM

openssl x509 -inform der -in MYCERT.cer -out MYCERT.pem

convert PEM to DER

openssl x509 -outform der -in MYCERT.pem -out MYCERT.der

convert PKCS#12 (.pfx .p12) to PEM containing both private key and certificates

openssl pkcs12 -in KEYSTORE.pfx -out KEYSTORE.pem -nodes

add -nocerts for private key only; add -nokeys for certificates only

convert (add) a seperate key and certificate to a new keystore of type PKCS#12

openssl pkcs12 -export -in MYCERT.crt -inkey MYKEY.key -out KEYSTORE.p12 -name "tomcat"
check a private key

openssl rsa -in MYKEY.key -check

add -noout to not disclose the key

check a Certificate Signing Request

openssl req -text -noout -verify -in MYCSR.csr

check a certificate

openssl x509 -in MYCERT.crt -text -noout
check a PKCS#12 keystore

openssl pkcs12 -info -in KEYSTORE.p12

check a trust chain of a certificate

openssl verify -CAfile MYCHAINFILE.pem -verbose MYCERT.crt

-to check for server usage: -purpose sslserver
-to check for client usage: -purpose sslient

Mount a Linux NFS Share on Windows 7

First you need to install the windows nfs client. Go to

Control PanelAll Control Panel ItemsPrograms and Features

Then click on Turn Windows features on or off then select NFS Services Client for NFS. After the installation start a dos box or power shell. And enter the following command to mount the share backup on server 192.168.1.1 and assign the drive letter k:

mount \\192.168.1.1\backup k:

Example: mount [options] \\nfs-server\unc-nameshare-name [drive letter]

Extracting a Database From a mysqldump File

Restoring a single database from a full dump is pretty easy, using the mysql command line client’s –one-database option:

mysql -u root -p --one-database db_to_restore < fulldump.sql

But what if you don’t want to restore the database, you just want to extract it out of the dump file? Well, that happens to be easy as well, thanks to the magic of sed:

sed -n '/^-- Current Database: `test`/,/^-- Current Database: `/p' fulldump.sql > test.sql

You just need to change “test” to be the name of the database you want extracted. Or you can use this shell script:

Download mysqldumpsplitter

Usage:

$>sh MyDumpSplitter.sh
Usage: sh MyDumpSplitter.sh DUMP-FILE-NAME — Extract all tables as a separate file from dump.
sh MyDumpSplitter.sh DUMP-FILE-NAME TABLE-NAME — Extract single table from dump.
sh MyDumpSplitter.sh DUMP-FILE-NAME -S TABLE-NAME-REGEXP – Extract tables from dump for specified regular expression.

Further instructions for using this script can be found here:

Mysql dump-shell script

Upgrading Debian Lenny to Squeeze

Upgrade to Debian Squeeze if you have some Linux experience this upgrade should be fairly straight forward. Please read everything and do not skip steps unless you know what you are doing. You may be left with a system that will not boot. Please also consult the official Debian upgrade guide if you run into any problems or conflicts:


Debian upgrade guide


Create a list of installed packages and check the list for deinstalled packages this is an optional step to make sure you have a clean system:

uninstall=$(dpkg --get-selections > /root/package.list.lenny ; cat /root/package.list.lenny | grep deinstall |awk {'print $'1}) ; aptitude purge $uninstall

Check for half installed packages:

dpkg --audit

Remove Backuports and APT Pinnings Check for non debian sources and change them to the squeeze repo if available

Replace lenny entries with squeeze replace volitile with squeeze-updates:

Also make sure to add non-free and contrib in case your server needs the firmware-linux-nonfree package. This is a example sources list for squeeze if you live in Germany:

############################################################
deb http://ftp.hosteurope.de/pub/linux/debian/ squeeze main contrib non-free
deb-src http://ftp.hosteurope.de/pub/linux/debian/ squeeze main contrib non-free

deb http://security.debian.org/ squeeze/updates main contrib non-free
deb-src http://security.debian.org/ squeeze/updates main contrib non-free

deb http://ftp.hosteurope.de/pub/linux/debian/ squeeze-updates main contrib non-free
deb-src http://ftp.hosteurope.de/pub/linux/debian/ squeeze-updates main contrib non-free
#############################################################

Update sources:

apt-get update

Check to see if you have sufficient disk space:

apt-get -o APT::Get::Trivial-Only=true dist-upgrade

Preform a minimal System Upgrade:

apt-get upgrade

Install the new kernel important otherwise your system may not boot because of the new udev version choose your kernel:

apt-get install linux-image-2.6-amd64

This would install the 64bit Debian Kernel

Check the Kernel Install:

dpkg -l "linux-image*" | grep ^ii

Upgrade udev:

apt-get install udev

If you see any firmware warnings make sure to install the firmware-linux-nonfree or the firmware-linux package before you reboot:

apt-get install firmware-linux-nonfree

or

apt-get install firmware-linux

Preform a system Upgrade or full upgrade:

apt-get dist-upgrade

Change init scripts to inssrv this is normally done automatically:

dpkg-reconfigure sysv-rc

Reboot the system

After first reboot Install Grub 2 to MBR:

upgrade-from-grub-legacy

rm -f /boot/grub/menu.lst*

Clean up and remove downloaded packages removing the downloaded packages is a optional step:

apt-get autoremove

rm -f /var/cache/apt/archives/*.deb

This step is also optional remove obsolete packages with deborphan helps to keep your system clean:

install deborphan:

apt-get install deborphan

Use deborphan to remove obsolete packages check the list first:

deborphan --guess-all

Then remove the obsolete packages:

deborphan --guess-all | xargs aptitude -y purge

Thats it you should have a clean system running Debian Squeeze

Ubuntu / Debian Linux Regenerate SSH Host Keys

If you need to regenerate your SSH Host Keys do the following.

1. delete your old keys

rm /etc/ssh/ssh_host_*

2. reconfigure the ssh server

dpkg-reconfigure openssh-server

That’s it now you can update you known_hosts file when you connect next time. If you use strict checking which you should you will need to delete the key from you known_hosts file in you home directory. Or you will not be able to connect.