Archive for May, 2003

Converting normal time to Unix time

Saturday, May 31st, 2003

Have you ever wondered how much seconds passed since 00:00:00 Jan 1 1970 (unix time)?

OK, here goes the answer…

date -d \”May 31 21:15:00 2003\” +%s

or

date -d now +%s

umount: /mnt/XXXX: device is busy

Monday, May 12th, 2003

Are your tired of those nasty messages telling you can’t umount /mnt/cdrom?

Well here goes a little trick…

lsof | grep /mnt/cdrom

This will output the process(es) that are using the device. Now stop or kill the process and you are done.

There are another approach to this question, but let’s see if you have ideas on this…

More security for your files and directories

Monday, May 12th, 2003

There is a tool called chattr that allows you to change/set file attributes on a GNU/Linux second extended (ext2) filesystem.

For example to protect myfile.txt, proceed as follows…

chattr +i myfile.txt

A file with the “i” (immutable) attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser or a process pessessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

Cleaning up core files

Sunday, May 11th, 2003

When an application crashes, the kernel saves the state of the process in a core file for later analysis. This will help to determine the cause of a failure.

To avoid your hard disk being populated by unnecessary core files, you can seek and destroy those files older than 4 days:

find / -name core -atime +4 -exec rm -f \”{}\” ‘;’

To make your life easier you should add the above line to a cron job.

Tunneling over OpenSSH

Sunday, May 11th, 2003

One of the beauties of the OpenSSH suite tools is that you can connect to remote host from your localhost by creating a secure connection through both ends.

Let’s say you want to “tunnel” mail from your laptop to your remote mail server…

ssh -l user -L 110:mailhost:110 -N mailhost

Specifies that the given port on the local host is to be forwarded to the given host and port on the remote side (-L).

The -l switch specifies a login name and -N avoids the execution of a remote command.

Using GnuPG

Saturday, May 10th, 2003

GnuPG is the GNU Privacy Guard, the open source equivalent to Pretty Good Privacy (PGP). You can use GnuPG to encrypt and/or sign your mails or files and hence transmit them in a more secure fashion and ensure their integrity.

There are graphical environments to handle GnuPG but here we are going to use text-based commands.

First of all me must generate a key pair:

gpg –gen-key

The first time you run this command it will create some directories and files, so you need to launch the command again to create the keyrings.

When prompted select these options:

DSA and ElGamal
Keysize 1024
Expire time 0 (never expires)
Personal info
Passphrase

For the moment accepting default values is fine. Be careful with your passphrase as it will be used to encrypt/decrypt and sign your data, so do not simply choose the first silly words you guess ;-)

Once you have your key-pairs, you are ready to start using GnuPG.

gpg -ea -r karkoma myfile.txt

Encrypts myfile.txt using karkoma’s public key with an ASCII armor (more on this in my next article).

gpg -d myfile.txt.asc >myfile.txt

Decrypts myfile.txt.asc (enter your passphrase)

gpg –clearsign -a myfile.txt

Signs myfile.txt. Once signed, the smallest modification to the file will indicate an invalid signature.

gpg –verify myfile.txt.asc

Verifies your file signature.

gpg -ba myfile.tar.gz

Signs a binary file

That’s all folks, just for now. I am preparing a more complete article regarding GnuPG, so come back soon.