Thursday, 9 September 2004

How to make your important files stand out from the others while using Gnome in linux.

While playing around in gnome, I came across a niffy way by which you can mark a particular file or folder in gnome file manager (this works on files on the gnome desktop too) to stand out from the others. This is made possible by marking your file or folder with an emblem. That is right, by using an emblem, you can mark your important files and folders using cute icons to which you associate special meaning. For example, you can associate an emblem named "important" to a file which holds your important data and another folder which holds fun stuff can be given the emblem named "cool" and so on.

This can be achieved as follows :

While in gnome window manager,Select the file or folder (in nautilus) to which an emblem has to be applied. Then right click keeping the mouse pointer on the selected file / folder. Then a menu pops up in which you select the "Properties" command. Then a window pops up showing the permissions that the file or folder has. There is a tab in the window named emblems. Click on it and you are shown a good collection of icons having different names like cool, important, draft, mail and so on. Make your selection and press OK button. Voila! your file sports a niffy emblem which makes it easier for you to identify from the other files or folders of similar nature. This I discovered in Gnome 2.4. But I guess it can be obtained in more recent Gnome 2.6/2.8 too (but I have tried it only in gnome 2.4).

You can also add your own set of emblems. To do that first create small icons (PNG) ideally 32x32 pixel format and then copy them into your ~/.nautilus/emblems/ directory. You can get a great set of icons at Tigert.gimp.org site.





The Menu when you right click on a file or folder. Posted by Hello







The emblem dialog Posted by Hello







The file showing the tagged emblem Posted by Hello

Sunday, 5 September 2004

SSH - Secure SHell

SSH is a Secure SHell which can be used in the place of telnet to connect to a remote machine. The advantage of using ssh over telnet is that communication and data transfer between the local machine and the remote machine occurs in a secure encrypted tunnel. So no one will be able to snoop on your data.These are a few tips in using this program.

Connect to remotehost and tunnel all X traffic over the encrypted connection.

To see how this works, run the command as follows :

$ ssh -X remotehost
...and then run xeyes when you get your shell prompt on the other machine. Notice how it automatically displays on your own X server.

Tunnelling an entire X Session over SSH

This is the method used to tunnel an entire X session from a remote host.

$ ssh -X remotehost

$ gdmXnest &

$ export DISPLAY=:20 // DISPLAY=:20 should be the same thing that gdmXnest just printed.

$ gnome-session
Note that if you aren't on the same LAN, you'll probably want to use a lightweight window manager like fluxbox instead of heavy desktops like gnome and kde.

Copying an entire directory to a remote host using SSH

Let us say you want to copy entire contents of the current directory to the directory tree /tmp/dir on the remotehost. This can be done with a combination of tar and ssh as follows:

$ tar cf . | ssh remotehost "cd /tmp/dir ; tar xf -"
Finally, some helpful information for troubleshooting SSH connections and their keys.

If you are having problems connecting to an SSH server , then the steps given below should help you in tracking down your problem as well as prevent future problems. Follow the steps given below while testing your connection after every step.

  • Check your logs.
    # less /var/log/secure
    This will contain the logs related to the ssh authentication. It is also a good idea to turn on debugging in /etc/ssh/sshd_config to better clarify the problem. Add the following line to /etc/ssh/sshd_config file.
    LogLevel DEBUG3
  • After making changes to the sshd_config file, restart the service.
    # service sshd restart
    You can now view the connection attempts in the console by issuing:
    # tail -f /var/log/secure
    To exit, just do a [Control + C]
  • Verify the keypair.
    # ssh-keygen -y
    This can be used to generate the public key for a known private key. By comparing the output of this command to what you believe to be the public key, you can determine if the key's match. For Example:
    [user@linux .ssh]$ ssh-keygen -y

    Enter file in which the key is (/home/user/.ssh/id_rsa): /home/user/.ssh/id_dsa

    [KEY Here......................................

    .

    .................................. ]

    [user@linux .ssh]$ cat /home/user/.ssh/id_dsa.pub

    [KEY Here......................................

    .

    .

    .................................. ]

    [user@linux .ssh]$
    Verify that most of the numbers look ok. The odds of two keys being off by only a few numbers are very small. The error would be blatant. If the key's do not match (or do not exist), generate new key's (See the end of this post).
  • Check your permissions. SSH is very picky about permissions, so be sure that your user has the correct rights to the files. The most important files are located in ~/.ssh . Do these as root. This assumes that your user's name is user, so you should change the name accordingly.
    # chown user:user /home/user/.ssh

    # chmod 700 /home/user/.ssh

    # chown user:user /home/user/.ssh/*

    # chmod 640 /home/user/.ssh/*

    // The following files may not exist

    # chmod 600 /home/user/.ssh/identity

    # chmod 600 /home/user/.ssh/id_dsa

    # chmod 600 /home/user/.ssh/id_rsa
  • Check the Settings in sshd_config .
    # vi /etc/ssh/sshd_config
    This file contains the settings used by the SSH Daemon. Any line preceded by a "#" is commented out and shows the default setting. For Example:
    # Port 22
    Means that no change has been made from the default, and the default is Port 22 for SSH connections. Look through the file for the following settings, and note their values. The defaults are listed here.
    #AuthorizedKeysFile .ssh/authorized_keys2

    #PasswordAuthentication yes
    For troubleshooting purposes you should comment out the above lines. Also look for:
    AllowUsers
    If that line is present, make sure that your user's name is listed. (If its not listed, you can add it for extra security.) For Example:
    AllowUsers user user1 user2
    Remember to restart the service:
    # service sshd restart
