Archive for January, 2009

Things you might want to change in Ubuntu 8.04 (hardy) desktop, part 2

Thursday, January 22nd, 2009

After installing Ubuntu 8.04 (hardy) desktop, there are some things you might want to change. This article focus on user configuration (mostly editing dot files in your home directory) and do not require superuser access. Some of this changes requires that you log out to take effect.

Customize the bash shell

By default, bash save all commands in a history file. This can be quite annoying when you run several instances of the shell in parallel, and may also be a security concern. Add this line at the beginning of ~/.bashrc to only keep command in memory until you exit the shell:

unset HISTFILE
Customize the nano editor

Add this to ~/.nanorc:

unset backup
unset historylog
set nowrap
set quickblank
set tabsize 4
set morespace
Customize xterm

I prefer to use xterm instead of the default GNOME terminal. xterm does not look so good by default, by using this you can get it to look almost like GNOME terminal, but faster and with smaller memory footprint. Add this to ~/.Xresources:

XTerm*faceName: monospace
XTerm*faceSize: 10
XTerm*vt100.Background: white
XTerm*vt100.Foreground: black
XTerm*vt100.metaSendsEscape: true

xterm*saveLines: 1000
xterm*vt100.translations: #override \n\
                 <BtnUp>: select-end(PRIMARY, CLIPBOARD, CUT_BUFFER0) \n

Then open “Perferred Applications” in “Preferences” in the System menu, open the “System” tab and select “Standard XTerminal”.

See also part 1.

How to setup PPTP VPN in Linux

Monday, January 19th, 2009

1. Create a file /etc/ppp/peers/name:

pty "pptp host --nolaunchpppd"
name username
remotename PPTP
require-mppe-128
file /etc/ppp/options.pptp
ipparam name

2. Add this line to the file /etc/ppp/chap-secrets:

username PPTP password *

3. Create a file /etc/ppp/ip-up.d/tunnel

#!/bin/sh

if [ "${PPP_IPPARAM}" = "name" ]; then
route add -net RemoteNetworkWithNetmask dev ${PPP_IFACE}
fi

RemoteNetworkWithNetmask is the network on the remote side you want to access via the VPN tunnel, e.g. 172.16.0.0/12.

Connect by running sudo pon name
Disconnect by running sudo poff
Check what happends by running plog

You can setup several VPN connections with different names, but I’m not sure if it’s possible to connect to more than one at the same time.

This is tested in Ubuntu desktop 8.04 (hardy) desktop.

Things you might want to change in Ubuntu 8.04 (hardy) desktop, part 1

Friday, January 16th, 2009

After installing Ubuntu 8.04 (hardy) desktop, there are some things you might want to change. This article focus on system configuration (mostly editing in /etc) and requires superuser access (using sudo). Some of this changes requires reboot to take effect.

Fix terminal font rendering bug

There is a bug which gives bad font rendering in the terminal window. Fix it by doing this in a terminal:

cd /etc/fonts/cond.d
sudo unlink 10-hinting-medium.conf
sudo ln -s ../conf.avail/10-hinting-full.conf
Fix bug in DHCP client

Fix a bug in the DHCP client described here.

Use GNU nano as default console text editor instead of vi

Add this line to /etc/profile:

export EDITOR=nano
Mount /tmp as tmpfs if you have plenty of RAM

Add this to /etc/init.d/mountkernfs.sh:

32a33,35
>       domount tmpfs "" /tmp -omode=1777,nodev,exec,nosuid
>       # this is necessary to avoid that files are removed later in the boot process
>       touch /tmp/.clean

And add this to /etc/init.d/mtab.sh:

100a101,101
>       domtab tmpfs /tmp "tmp" -omode=1777,nodev,exec,nosuid
Increase the limit of number of open files

Add this to /etc/security/limits.conf:

42a43,44
> *               hard    nofile          65536
> *               soft    nofile          65536
Setup some useful NTP servers and sync clock at each login

Setup some useful NTP servers in /etc/default/ntpdate.

Create a file /etc/X11/gdm/PostLogin/Default:

