Thursday, 14 April 2005

A collection of PDF viewers for GNU/Linux

Portable Document Format (pdf) file is a self-contained cross-platform document. In plain language, it is a file that will look the same on the screen and in print, regardless of what kind of computer or printer someone is using and regardless of what software package was originally used to create it.Although they contain the complete formatting of the original document, including fonts and images, PDF files are highly compressed, allowing complex information to be downloaded efficiently.
PDF is a file type created by Adobe Systems Incorporated. You need a viewer to read the pdf files.And since Adobe released the schema of PDF and postscript (another file format for printing purposes) in the public domain, anybody interested in creating a software for viewing PDF files can easily create one.
Linux being a community effort,there are a number of utilities for viewing PDF files.
The one that come installed by default on most modern linux distributions is GPDF . GPdf is a PDF viewer for the GNOME 2 platform. It has got basic PDF viewing capabilities but not many features . Another PDF viewer is XPDF . Xpdf is not so beautiful to look at. But it has a very functional interface with which you can view the PDF files. An advantage of XPDF over GPDF is that it has got a low memory footprint and so loads very fast even on my machine which has only 64 MB RAM.
Recently Gnome has brought out another document viewer called Evince . Evince is a document viewer for multiple document formats like pdf, postscript and support planned for other formats like multi-page TIFF, DJVU, DVI and Images. Their plan is to replace the multiple document viewers that exist on the GNOME Desktop with a single simple application.
Other PDF viewers that come to mind are ggv (Ghostscript Viewer) and kpdf (pdf viewer on kde). In fact true to the spirit of freedom of choice, there are a plethora of pdf viewers for the GNU/Linux platform and the user can choose to use the one he is more comfortable with.
Till recently Adobe had not released a version of Acrobat Reader (a popular software used to view PDF files) for GNU/Linux. But that has changed now. They have released the Acrobat Reader Version 7.0 for linux (over 30 MB download), which is a very important milestone for the GNU/Linux community because even though Adobe has released only a binary version of their Acrobat Reader, the mere act of releasing a software on this platform strengthens the fact that GNU/Linux on the desktop has come of age and is becoming increasingly popular among the masses. And companies that have a stake in the IT industry cannot afford to sit back and all together ignore this platform.

Saturday, 9 April 2005

Installing linux on a Mac Mini

I have always been fascinated by the iMacs from Apple after I got to use an iMac at a friends place. But buying one was beyond my price range until Apple released the Mac Mini - widely touted as the budget Mac which could make the PC run for their money.

For people who doesn't know - Apple brings out the Mac series of machines running their own proprietary OS called OSX. This Operating system is built on a Unix base (more specifically the FreeBSD) and so can run most command line tools of Unix/Linux. Also unlike the PC which is built on Intel architecture, the Mac computers use the G5 Chipset (PowerPC Architecture). Frankly speaking, each Mac computer could be considered to be a piece of art considering the elegant look and latest technologies used in them.

Now my writing about this in the blog dedicated to linux takes significance because I have always wondered if Linux could be installed on a Mac computer. Recently, I came across this article which gives a detailed explanation on Installing Debian Linux on the Mac Mini. Those of you who are thinking of buying a Mac Mini might be interested to know that you can also dual boot between Linux and OSX in the Mac Mini just like you do in a PC.

Tuesday, 5 April 2005

Configuring Apache webserver to restrict access to your website

Apache Webserver is the most popular web server and has a market share of around 60%. Here I will explain a small but very useful feature of the apache web server - which is restricting access to (a part of) your website to only the privileged few by implementing username and passwords.
There are two ways of restricting access to documents.
  1. Either by the hostname of the browser being used
  2. By asking a username and password
The first method can be used to, for example, restricting documents being used within a company. But if the people who are accessing documents are widely dispersed, then the second method is more suitable.
Here I will explain the second method - ie, assigning username and passwords to users who are authorized to access the documents. This is known as user authentication.
Setting up user authentication takes two steps :
  1. Create a file containing username and passwords - Apache webserver has a utility called htpasswd to create the file containing username and passwords. Here I am creating a file called 'users' in the /usr/local/etc/ directory.