These steps should help you get an SSH session up and running using key authentication. You should be able to track any further problems from the log file, but if you follow these directions, most problems you could face should be mitigated.

Generating New Keys

Note: This is to be done as a normal user. I'm using DSA keypairs for an example.

$ ssh-keygen -t DSA
This will create two files: ~/.ssh/id_dsa and ~/.ssh/id_dsa.pub . You can optionally create a passphrase for the keys, as an added level of security.

Copy the public key to your authorized_keys2 file.

$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys2
Copy the id_dsa to your client machine and change its permissions to read/write for the user and none for the group and others.

$ mv id_dsa .ssh/id_dsa

$ chmod 600 .ssh/id_dsa


Friday, 3 September 2004

How to use windows fonts in Mozilla (linux)

In order to do that, you needed to copy the fonts you use for Windows XP Pro to Linux. Here are the steps to get fonts over to Linux and how to activated them:
1. If you don't have a /usr/share/fonts/TrueType directory, create one.
# mkdir /usr/share/fonts/TrueType
# cd /usr/share/fonts/TrueType

2. Make sure that all the font files you're copying have lower-case extensions, so if you have files like font.TTF, rename that to font.ttf
3. Copy the fonts to /usr/share/fonts/TrueType
4. Change into that directory:
# copy  /mnt/C:\/windows/fonts/*.ttf   /usr/share/fonts/TrueType/. # cd  /usr/share/fonts/TrueType 

5. Issue the following commands to build the necessary fonts.scale and fonts.dir:
# ttmkfdir -o fonts.scale
# mkfontdir

6. This should have now created the fonts.scale and fonts.dir files
7. Now go to you /etc/X11 directory so that you can add the new font directory to the search path of your X server by adding it to the fonts section of XF86Config

8. Edit XF86Config - Go to the "Files" section and add the FontPath there, mine looks like the following after editing:
RgbPath "/usr/X11R6/lib/X11/rgb"
FontPath "unix/:7100"
FontPath "/usr/share/fonts/TrueType"

9. Now for the Mozilla part! Go to the directory you installed Mozilla in, located at /usr/local/mozilla. Change into /usr/lib/mozilla-1.4/defaults/pref. Note your mozilla may be installed somewhere else. In redhat, try
# rpm -ql mozilla grep unix.js 
to get the path where your unix.js file resides.
10. Backup the unix.js preference file so that you can get back to it if anything screws up:
11. cp unix.js unix.js.bak
12. Edit the unix.js file and look for the TrueType section and change it to look like the following snippet:

// TrueType
pref("font.FreeType2.enable", true);
pref("font.freetype2.shared-library", "libfreetype.so.6");
// if
libfreetype was built without hinting compiled in
// it is best to leave
hinting off
pref("font.FreeType2.autohinted", false);
pref("font.FreeType2.unhinted", false);
// below a certian pixel size
anti-aliased fonts produce poor results
pref("font.antialias.min", ;
pref("font.embedded_bitmaps.max", 1000000);
pref("font.scale.tt_bitmap.dark_text.min", 0);
pref("font.scale.tt_bitmap.dark_text.gain", "0.7");
// sample prefs for
TrueType font dirs
pref("font.directory.truetype.1",
"/usr/share/fonts/TrueType");
pref("font.directory.truetype.2", "/usr/X11R6/lib/X11/fonts/TTF");
//pref("font.directory.truetype.3",
"/u/sam/tt_font3");
pref("font.FreeType2.printing", true);

Now you'll enjoy a MUCH clearer veiw of websites you visit!

Monday, 23 August 2004

Steps to Compile a Kernel

First download and install the kernel source to your machine. Then move to that directory. In redhat linux the source is usually installed in a directory named linux-2.x.xx.xxx in the /usr/src directory. And a soft link to that directory is created by the name linux-2.4 (Assuming it is the source of the linux 2.4 kernel). So the kernel source is installed in /usr/src/linux-2.4 directory.