#!/bin/sh
#
# This script will be run before any setup is run on behalf of the user and is
# useful if you for example need to do some setup to create a home directory
# for the user or something like that.  $HOME, $LOGIN and such will all be
# set appropriately and this script is run as root.

ntpdate-debian -s
if [ $? -gt 0 ];
then
        logger -p user.err "ntpdate failed"
        zenity --warning --text "ntpdate failed"
else
        logger -p user.info "ntpdate successful"
fi

See also packages you might want to remove.

How to use mousewheel in GNU Screen

Sunday, January 11th, 2009

GNU Screen has support for scrollback, but by default you have to use awkward keys to use it. I would like to be able to use Shift-PageUp, Shift-PageDown and the mousewheel to scroll, just like you can do in xterm.

It was not easy to configure Screen for this, and it involves cooperation with the terminal emulator. But I finally managed to achieve a solution which works pretty well. Add this to your ~/.Xresources file (you need to log out for this to take effect):

XTerm*saveLines: 0
XTerm*vt100.translations: #override \n\
  Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  Lock @Num_Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  @Num_Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  <Btn4Down>: string(0x1b) string("[5S") \n\
  Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  Lock @Num_Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  @Num_Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  <Btn5Down>: string(0x1b) string("[5T") \n\
  Shift <KeyPress> Prior: string(0x1b) string("[25S") \n\
  Shift <KeyPress> Next: string(0x1b) string("[25T") \n

Then add this to your ~/.screenrc file:

defscrollback 1000

# Scroll up
bindkey -d "^[[5S" eval copy "stuff 5\025"
bindkey -m "^[[5S" stuff 5\025

# Scroll down
bindkey -d "^[[5T" eval copy "stuff 5\004"
bindkey -m "^[[5T" stuff 5\004

# Scroll up more
bindkey -d "^[[25S" eval copy "stuff \025"
bindkey -m "^[[25S" stuff \025

# Scroll down more
bindkey -d "^[[25T" eval copy "stuff \004"
bindkey -m "^[[25T" stuff \004

This works in xterm. I’m not sure if it works in other terminal emulators.

Note that this disables the normal scrolling support in xterm, you will only be able to scroll when using Screen. You might want to start xterm like this to always use Screen:

xterm -e screen

How to use Ctrl-Tab in GNU Screen

Saturday, January 10th, 2009

GNU Screen allows you to open several sub-windows within one terminal window. By default, you switch between them using Ctrl-A followed by n or p. I think this is a bit clumsy, I would like to switch with Ctrl-Tab and Ctrl-Shift-Tab just like you switch tabs in Firefox and many other applications. The sub-windows in Screen is conceptually just like tabs in Firefox, so it’s logical to use the same keys to switch between them.

Screen can be configured to use any key combination for switching sub-window by using the bindkey command. However, Screen can only recognize the key combinations that your terminal emulator actually intercept and send a unique code for. By default, most terminal emulators do not intercept Ctrl-Tab, they just send the same code as for Tab. And you certainly not want to use that since Tab is used for tab completion in the shell.

So you need to configure your terminal emulator to intercept and send a unique code for Ctrl-Tab. In xterm, you can do that by setting the X resource XTerm.vt100.modifyOtherKeys: 2. Now xterm sends ^[[27;5;9~ for Ctrl-Tab and ^[[27;6;9~ for Ctrl-Shift-Tab (^[ is ESC). However, you don’t want to use this since it mess up other things. You need to configure just Ctrl-Tab and Ctrl-Shift-Tab without altering any other keys. This can be done using the translation feature. Add this to your ~/.Xresources file (you need to log out for this to take effect):

*vt100.translations: #override \n\
        Ctrl ~Shift <Key>Tab: string(0x1b) string("[27;5;9~") \n \
        Ctrl Shift <Key>Tab: string(0x1b) string("[27;6;9~") \n

Then add this to your ~/.screenrc file:

# Ctrl-Tab
bindkey "^[[27;5;9~" next

# Ctrl-Shift-Tab
bindkey "^[[27;6;9~" prev

This works in xterm. I’m not sure if it works in other terminal emulators.