Note: For security reasons, the above file should NOT be under the document root. It can be anywhere BUT the document root.
The first time you run the htpasswd utility, you run it using the -c flag as follows:
# htpasswd -c /usr/local/etc/users gopinath
The -c argument tells htpasswd to create a new users file. When you run the above command, you will be prompted to enter a password for the user gopinath, and confirm it by entering it again. Other users can be added to the existing file in the same way, except that the -c argument is not needed. The same command can also be used to modify the password of an existing user.
After adding a few users, the /usr/local/etc/users file might look like this :
gopinath:WrU90BHQai36
kumar:iABSd12QWs67
ankit:Wer56HsD12s6
The first field is the username and the second field is the encrypted password.
Now comes the Apache server's configuration part. Open the apache server's configuration file /etc/httpd/conf/httpd.conf (your configuration file will be in different location depending on the distribution you are using) and look for the line :
AllowOverride None 
And change it to
AllowOverride AuthConfig
If you want to protect the document root itself, create a file '.htaccess' in the top directory path and include the following lines to it:
#File: .htaccess
AuthName "Only Valid Access"
AuthType Basic
AuthUserFile /usr/local/etc/users
require valid-user
AuthName - directive specifies a realm name for this protection. Once a user has entered a valid username and password, any other resource within the same realm name can be accessed with the same username and password.
AuthType - directive tells the server what protocol is to be used for authentication. At the moment, 'Basic' is the only method available. However, a new method, 'Digest' is about to be standardized, and once browsers start to implement it, Digest authentication will provide more security than Basic authentication.
AuthUserFile - tells the server the location of the user file created by htpasswd utility. A similar directive, AuthGroupFile, can be used to tell the server the location of a group's file.

Lastly don't forget to restart the web server which rereads the changed configuration files :
# service httpd restart
From here on when you try to access your protected site or the directory via the web browser, you will be asked for authentication first. And only those users whose name has been entered in the file pointed to by the AuthUserFile directive will be allowed access to your site.

Thursday, 3 February 2005

Mounting a filesystem automatically using 'autofs'

There was a drawback in Linux when compared to other OSes in that, you cannot read the contents of a filesystem as easily as you do in other OSes like Windows without executing the mount commands (this is especially true for removable media like a Floppy, CDROM or remote filesystems like an NFS share). For example, if you want to read the contents of a floppy, you have to mount the floppy into a directory using the mount command. And after you have read the data , and before you pull out the floppy from the floppy drive, you have to remember to unmount the floppy using umount command. If by any chance, you have forgotten to unmount the floppy, there is a good chance that your data will be corrupted.
But now you have an easy way out of the hassle of mounting and unmounting your filesystem and using it like you use in windows. This is achieved by the autofs daemon.
Autofs is a standard feature in all major linux distributions. It is installed by default. Here I will explain how to configure autofs in RedHat distribution. The configuration is the same in other distributions other than the chkconfig and service scripts which are a RedHat feature.
First check if the autofs daemon is configured to start at boot time by running the command:
# chkconfig autofs --list
autofs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
As you can see from the above listing that autofs is OFF on my system. So I turn it ON using the command:
# chkconfig autofs on
# chkconfig autofs --list
autofs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Now the autofs daemon is configured to start automatically when you boot up your machine.
The main configuration files for autofs is /etc/auto.master. This file has the syntax as follows:
Each mount point is given on a seperate line. For eg:
# File: /etc/auto.master
/mnt /etc/auto.misc
Where, /mnt is the mount point and it points to another file called autofs.misc (the file can have any name but following precedence, it should start with the name auto), which contains the details of how and what to mount.Suppose I have to make autofs automount my floppy whenever I change into my /mnt/floppy directory, and unmount it automatically when I come out of the /mnt/floppy directory, I just include the following line into my /etc/auto.misc file.
# File: /etc/auto.misc
floppy -fstype=auto,rw,users :/dev/fd0
Each line in the file is divided into 3 sections seperated by one or more spaces.They are :
  • A key - The key can be any single word but preferably the name of the device or the name of the sub-directory below the mount point specified in the auto.master file.
  • The mount options for the filesystem associated with the key. In the listing of my auto.misc file, I have set it to mount with read/write permission and autodetect the type of filesystem - whether ext3 or vfat etc - and who all can mount the filesystem (see man mount for more options).
  • The path of the device file associated with the filesystem. It should be preceeded by a colon (:).