Now move to this directory.

# cd /usr/src/linux-2.4
The next step is creating the configuration file (.config). This can be done in three ways.

# make config - brings up a command-line console mode interface.

# make menuconfig - brings up a ncurses based GUI Interface.

# make xconfig - brings up a X GUI based user friendly interface.
You may use any one of the above three commands.Depending upon the command that was executed, you will get a relevent interface using which you can configure your kernel before it is compiled.For example, you can select the proper processor type in the configuration dialog. Another thing is you can decide whether to build a functionality directly in the kernel or load it as a module when the kernel needs it.This will optimise your kernel for your computer and will help decrease the size of your kernel. The end result is your linux machine starts much faster.

After you have made the changes to the settings, you have to save and exit.Then all the changes you made to the configuration file has been saved at /usr/src/linux-2.4/.config

Now the next step is to make the dependencies. For that execute the following commands.

# make dep

# make clean
The first of these commands builds the tree of interdependencies in the kernel sources. These dependencies may have been affected by the options you have choosen in the configure step. The 'make clean' purges any now-unwanted files left from previous builds of the kernel.

The next step is the actual compilation of the kernel. Here you can opt to create a compressed image by executing the command

# make bzImage
Or if you opt for a non compressed image then you can execute the command

#make zImage
The time taken for compilation of the kernel depends on the speed of your machine. In my machine (Celeron 333MHz) it took around 15-20 mins.

After the compilation is complete, you can find your newly compiled kernel here : /usr/src/linux-2.4/arch/i386/boot/bzImage .

If you have enabled loadable modules support in the kernel during configuring, then you have to now execute the commands

# make modules

# make modules_install
Loadable modules are installed in the /lib/modules directory.

Now to start using your newly compiled kernel, you have to copy the kernel into the /boot directory.

# cp /usr/src/linux-2.4/arch/i386/boot/bzImage /boot/bzImage-mykernel-sept2004
Now open your boot configuration file (I used lilo) in your favourate editor and insert the following lines to boot linux using your new kernel.

# vi /etc/lilo.conf
//Inside lilo.conf file

image=/boot/bzImage-mykernel-sept2004

label=myker

root=/dev/hda3

read-only
My root is located at /dev/hda3 which I found out using the command

# df /
Now don't forget to execute the 'lilo' command to update the changes in the boot loader. Reboot your machine and in the lilo prompt, select 'myker' and press enter to start loading your newly compiled kernel.

Sunday, 11 July 2004

Read, write and move files to and from an MS-DOS formatted floppy in Linux

I have been asked a number of times as to whether Linux can read files from an MS-DOS formatted floppy. And the answer is yes it can and the method to do it is to mount the MS-DOS formatted floppy to a mount point and then read the files from there. Usually in Linux your first floppy drive will be allocated the device name /dev/fd0. So you can mount the floppy to the mount point /mnt as follows :
# mount -t msdos /dev/fd0 /mnt
And then you can access the files from the /mnt directory. Once you have mounted a device, you have to remember to unmount it before you detach the device. So in the case of the floppy, before you remove it from the floppy drive, you have to run the command:
# umount /mnt
Easier method :
But there is an easier way of reading and writing to a floppy which is formatted with an MS-DOS file system such as FAT16. That is by use of the commands in the mtools package which is usually installed by default in most major Linux distributions. A cursory look at the mtools package shows that there are around 26 command line tools in it. But the beauty of mtools is that if you have ever used commands in MS-DOS you will be perfectly at home using the commands in mtools package too.

First to get an idea of the different commands bundled with mtools, fire up a terminal and execute the command 'mtools' as follows:
$ mtools
Supported commands:
mattrib, mbadblocks, mcat, mcd, mclasserase, mcopy, mdel, mdeltree
mdir, mdoctorfat, mdu, mformat, minfo, mlabel, mmd, mmount
mpartition, mrd, mread, mmove, mren, mshowfat, mtoolstest, mtype
mwrite, mzip
From the above output, you will recognize a number of msdos commands such as copy, attrib, deltree, dir, format and so on but with the exception that they have the letter 'm' prepended to it. And these commands accomplish the same tasks as those of the MSDOS counterpart.

For instance to list the contents of a MSDOS formatted floppy, insert the floppy in the floppy drive and run the following command :
$ mdir a:
And it will display all the files and directories in the floppy. Similarly to copy a file from the Linux partition to the floppy, run the mcopy command as follows :
$ mcopy /home/ravi/test.txt a:/.
... and the file 'test.txt' gets copied to the floppy.

To format the floppy with an MSDOS file system, use the 'mformat' command and so on.

One thing worth noting is that to use mtools, you do not have to mount the floppy which is a plus point of these set of tools. You can learn more about the respective commands by viewing the man page of each of them.