Thursday, June 30, 2005

Passwordless logins with SSH

Here's how to login without supplying a password for remote machines running ssh.

  • On the local Unix/Linux host or a local Windows host with openssh installed, execute:
    ssh-keygen -t dsa
  • Use scp to copy the $HOME/.ssh/id_dsa.pub from the local machine to the remote ssh host.
  • Login to the remote ssh host.
  • Append the contents of id_dsa.pub to $HOME/.ssh/authorized_keys.
    cat $HOME/id_dsa.pub > $HOME/.ssh/authorized_keys
    rm $HOME/id_dsa.pub
  • Ensure permissions on the $HOME/.ssh directory are strictly for the file owner only.
    chmod 700 $HOME/.ssh
    chmod 600 $HOME/.ssh/*

Alternately, if the local host is Windows and there's no openssh around, then download and install the Putty installer - preferrably the 0.58 version or higher. Then run the puttygen tool, select the dsa option and press Generate. After the key generation is completed, save the public and private keys. Do the same stuff with the public key as mentioned above. [Urk - I'll complete this later - am running late ]

Wednesday, June 29, 2005

Converting Type 1 fonts for use with Windows

Some Linux distributions like Red Hat and Suse have some fabulous Type 1 fonts for use that Windows users can really drool over. I especially like the URW and Chancery fonts.

If you want to use these fonts in Windows, hop over to the FontForge site and download FontForge. Open the font you wish to convert, select Generate, and choose to convert to either an OpenType or TrueType font. Drop the font in your fonts directory and you're home free. :)

Converting TTF for use with Linux/Unix apps

There are some apps on Linux/Unix that refuse to play nicely with TrueType or OpenType fonts. (The WxWindows library is one that gave me such headaches.) For such programs, the best bet is to convert the TTF to Postscript Type 1 fonts using TTF2PT1. There's even a version for Windows.

After installing TTF2PT1, convert the font to Type 1 using the command:
ttf2pt1 -a -e -llatin1 filename.ttf

For creating fonts for use with Ghostscript:
ttf2pt1 -a -b -llatin1 filename.ttf

You ought to have a files suffixed with .afm and .pfa (or .pfb for use with GhostScript) after the conversion completes.

Note that you should NOT do this if the font license disallows such a conversion.
Drop the font in the appropriate directory on Linux/Unix and from that directory, build the fonts.scale and fonts.dir file with
mkfontscale
mkfontdir
.

If needed, add the directory to the X font path as mentioned in this tip.

Installing truetype fonts in Fedora Core/Red Hat and others

X Window supports many different types of fonts like Adobe Type 1 fonts, TrueType, or OpenType. If you need your OpenType/TrueType fonts accessible in Linux:

mkdir /usr/share/fonts/opentype

Copy the TrueType (.ttf) or OpenType (.otf) fonts into this folder. Now run
ttmkfdir -d /usr/share/fonts/opentype \
-o /usr/share/fonts/opentype/fonts.scale
mkfontdir /usr/share/fonts/opentype


Run chkfontpath to see if the directory we created (/usr/share/fonts/opentype) is present in the list of locations X Window will look for font files. If not, run:
chkfontpath -a /usr/share/fonts/opentype

If chkfontpath is not present, edit /etc/X11/fs/config or /etc/X11/xfs/config (whichever is present). Locate the lines

catalogue = /usr/X11R6/lib/X11/fonts/misc:unscaled,
/usr/X11R6/lib/X11/fonts/75dpi:unscaled,
/usr/X11R6/lib/X11/fonts/100dpi:unscaled,
/usr/X11R6/lib/X11/fonts/Type1,
/usr/X11R6/lib/X11/fonts/Speedo,
/usr/share/fonts/default/Type1,


To this, add /usr/share/fonts/opentype so that the content now appears like:
catalogue = /usr/X11R6/lib/X11/fonts/misc:unscaled,
/usr/X11R6/lib/X11/fonts/75dpi:unscaled,
/usr/X11R6/lib/X11/fonts/100dpi:unscaled,
/usr/X11R6/lib/X11/fonts/Type1,
/usr/X11R6/lib/X11/fonts/Speedo,
/usr/share/fonts/default/Type1,
/usr/share/fonts/opentype,


Now run:
fc-cache
fc-list


Check if the fonts added appear in the list. You can also run xfontsel to check the font list. For a font preview as well, run gucharmap.

If you add new fonts to this directory, run ttmkfdir, mkfontdir and fc-cache again.

Monday, June 27, 2005

Making KBD tags look good

Not directly Linux related, but something I wouldn't like to forget :-)

The Mozilla support site shows keystrokes really neatly. Like this: Ctrl+Alt+Del or Ctrl+W. The style sheet I used is:
kbd {
padding: 0px 1px 0px 1px;
border-width: 1px 3px 3px 3px;
border-style: solid;
background: #faf6f6;
color: #000;
border-color: #edd #baa #baa #eed;
font-size: 10pt;
font-style: monospace;
font-variant: normal;
font-weight: normal;
}

End result is a nice keyboard effect of sorts.

Friday, June 24, 2005

Starting a new X session through KDE

To be able to start a new X session through KDE:
cd /etc/X11/xdm
cp Xservers Xservers.orig

Edit the Xservers file so that it looks similar to this:

...
# you can add them here as well. Each X terminal line should
# look like:
# XTerminalName:0 foreign

# We comment out the following:
# :0 local /usr/X11R6/bin/X

# Add these lines
:0 local@tty1 /usr/X11R6/bin/X -nolisten tcp vt7
:1 local@tty2 reserve /usr/X11R6/bin/X -nolisten tcp :1 vt8
#:2 local@tty3 reserve /usr/X11R6/bin/X -nolisten tcp :2 vt9
#:3 local@tty4 reserve /usr/X11R6/bin/X -nolisten tcp :3 vt10
#:4 local@tty5 reserve /usr/X11R6/bin/X -nolisten tcp :4 vt11


You can then select Start New Session under the KDE menu. KDM and KDE are both needed for this to work. KDE does have it's own Xservers file, but on FC at least, it's a symbolic link to /etc/X11/xdm/Xservers.

Transparent Proxying

To make the host a transparent proxy, on the m/c connected directly to the ISP, edit /etc/sysctl.conf and set net.ipv4.ip_forward to 1.
Then execute the following:
# sysctl -p
# #Use appropriate network address below
# iptables -t nat -A POSTROUTING \
-s 192.168.10.0/24 -j MASQUERADE
# services iptables save
On other hosts set their default gateway to the transparent proxy's internal IP.

Cool ImageMagick stuff

Make thumbnails with ImageMagick's convert utility using:
convert -resize 25x25% filename.png filename-thumb.png

The convert utility can also convert image formats:
convert file.jpg file.png

Another cool tool in ImageMagicks arsental which can convert images is mogrify - this one's more useful when there are a many images requiring conversion:
mogrify -format jpg *.png

This will annotate an image:
convert -font helvetica -fill white -pointsize 36 \
-draw 'text 10,14 "Garden, Pune"' \
img_314.jpg annotated_314.jpg


To make an image look like it was sketched:
convert -charcoal 2 \
portrait.jpg charcoal-portrait.jpg


To make images out of a pdf file:
convert bigfile.pdf bigfilepages-%03d.png

You can also combine effects:
/bin/convert -size 460x90 xc:transparent \
-font AvantGarde-DemiOblique -pointsize 72\
-draw "text 10,75 'AvantGarde'" \
-fill darkblue -stroke yellow \
-draw "text 15,70 AvantGarde" test.jpg


This results in an image that looks like

Automounting the USB key

[update: FC3 automounts in GNOME anyways without the hoopla - that new HAL thingy works well with udev. I'll try to get the dratted thingy to work in KDE. The stuff below does NOT work out with FC3 and above.] Add this to /etc/fstab to help the USB key mount automatically in GNOME

/dev/sda1 /mnt/usb vfat \
user,iocharset=utf8,umask=0,sync,quiet,\
exec,codepage=866,noauto 0 0

If you need to automount the USB key, edit /etc/auto.master and add:
/mnt/usb /etc/auto.misc --timeout=60

Then add this line into /etc/auto.misc:
usb -fstype=auto,nosuid,nodev,\
sync,dirsync,mode=777,uid=99,gid=99,umask=000 \
:/dev/sda1

(In the above line, the user nobody has the uid and gid of 99. This is chosen as autofs runs as root.)

Then start/restart autofs :
# chkconfig --level 345 autofs on
# service autofs restart

The USB drive will be mounted/unmounted automatically.

If you want to automount USB flashdrive without using automount:
Plugin your flash drive look a the tail end of dmesg. If there is something about the usb drive on /dev/sda1, then the following will work if you have devlabel:

$ devlabel add -d /dev/sda1 \
-s /dev/flashdrive --automount \
--perms 666

Edit /etc/fstab and add this line:
/dev/flashdrive /mnt/flashdrive \
auto noauto,noatime,user,kudzu 0 0

Next time your flashdrive is plugged in, it should be automounted at /mnt/usb.

Mounting an 8-in-1 card reader

I'd written this tip down on paper - don't remember the origin.

I recently bought an 8in1 USB card reader. It uses multiple LUNs for the different media. To get all of them registered, edit grub.conf to add the kernel parameter "max_scsi_luns=8". Also add "options scsi_mod max_scsi_luns=8" to /etc/modules.conf. Reboot so the new kernel options take effect. Afteryou plug in the USB card reader, you can use the right mouse button on the root window to get a popup menu with a submenu "drives" that contains entries like "memstick", "memstick1", "memstick2", etc. After you picked one of them, it will be mounted and a new icon appears on your desktop.

Acronym tag and styles

This isn't strictly Linux - but it's kinda nice to know.
Firefox supports tags like ACRONYM and DFN. Here's an exampe of the ACRONYM tag - HTTP (Hold the mouse over the word HTTP for a few seconds).

In case you're wondering if the appearance you see here is default, it is not. It's been spruced up with this stylesheet.
<style>
acronym {
border-bottom: 1px dashed;
cursor: help;
}
</style>


I've added this to the HEAD section in my blog template.

Thursday, June 23, 2005

Displaying the path in the title bar

The string '\[\e]2;\H:$PWD\a\]' in PS1 will show the hostname and path in the title bar. The single quotes are important. Also, enclosing the string with \[..\] also matters when it comes to screen wrap. It tells the wrapping mechanism to not count the enclosed characters.

If you use double quotes, use \w instead of $PWD. I like $PWD because it shows the full path and not '~' if the current dir is the home dir.

Another way to do this is in bash is by placing the string in PROMPT_COMMAND. Don't use this unless echo is a shell builtin.

Get the *bleep* out

The PC speaker beeps irritate.

Here's how to turn the beep off for X window:
xset b off

Here's how to turn the beep off for bash:
Edit .inputrc (or /etc/inputrc if you want this systemwide) to reflect:
set bell-style none
Set the bell-style to visual if you want a visual bell instead.

For vim, edit the .vimrc to contain
set visualbell

Running Java apps on FC4 with Sun's JVM

The FC4 release notes advise to not install Sun's JRE rpms, but the self-xtractors instead. If you have these installed, you need to tell certain Java apps to use Sun's VM.

Edit /etc/profile.d/java.sh and type
export J2RE_HOME=/opt/jre1.5.0_03
export PATH=$J2RE_HOME/bin:$PATH

At the prompt, execute . /etc/profile.d/java.sh

Then execute:
alternatives --install /usr/bin/java java /opt/jre1.5.0_03/bin/java 2
alternatives --config java
Output
There are 2 programs which provide 'java'.
Selection Command
---------------------------------------------
*+ 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java
  2 /opt/jre1.5.0_03/bin/java
Enter to keep the current selection[+], or type selection number:
2

/usr/sbin/alternatives --display java


You should see:
java - status is manual.
link currently points to /opt/jre1.5.0_03/bin/java

NVidia on FC4

Again, I got this off the Fedora Core 4 installation notes for us blokes with nVidia cards:

Download the appropriate driver from Nvidia's unix drivers page.

Change to runlevel 3.

Remove the "rhgb quiet" from /etc/grub.conf to disable the "Red Hat Graphical Boot"

Edit /etc/X11/xorg.conf. In the "module" section comment the "load "dri" entry. In the "device" section change "nv" to "nvidia".

Add the line /sbin/modprobe nvidia to /etc/rc.local.

Disable selinux with /usr/sbin/setenforce 0
Execute sh nameOfNvidiaDriverInstaller.run

Reboot.

You should see the nVidia splash screen when Fedora reboots.

To get the graphical boot back:
cp -a /dev/nvidia* /etc/udev/devices
chown root.root /etc/udev/devices/nvidia*

Remove the modprobe nvidia line from /etc/rc.local
Add the "rghb quiet" back to grub.conf

Note that upgrading the kernel requires this whole procedure to be followed again!

Troubleshooting
If the driver installer complains about differing versions of gcc and the version the kernel was compiled with, do this:
sh nameOfNvidiaDriverInstaller.run --extract-only
cd nameOfNvidiaDriverInstaller.run

#I think this should be gcc40
# for FC4- not sure tho'
make install CC=gcc40 # used to be gcc32 for FC1

Speeding up browsing

Haven't verified this - found it on the Fedora Core 4 installation notes over at FedoraNews.org. Edit /etc/modprobe.conf so that it contains

alias net-pf-10 off
alias ipv6 off


Apparently this will speed up browsing and file transfers by decreasing DNS lookup time.

Enabling the slocate Database on FC

To make sure updatedb creates the database used by locate, enable the database creation by setting DAILY_UPDATE to yes in /etc/updatedb.conf.

FC4 system call auditing

Boot the kernel with audit=1 to enable system call auditing. Alternately, enable auditing with the command:

# auditctl -e 1

Firefox bookmark tips

Ok, this isn't exactly Linux, but FF is a linux app so...

In a bookmark's properties, enter a keyword. You can then use the keyword instead of the full URL in the location bar and awayyy we go...

For sites that use GET to submit search forms, note the URL at the time of submitting. Eg: Note the URL:
http://www.google.com/search?q=search+item
Bookmark the URL and edit the bookmark properties. Subsitute a %s in place of the search item. The URL will now be http://www.google.com/search?q=%s.

Assign a keyword - like 'google' to this item. In the location bar type
google searchitem
and we end up straight on the results page.

Wednesday, June 22, 2005

Extended File System Attributes

Clean forgot there were something called extended attributes. This jogged my memory a bit. In summary: For ext3 or xfs, add the user_xattr option while mounting. Eg. in /etc/fstab edit the lines that mount ext3 or xfs file systems like this:
/dev/hda1 / ext3 defaults,noatime,user_xattr 0 1 Then remount the partitions:
mount -o remount,user_xattr / Then use setfattr and getfattr to set/get extended attributes.
  • Create an attribute 'testing' in the 'user' namespace: setfattr -n user.testing -v "this is a test" test-1.txt
  • Delete the attribute: setfattr -x user.testing test-1.txt
  • Retrieve the attribute: getfattr -n user.testing test-1.txt
  • Backup all extended attributes: getfattr --dump * > data_file
  • Restore all extended attributes: setfattr --restore=data_file
And oh, if you dont have setfattr and getfattr, you can get the sources from the SGI site or look for 'attr' on rpmseek or rpmfind.net

Checking Fedora Core CD Media

Checksum Fedora Core ISOs prior to burning them with md5sum (FC3 and earlier) or sha1sum (FC4 and later). When installing Fedora Core off CD media do a mediacheck. Recommended way to do the media check:
boot: linux mediacheck ide=nodma
So far I've not been using ide=nodma - which may explain the reason I've got a failure on working discs as well.