Now I save and exit the /etc/auto.misc file. The last thing to do is to restart the autofs daemon to re-read the /etc/auto.master file.
# service autofs restart
Note: Each time any changes are made to the /etc/auto.master file, you have to restart the autofs daemon to bring the changes to effect. But you need not restart autofs if you change the contents of auto.misc file or the contents of any other files listed in the /etc/auto.master file. Now I test my setup by inserting a floppy into the floppy drive and execute the following command:
# cd /mnt/floppy
Success!! The floppy gets mounted automatically and I am able to list the contents of the floppy.Now I come out of the directory. And after a period of inactivity (default is 60 sec), the floppy is automatically unmounted.
You can likewise set the remote NFS share (at IP address 192.168.0.1) to mount using autofs. For example, I could append a line in /etc/auto.misc file as follows:
# File: /etc/auto.misc
nfsshare -fstype=auto,soft,intr 192.168.0.1:/remote_nfs_share
cdrom -fstype=iso9660,ro :/dev/cdrom
.. and so on.

Tuesday, 1 February 2005

DHCP Server configuration

Suppose you are in charge of a network of say 100 computers all in a single broadcast domain. There are two ways of configuring the IP addresses of these machines. One is the static method ; assigning an IP address to each of the 100 machines manually which can be quite tedious. The other easier and better method, is to use DHCP (Dynamic Host Configuration Protocol) to let a computer acting as the server assign the IP address to each of the 100 machines automatically. Infact, it is so easy that nowadays any computer which forms a part of a large network is assigned its IP address dynamically. This is also true when you connect to the internet via a dial-up or DSL modem - in which case, your computer is technically a part of the large network of your ISP and your ISP assigns your computer an IP address from its address pool automatically.

There are two popular methods of assigning IP addresses. They are BOOTP and DHCP. Both wait and hear for computers in the network to send broadcasts publishing their MAC addresses and requesting an IP address. The BOOTP or DHCP server, on recieving a broadcast, assign an IP address to the MAC address in the broadcast from its address pool. The client computers can query the server and find lots of information like default gateway, IP address, subnet mask, DNS etc.

Here I will explain how to convert your linux machine into a DHCP server. The power of DHCP is that if anything changes on your network such as the IP of a DNS server, you only need to edit one configuration file even if you have hundreds of clients.



If you do not have dhcp server installed on your machine, this is the right time to do so. In Redhat, you install the dhcp (rpm) package. The dhcp server runs as a daemon and has the name dhcpd and listens on ports 67 (bootp server) and 68 (bootp client). There are two main configuration files for the DHCP server. They are :

  • /etc/dhcpd.conf
  • /var/lib/dhcp/dhcpd.leases

The dhcp package installs without any configuration. The daemon will not start if a dhcpd.leases file does not exist. An empty file (commented) is installed with this package.

#File : /etc/dhcpd.conf



ddns-update-style none;



option domain-name "mydomain.com";



default-lease-time 21600;

max-lease-time 43200;



subnet 192.168.1.0 netmask 255.255.255.0

{

range 192.168.1.100 192.168.1.200;

option subnet-mask 255.255.255.0;

option broadcast-address 192.168.1.255;

option domain-name-servers 123.123.123.10, 123.123.123.20;

option routers 192.168.1.1;



host station1

{

hardware ethernet 00:a0:cc:3d:0b:39;

fixed-address 192.168.1.7;

}



host station2

{

hardware ethernet 00:06:CD:CD:CD:CD;

fixed-address 192.168.1.8;

}

}
Above I have shown the listing of my /etc/dhcpd.conf file. I will explain the meaning of each line below :

