jump to navigation

Fix hostname “Unknown” in router February 6, 2006

Posted by Carthik in snippets, ubuntu.

I have a D-link router, and have three ubuntu boxes at home. When I got the router management page and look at the DHCP clients that are connected to the router, I see either “unknown” or ” ” as the name for the Ubuntu boxes. Managing these becomes a pain, as i have to resort to finding out the MAC address to do this.

The WinXP boxes have their designated names.

The hostname for the Ubuntu boxes are set, and yet the router recognizes them as “unknown” or ” “.

I fixed this problem by editing the /etc/dhcp3/dhclient.conf file to uncomment the following line and editing it as follows:
send host-name "gabriel"

Make Documentation Easier to Read February 4, 2006

Posted by Carthik in administration, snippets, ubuntu.

Today’s tip rules them all, for it puts you in the driver’s seat.

Debian (and ergo Ubuntu) has some of the best documentation in the world. The best thing about the documentation is that it is on your machine, not on the internet. However not many realize this, and many a problem that can be solved just by reading the documentation remains unsolved, and many a user resorts to forums, mailing lists etc when the answer is right there on their own computer. I am guilty too, having realized the power of RTFM-ing before.

You can browse most of the html documentation on your system by
Clicking the System -> Help menu item on the desktop taskbar. Besides Manual Pages, and other Documentation, you will find lots of docs for the different applications.

But what if the tool/library you installed does not come with a GUI, or a menu entry? The documentation for all packages is installed in /usr/share/doc. You could use the terminal to change to that directory and then look around to find the directory containing documentation for the package. Or you could use today’s tip 🙂

To make documentation easier to access, set CDPATH as follows:
$export CDPATH=.:/usr/local:/usr/share/doc

To make the change permanent (across terminal sessions/restarts), add the line to your ~/.bashrc file.

Now, to find documentation for package-name
$cd package-name
and then you can do an $ls to see what documentation is on offer. You can then use your favourite editor/pager to read the documentation.

Often, if you have problems with a package, it is good to read the README.Debian file to see if there are any special notes explaining workarounds or expected problems.
$ pager README.Debian

If there is a file called index.html, you can read the html documentation using
$firefox index.html

There, now you are all set to go exploring and find out more about the packages installed on your system. I was literally overjoyed to find the “CDPATH” variable for bash which makes things so much easier.

Keeping SSH Sessions Alive February 3, 2006

Posted by Carthik in administration, snippets, ubuntu.

Scott Merrill writes in to say:

I noticed recently that ssh connections from my Ubuntu laptop to my
Debian server would time out and disconnect if I left the connection
idle for a long-ish period of time. This really annoyed me, because my
Debian desktop does not exhibit this behavior when connecting to the server.

I added the following line to /etc/ssh/ssh_config :
ServerAliveInterval 5

That seems to have fixed the problem, and my laptop can now remain
connected, though idle, to my server. Maybe this will help someone
else, too.

What this does, essentially is every 5 seconds, the client sends a small keep-alive packet to the server to make it look like the ssh connection is being actively used. The reason for Scott’s timeout could be a NAT firewall that seeks to minimize the nember of active connections to reduce its memory footprint, or to improve performance for other clients. Most firewalls and networks let you keep your connections alive for as long as you wish, but some may act up, and that’s when you can use Scott’s trick.

Tip: Change 5 to 240 or 300, so that instead of every 5 seconds, the keep-alive signal is sent only once in 4 or 5 minutes 🙂

Sorry it took me so long to post this useful tip, Scott.

Nautilus: Set Image as Wallpaper February 2, 2006

Posted by Carthik in snippets, ubuntu.

Quick Tip:

To set an image you are seeing in Nautilus as the wallpaper, drag the image using a middle-click to the desktop. You will then get an option to set the image as the desktop background.

Defining Keyboard Shortcuts for Commands January 30, 2006

Posted by Carthik in administration, guides, snippets, ubuntu.

One of the insanely difficult things to do in Gnome/Ubuntu is to map a custom keyboard shortcut to launch an application. Someone out there knows why one has to muck about in the gconf-editor to do this!!! Usability experts, listen up and fix this! While you are at it, please make it easier to change the default application used to open different filetypes.

But I rant, needlessly 🙂

Faced with the difficult problem of creating a keyboard shortcut to have +E to open up Nautilus, I found this very useful guide to adding keyboard shortcuts for commands in Gnome.

Turn on Bash Smart Completion January 28, 2006

Posted by Carthik in administration, commands, snippets, ubuntu.

The Bash shell has this sweet feature where you can use the TAB key to auto-complete certain things. For example, when I am in my home directory, the following command:
$cd Do[TAB-key]
will automatically yield:
$cd Documents

If you are an absolute novice, like I was, not so long ago, discovering tab completion in the terminal can make you go “Wow!”. Wait till you hear the rest now 🙂

Though you can use the TAB key to complete the names of files and directories, by default the completion is pretty “dumb”. If you have already typed $cd D you would expect that the tab key would cause only the directory names to be completed, but if I try it on my machine, the tab completion tool uses filenames too.

Now, don’t despair! There is now a smart bash tab completion trick you can use. Smart completion even complete the arguments to commands!!

To enable smart completion, edit your /etc/bash.bashrc file. Uncomment the following lines, by removing the # in the beginning of the lines:

#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion

Now you can use tab completion to power your way through commands.

You can even extend bash smart completion to your own favourite commands by using /etc/bash_completion, the “complete” utility and /etc/bash_completion.d . Explaining the nitty-gritty is beyond me. I refer you to the Debian Administration gurus for more information regarding smarter bash completion.

Tilde (backup file) cleanup January 26, 2006

