Yum provides…

Yum, the preferred RPM package manager makes our lives a bunch easier when you need to install new packages.
Below an example of a nice feature that yum “provides”.

[pieter@laptop ~] nslookup www.google.com

bash: nslookup: command not found

[pieter@laptop ~] yum search nslookup
Loaded plugins: fastestmirror, langpacks, presto, refresh-packagekit
Loading mirror speeds from cached hostfile
Warning: No matches found for: nslookup
No Matches found

Doooooh!! Now what?

In Yum’s man page (man yum) we find our rescue:

provides or whatprovides

Is used to find out which package provides some feature or file. Just use a specific name or a file-glob-syntax wildcards to list the pack‐
ages available or installed that provide that feature or file.

[pieter@laptop ~] yum provides */nslookup

Loaded plugins: fastestmirror, langpacks, presto, refresh-packagekit
Loading mirror speeds from cached hostfile

32:bind-utils-9.8.1-2.fc16.x86_64 : Utilities for querying DNS name servers
Repo : fedora
Matched from:
Filename : /usr/bin/nslookup

32:bind-utils-9.8.2-0.2.rc1.fc16.x86_64 : Utilities for querying DNS name servers
Repo : updates
Matched from:
Filename : /usr/bin/nslookup

As we can see from Yum’s output, the package we need to install in order to have nslookup is “bind-utils”

[pieter@laptop ~] yum install -y bind-utils

[..output stripped…]

[pieter@laptop ~] nslookup www.google.com
Server: ******
Address: *****#53

Non-authoritative answer:
www.google.com canonical name = www.l.google.com.
Name: www.l.google.com
Name: www.l.google.com
Name: www.l.google.com
Name: www.l.google.com
Name: www.l.google.com


How to avoid commands being logged in bash history

Maybe if you are not a hacker it’s not very useful, and if you are a hacker you probably already knew this. But hey, just in case it might be useful, I’ll share it with the world.

Normally every command you write it the Bash command line gets recorded in it’s history.

A simple example showing that this is true

[pieter@laptop ~]$ echo “Hey, I’ll end up in the history”
Hey, I’ll end up in the history
[pieter@laptop ~]$ history
2 echo “Hey, I’ll end up in the history”
3 history
[pieter@laptop ~]$

The echo command is logged in the history, as well as the history command itself.

Now, if you do not want the command you execute to be logged in the history, set the following variable:

$ export HISTIGNORE="&:[ ]*:exit"

From now on every command you executed preceded with a space isn’t being logged to the bash history. Useful in case you need to execute a command that has a password as parameter (I know, not very secure…but still).

[pieter@laptop ~]$ [SPACE]echo “I remain unnoticed, hahahahaha”
I remain unnoticed, hahahahaha
[pieter@laptop ~]$ history
2 echo “Hey, I’ll end up in the history”
3 history


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.