ddns-update-style none;
The first thing we need to do is set a Dynamic DNS update style. Here I have set it to the value none. But if it is something you want to do, you may read the man pages which has lots of information on this topic.

option domain-name "mydomain.com";
The above line specifies the domain name set on your server if you are running DNS.

default-lease-time 21600;

max-lease-time 43200;

Specifies the time in seconds after which the lease will expire and the maximum lease time also in seconds.

subnet 192.168.1.0 netmask 255.255.255.0
Next we must specify what subnet and netmask we will be working on. Note that you can have many subnet configurations within the single dhcpd.conf file. Each subnet group is bound together by curly braces { }



Note that every command from here on will only pertain to the subnet specified above. This will be true until we reach the closing curly brace } as noted above.



Now we will specify what range of IP addresses we want to be made available for clients using DHCP. This option is very handy when used in conjunction with a firewall because you know exactly what IP addresses came from a client using DHCP and you can exercise restrictions upon them as necessary.

range 192.168.1.100 192.168.1.200;
option subnet-mask 255.255.255.0;
The above option is redundant as it has been already set before the curly braces. But since it is given in the man pages, I have included it here.

option broadcast-address 192.168.1.255;
Specifying the broadcast address of our subnet.

option domain-name-servers 123.123.123.10, 123.123.123.20;
The above line tells all our clients what servers to use for DNS inorder to resolve hostnames to IP addresses.

option routers 192.168.1.1;
This line tells our clients what IP address to use for the default gateway. Usually the default gateway is our router.

Even though DHCP gives out IP addresses dynamically, it has the option of reserving a particular address for a certain computer. To do this, you have to specify the MAC address of your client machine for which you need to reserve an IP address. You can find the MAC address by running the following command on your client machine:

# ifconfig eth0 | grep HWaddr
..where eth0 is your ethernet interface. The MAC address is a 48 bit address burned into the NIC by its manufacturer. It is a unique number and no two NICs in the world will have the same number. It is obtained in hexadecimal format.

host station1
The first thing we must do is to specify a name for the computer as a helpful identifier as shown above. Note that similar to the subnet grouping, we are starting a sub-group which is represented by the curly braces. This allows us to have multiple host definitions within one subnet group.

hardware ethernet 00:a0:cc:3d:0b:39;
This is the client machine's MAC address for which we are going to reserve an IP address.

fixed-address 192.168.1.7;
This line tells the dhcpd server what IP address we always want to be assigned to this computer. Now the only thing remaining is to save your /etc/dhcpd.conf file and restart your DHCP daemon.

# service dhcpd restart
Also see How to assign an IP Address to understand DHCP client configuration.

Sunday, 30 January 2005

NFS Client - Server Configuration

NFS - Network File Service - is a System V managed service which is basically used to serve files from a remote computer to your local machine. It consists of two parts; the server part and the client part.



The Server Configuration:

Two main RPM packages are needed to configure NFS as a server on your RedHat machine:

portmap - needed because NFS server is an RPC (Remote Procedure Call) service.

nfs-utils - Which contains the essential files and utilities like the exportfs, showmount, scripts installed in the /etc/rc.d/init.d/ directories like nfs etc which form a part of the NFS server.



The NFS server software is depended on three facilities for its work:

  • portmap : Which maps the calls made from the other machines to the correct RPC service.
  • nfs (in kernel): Translates NFS requests into requests on the local filesystem and
  • rpc.mountd : Which mounts and unmounts filesystems.

All the above three run as daemons and are started at boot time from the portmap and nfs System V initialization scripts. See /etc/rc.d/init.d/ directory.



To verify that these services are running, do eaither of the following:

# rpcinfo -p
OR

# service nfs status

# service portmap status
To verify that these services are running on a remote server (say myserver), do:

# rpcinfo -p myserver
Once you have made sure the above services are running, the next step is to decide which all directories and filesystems are to be made available for sharing across the network via NFS.

