Fixing Backspace and Delete for SSH in OS X’s Terminal.app

How do I get the backspace and forward delete keys to work correctly?

  • In the Keyboard section of the Terminal Inspector:
    • Turn on the Delete key sends backspace option.
    • Map the forward delete key to the following string:
      \033[3~
  • Add the following line to your .profile:
    stty erase ˆH

    Since ˆH is a non-printable control character, the easiest way to do this is to execute the following command:

    echo -e "stty erase ˆH" >> ~/.profile

    Type the ˆH by pressing Control-V and Control-H.

  • Add the following line to your .inputrc:
    "\e[3~": delete-char
  • Apply changes by doing a source ~/.profile and a bind -f ~/.inputrc.

Very helpful! I found this information on this website. Thanks, desp!



10 Responses to “Fixing Backspace and Delete for SSH in OS X’s Terminal.app”

  1. This bugged the crap out of me for a while.

    Why doesn’t just “Turn on the Delete key sends backspace option.” work? That’s all I’ve done and it seems to work.

  2. The answer is: Sometimes.

    It worked for some servers for me, but others still executed a delete when I pressed backspace.

    The settings mentioned above managed to make it work for all servers I tested so far :)

  3. Nice but totaly not needed.
    export TERM=linux will fix it just put that in your profile (or the equivelent csh expresion if you use that.)

  4. Interesting. Will try that out, thanks :)

  5. You have to check if the mac os X ssh program requests the correct terminal settings on a remote machine.

    Thats the only problem with it that can occur. I have tested this on remote linux and solaris systems.

  6. [...] Ever have the problem in a Mac OS X terminal that when ssh’ed into a remote machine – delete (backspace on mac) hates you? It doesn’t work but instead send an unparsable character?  Here’s a quick fix. From Frederic Wenzel’s blog: Add the following line to your .profile: [...]

  7. Thanks for the tip. Found some other tips along the same lines on the macromates blog here: http://macromates.com/blog/archives/2006/01/07/word-movement-in-terminal/

    I posted the one I found most useful on my blog at: http://joshwilson.com/blog/?p=87 – or included below from comments on the macromates blog entry:

    “”"

    07 Jan 2006 | # sjk wrote…

    Option-left/right-arrow will invoke backward/forward-word in bash, tcsh, and zsh by simply setting “Use option key as meta key” on the Keyboard page of Terminal Inspector, seen in the first screencapture of this article. That also makes the option key a meta key for other useful shell functions, which is much nicer (for Emacs junkies like me) than using the escape key or control-[. Some functions, like history-search-backward/forward, are particularly painful without the metafied option key.

    “”"

    Cheers,
    -Josh

  8. Wow, thanks a million, that really saved me so much headache!

  9. [...] problem, and various solutions are documented all over the net, but I found and used this page most recently. « Update from the We Are Doomed [...]

  10. @Robrecht van Valkenburg

    I just tried you method, and it works great; thanks.