Downloading a file from a redirecting URL with cURL

The other day I launched an Amazon EC2 instance of OpenSuse 11.3 (I know it’s old) and needed to download a file from SourceForge.

To my surprise, the EC2 instance didn’t carry “wget”, so I had to use cURL.

The thing is that cURL didn’t like the SourceForge download URL as it redirects to another URL.

To make cURL follow redirects execute:

curl -L -o filename URL

How to change the encoding in Ubuntu

Say we wish to change the locale to Spanish UTF-8, what do we need to do?

Step 1: List the available/installed locales in the system:

bash$> locale -a

As you can observe, there is no Spanish locale installed, so we will first need to generate/compile it. The reason why not all locales are installed is to save space. Each locale approximately occupies 50MB,  and since most users only need a few locales, it would be a huge loss of space to install them all..

Step 2: Install the locale Since the locale we want to set is not installed on our system, we need to install it.

bash$> /usr/sbin/locale-gen es_ES.UTF-8

Generating locales… es_ES.UTF-8… done Generation complete.

Note: To know which locales you can generate, take a look at the file /usr/share/i18n/SUPPORTED. I.e:

es_ES.UTF-8 #UTF-8
es_ES # ISO-8859-1

After installing the locale, it should now be available on our system:

bash$> locale -a

Step 3: Update the locale

bash$> /usr/sbin/update-locale LANG=es_ES.UTF-8

This actually only changes the contents of /etc/default/locale. You might as well update that file  manually to change the encoding.

Step 4: Open a new terminal / log in again

bash$> locale
LANG=es_ES.UTF-8 # Default value used in case one of below is not set
LC_CTYPE=”es_ES.UTF-8″ # Character encoding to be used
LC_NUMERIC=”es_ES.UTF-8″ # How to format numbers. I.e decimal separator as dot or comma.
LC_TIME=”es_ES.UTF-8″ # How to format date and time. For example 12 or 24 hour clock
LC_COLLATE=”es_ES.UTF-8″ # Defines how strings are alphabetically sorted.
LC_MONETARY=”es_ES.UTF-8″ # The currency (name and symbol) for the selected country
LC_MESSAGES=”es_ES.UTF-8″ # Language in which the messages (terminal) should be printed
LC_PAPER=”es_ES.UTF-8″ # Paper formats for the country
LC_NAME=”es_ES.UTF-8″ # How names or persons are formatted (firstname lastname)
LC_ADDRESS=”es_ES.UTF-8″ # Format of addresses
LC_TELEPHONE=”es_ES.UTF-8″ # Idem for telephones
LC_MEASUREMENT=”es_ES.UTF-8″ # Defines whether to use pounds, kilograms, etc
LC_IDENTIFICATION=”es_ES.UTF-8″ # Nobody knows!
LC_ALL= # Overrides all the previous!!

Generating a self signed certificate in 2 steps

Step 1

First we create a key-pair in order to be able to digitally sign our own certificate request:

openssl genrsa -rand /path_to_bigfile:/path_to_otherbigfile -out private.key 2048

-rand tells openssl to use to listed files in order to randomize the generated key. Note that a colon (:) seperates the path names.

-out specifies the file where to store the generated key and last but not least 2048 are the amount of bits we want our key to have. The default is 1024.

Step 2

Now that are key-pair is generated we are ready to create our certificate request and sign it:

openssl req -x509 -key private.key -days 3000 -new > mycertificate.crt

Normally we would have to do this in two steps, first create the certificate request, and then sign it with another openssl command. However, the -x509 option tells openssl to immediately output a certificate instead of a certificate request. In order to do so, we must specify the key openssl should use to sign our certificate, using the -key option. -days specifies how long the certificate should be valid.

After issuing the command we’ll be asked some questions such as country, province, state, common name, etc.

If you are planning on using the signed certificate for a HTTPS website, make sure common name is the same as the website’s hostname, if not users will receive an ugly error stating that the certificate does not match the websites hostname.