Posted by Carthik in snippets, ubuntu.

In response to my request for tips from users, a few have written in with their favourite tips. I will be posting them here, in the order received, one or more per day.

First, Clifton Snyder has a tip to share with everyone.

Several text editors these days – Emacs, jEdit, et al – leave behind pesky tilde-files after you’ve edited/saved them. This can lead to a cluttered mess of extraneous backup files in different directories. (.bashrc~, .bash_profile~, .fluxbox/menu~, etc.). Thus, one of the smallest – but most useful – snippets that I use is the following alias:

alias emacs-clean='find . -name "*~" -exec rm {} \; -or -name ".*~" -exec rm {} \;'

This will find all files in $PWD and below that have a tilde (~) appended to them and send them to The Great Bit-Bucket Beyond.

I have the following to add:
An alias is something you add to your ~/.bashrc file. Once you add that line to your .bashrc file, typing “emacs-clean” on the command line will execute the action.

The tilde files are automatic backup files of the last version created by the text editors. You can turn off this automatic creation by editing the preferences of the text editor you use.

If you don’t want an alias, and just want to run this once (or every once in a while), execute the following command:
$find . -name "*~" -exec rm {} \; -or -name ".*~" -exec rm {} \;

Make sudo/gksudo remember passwords January 25, 2006

Posted by Carthik in administration, snippets, ubuntu.

I use sudo and gksudo quite often. Now, if you use sudo in a terminal window, then you only have to enter the password the first time. But what if you have more than one terminal window, and try to use a sudo command in all of them? You will be prompted for your password the first time you use sudo in each terminal window. The same applies for gksudo.

This makes sense for a computer that is acting as a server. If you are logged in from multiple locations, and you enter the password for sudo in your current location, all the other locations are still “safe” since the person using the other terminals will still have to enter the password to use sudo. But when it comes to desktop use, this behaviour can be an annoyance.

I hate being prompted again and again for the sudo password (and the graphical gksudo password). For me, on my laptop, I want the sudo password to be “shared” between the different terminal windows, and with gksudo. It would be nice if the timestamp on the password was “global” to all terminals, and all the “gksudo” menu entries.

I ensure this by changing the following line in /etc/sudoers:
Defaults !lecture,tty_tickets,!fqdn

Defaults !lecture,!tty_tickets,!fqdn

Here, tty_tickets refers to “terminal tickets”, and I just changed it from using one ticket per terminal, to a common ticket, globally.

Again, this is not recommended for server installs, but may make life a little easier for average Joe Desktop Users.

Use an Encrypted USB drive/partition January 24, 2006

Posted by Carthik in applications, snippets, ubuntu.

Martin Pitt, an Ubuntu developer, had written up a little note on how to use encrypted partitions with Ubuntu. I reproduce it below with minimal edits:

To create an encrypted partition on a removable device (like an USB stick), do the following:

* Install the package ‘cryptsetup’.
* If you do not want to encrypt the whole stick, repartition the stick with “sudo cfdisk /dev/sda” (or whichever device). E. g. my personal USB stick has a big unencrypted partition for data exchange and a very small (5 MB) encrypted partition for storing my GPG and SSH keys.
* Create an encrypted partition on the target partition:
sudo luksformat /dev/sda1
(or sda2 if you want to format the second partition, and so on).
This will ask you for a passphrase. The default file system is “vfat”, but you can specify a different one with the “-t” option (see manual page).

After this procedure, remove the stick and plug it in again. This should trigger a dialog which asks you for the passphrase and mounts the encrypted partition (along with any unencrypted one, of course).

Just a little warning at the end: Please be aware that if you lose the passphrase, there is *NO WAY* to restore your data!

How to use your Linux Machine as an Alarm January 22, 2006

Posted by Carthik in commands, guides, snippets, ubuntu.

You probably leave your computer on all the time. (Linux users keep it up longer, right?)
So instead of wasting more electricity by using an alarm clock to wake you up, why not put your desktop to work as a personal alarm? Like the Task Scheduler in Windows computers, it is really, really simple to have your Linux system do things at specified times in the future. This article will guide you through the process of using your desktop as a musical alarm.

Note: If you prefer player X and I use player Y in the examples below, you can easily substitute X for Y.

Use Kalarm:

Kalarm is the KDE alarm tool, which can, besides paying sounds, display a text file, or execute commands at specific times in the future. Even if you are an Ubuntu user (Gnome) you still can install and use kalarm. The name of the package to install is, unsurprisingly, “kalarm”!

Use the Xmms-Alarm plugin:

Xmms is the famous winamp-lookalike minimal music player for Linux. Install the package “xmms-alarm” and then you can use Xmms as an alarm. Downside: you will have to keep xmms running all night. No biggie? Alright then, you are all set. Click on the image above to see how to get to the point where you can set the preferences. (Right click on the Xmms window and Choose Options->Preferences->General Plugins)

Using Xmms and “at”:

Start XMMS and start playing songs. Adjust the volume to what you want to wake up to.

Push the stop button, then type:
$echo xmms -p | at 7:00

The “at” command line utility will make sure xmms starts playing at 7 AM the next day to wake you up.

Read $man at to find out more about “at”, which can do just about anything “at” a particular time.

Use “sleep” and “at” :

$sleep 8h && xmms /path/to/mp3file.mp3

This will open the mp3file.mp3 file with xmms after exactly 8 hours.

Use cron, mplayer, and a few other usual suspects:

More details at The Cron-Mp3 alarm clock writeup.

So , pick your poison potion!!!

Finally, if music doesn’t wake you up, the following sure will:
$sleep 8h && cat /dev/urandom > /dev/dsp

Thanks to all the ubuntu-users subscribers for writing in great suggestion, a few months ago.