Home and End keys – PuTTY – bash – Linux

Posted by Michael Giarlo on November 30, 2005

Here's a simple one. But first, some backstory.

I'd been using the tcsh shell on my Linux servers for years, but I am now working in an environment where bash is the preferred shell. I view it as an opportunity to poke around in a shell that's relatively unfamiliar to me as a dyed-in-the-wool tcsh user[1]. I'd also been used to connecting to my Linux servers with the SSH Communications Security version of the Secure Shell client. Unfortunately, the newest version of this client, which is available to me, will not connect to our department's boxes due to the version (or configuration) of the OpenSSH libraries that have been installed. I'm new to this job, so I'm accepting this more or less on the authority of comments made by coworkers; I haven't independently verified this, though I can confirm that I can't connect with the SSH client. I switched to the PuTTY SSH client, since it's free, widely used, and supported by my colleagues. And, oh yeah, it connects to our Linux boxes.

One of the neat features of the SSH Communications Security client is the ability map keys to certain other keys. For instance, I used to map the Home and End keys to <Ctrl-a> and <Ctrl-e> for ease of navigation on the command-line; sometimes the command strings I have to type are, to put it technically, really frickin' long and it's nice to be able to make edits to the beginning and end of these command strings without holding down the left and right arrow keys for an hour. PuTTY does not have a key-mapping feature, so I was wondering how to get my Home and End keys to do more than just generate the '~' character. (Though such a feature is on PuTTY's wish-list.)

It turns out there's a simple fix: just set the environment variable, TERM, to the value of "linux" in ~/.bash_profile (or .bashrc).

export TERM=linux

should do the trick. Make sure you logout and login again, or just source your bash config files. It's possible that other TERM values do the trick as well, but "linux" has worked for me. Prior to that, the TERM variable was set to the value "xterm".

For some more shell-based key mapping geared toward the Backspace and Delete keys, see the Consistent BackSpace and Delete Configuration page.

1. While I've used tcsh as my default shell for years, I do acknowledge the argument that csh programming is considered harmful. I use the Bourne shell and Perl for scripting, though primarily the latter.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Lars Fri, 14 Apr 2006 14:16:13 UTC

    export TERM=linux
    worked for me – thank you!

  2. Cees Wed, 26 Jul 2006 02:20:10 UTC

    Thank you!
    Running "export TERM=linux" fixed my problem instantly!

  3. Luar Roji Fri, 22 Sep 2006 15:27:27 UTC

    You can config in putty to send terminal "xterm-color" that has the features of xterm and the home/end keys are compatible.

    This configuration item is in Connection -> Data -> Terminal-type string, in putty's configuration.

    If you have problems with backspace later, you can change it to ^H.

    The cool features of an xterm terminal is the ability to use the mouse to click links in lynx, or use the scroll wheel to scroll through documents in lynx, or in vim..

    See ya!

  4. Armin Thu, 11 Jan 2007 23:49:47 UTC

    the problem with Luar Roji's solution will just be that shift-backspace for example will not get interpreted as backspace, so in most cases setting $TERM to 'linux' will be much better if one uses his putty for chatting.

    additionally, there is a modification of putty called 'nutty', which makes it possible to click on links – the behaviour of when to catch the mouse cursor for links and when to underline those is nicely configurable. just google for nutty and you will find it.

  5. Ryan Wed, 28 Feb 2007 14:09:12 UTC

    Setting the terminal to xterm-color almost works, except now Insert and Delete do not work. How frustrating!

  6. soker Fri, 09 May 2008 13:05:13 UTC

    It's easier modify the configuration, in category: Connection/Data, set "linux" in the field Terminal-type string. for permanent results save it in a session

  7. zhenia Mon, 12 May 2008 03:06:14 UTC

    Thank U !
    a lot of frustration flowed in my veins before this blog.

  8. [...] simple solution which worked for me was to change the Terminal-type String under the Connection > Data tab from [...]

  9. Mike Sat, 26 Jul 2008 02:24:27 UTC

    Thank you!
    This has been frustrating me for a while now. Putting "export TERM=linux" in my .zshrc file (I use Zsh) and setting Connection->Data->Terminal-type string to "linux" worked for me :-)

Comments