This is listed in the /etc/exports file.

#FILE: /etc/exports

/engineering *.myserver.com(ro,sync) otherserver.india.com(rw,sync)

/root/presentations macmot.dc.com(rw,sync)

/sales 192.168.10.0/255.255.255.0(sync)
The above listing is a part of my /etc/exports file. Each line contains one exported directory and its access permissions. For example, the first line exports the /engineering directory to all the clients in the 'myserver.com' domain with read-only access and 'otherserver.india.com' with read-write access. And the data is synchronized on to the disk on each access. The third line shows that you can also give a valid IP address/subnet mask to specify a range of addresses to which the particular directory is exported.

Note: You can use wild cards like * and ? for the purpose. Care should be taken to see that the options are not seperated from the hostnames with white space. If white space exists between a hostname and an option, it is treated as two distinct export destinations and the option will apply to a "world export".



Another thing of significance is that all entries in the /etc/exports are exported with root_squashing turned on. This ensures that a person having root access on a remote machine is not given root access to the files in the server machine.This can be negated by using the no_root_squash option.



Once you have finished editing the /etc/exports file, you have to make the NFS server read the /etc/exports file. This you can do eaither by rebooting the machine or you can run the command :

# exportfs -a
This exports all the shares listed in the /etc/exports file to the NFS server. You have to run this command each time you make changes to the /etc/exports file.

You can check the proper operation of your NFS server by running eaither of the two commands:

# exportfs -v
OR

# service nfs status
Client side configuration :

The main job here is to mount the NFS share exported by the remote computer (let us say server_one). This can be achieved by a few different ways:

  1. Specify it in the /etc/fstab file.
  2. Use the autofs daemon to mount NFS shares on demand and unmount them when idle.
  3. You can mount the NFS shares manually as root, using the mount command.

But before that, you have to know which are the directories exported by the remote NFS server. This is achieved by the command:

# showmount -e
Where hostname is the remote NFS server hostname. When you mount an exported directory from an NFS server, you can access it as if it were local to your machine.

#File: /etc/fstab

server_one:/sales /mnt/pub nfs defaults 0 0
The above listing shows that the /sales directory from the NFS server server_one is mounted locally at /mnt/pub directory. The /etc/rc.d/init.d/netfs script will mount any network filesystems that are configured to be mounted at boot time such as the /etc/fstab listing above.



Some NFS specific options that can be used with mount or in /etc/fstab include:

  • rsize=8192 and wsize=8192 - will speed up NFS thoughtput considerably.
  • soft - Processes return with an error on a failed I/O attempt.
  • hard - will block a process that tries to access an unreachable share.
  • intr - allows NFS requests to be interrupted or killed if the server is unreachable.
  • nolock - Disables file locking (lockd) and allows interpolation with older NFS servers.

For example:

# mount -t nfs -o rsize=8192,wsize=8192,soft,rw server_one:/sales /mnt/sales
The kernel automounter facility, autofs, provides the ability to mount the NFS shares on demand and unmount them when they are idle in a way that is transparent to the end user. Check whether you have the autofs RPM installed in your machine. Then turn it on using the command:

# chkconfig autofs on
Now edit the file /etc/auto.master to mirror your configuration. Check man auto.master for the details of the syntax. Lastly start the autofs service:

# service autofs start
Note: You have to restart the autofs daemon each time you make changes to the /etc/auto.master file. Now you have successfully configured the NFS server and client.

Tuesday, 11 January 2005

Changing the hostname on your machine

This can be achieved in three steps.

1) Issue the command :

root# hostname new-host-name
2) Change the network configuration file /etc/sysconfig/network to include the line :

HOSTNAME=new-host-name
3) Restart the systems which relied on the hostname (or reboot):
root# service network restart
Restart desktop

i) Bring down system to console mode :

root# init 3


ii) Bring up X Windows:

root# init 5


One may also want to check the file /etc/hosts for an entry using the system name which allows the system to be self aware.