Backspace, Tab, Del and arrow keys not working in terminal (using ssh)

143,507

Solution 1

EDIT: Reference: Mateng's answer

Mateng is close in that I think you're probably running Bourne Shell. But you shouldn't be editing your /etc/passwd file directly. Try using the chsh command instead:

chsh -s /bin/bash

The -s flag will make the new shell (Bash in this case) your login shell, going forward.

Solution 2

when you first ssh in, try these two commands

stty sane
export TERM=linux

I have to do this on some machines that I go into to fix exactly this problem

Solution 3

The following changes solved the problem for me. First, I checked which shell was running:

$ echo $0

which returned:

/bin/sh

As I read in this post in Ubuntuforums, changing the shell to /bin/bash brings the solution. So I edited my user settings in /etc/passwd to:

johndoe:x:1001:104:John Doe:/home/johndoe:/bin/bash

I logged out, then logged in again. Strangely, I had to switch the shell manually (maybe some cache was active) by entering this:

/bin/bash

Voila!
[The problem arose due to a distribution update.]

Solution 4

One of the easiest ways to fix this problem is to type /bin/bash at the command line interface prompt:

$ /bin/bash

The afore mentioned command will execute the Bourne Again Shell on top of the existing shell as a subprocess. This presents the disadvantage of utilising more resources, but nothing has to be edited and no special permissions are required. For example, in recent Kubuntu versions it will start a /bin/bash session atop the default /bin/dash command line shell interface.

To persist the changes, however, one possibility is to edit the /etc/passwd file and add/edit/replace the default shell to /bin/bash after the last ':' character in the line corresponding to the user. In order to edit this file, though, administrator privileges would be required.

Solution 5

I tried all the above plus notes from (this link) with no success. You may want to check vim is installed.

I usually use vi not vim. So I installed vim.

$ sudo apt-get install vim

After that, the keyboard strokes started working properly when I executed vi. Looking at the output of the following, it looks like vi was made an alias to vim after the install:

$ ls -al /etc/alternatives | grep vi 
lrwxrwxrwx   1 root root    18 Jan 13 09:38 vi -> /usr/bin/vim.basic
Share:
143,507

Related videos on Youtube

gopi1410
Author by

gopi1410

Updated on September 18, 2022

Comments

  • gopi1410
    gopi1410 over 1 year

    When I ssh into another Ubuntu machine with my account (with sudo permissions), my backspace key generates some awkward symbols on pressing. Also Tab, Del and Arrow keys don't work.

    On the other hand, I also have another account on the same machine & when I ssh through this account, its terminal works perfectly fine. I couldn't figure out why is this happening.

    • Admin
      Admin over 11 years
      I have the same problem - my host is Win7-64 and my remote guest systems are both Ubuntu Server 10.04. On one server, the keys work, on another, not.
    • Admin
      Admin over 11 years
      Can you try to ssh via a different program, or create a new profile for the target system?
    • Admin
      Admin over 11 years
      I faced the problem with cygwin (in win 7) too
    • Admin
      Admin over 11 years
      What is returned by typing echo "$TERM", when this occurs?
    • Admin
      Admin over 11 years
      echo "$TERM" > xterm
    • Admin
      Admin over 11 years
      I logged in with (1) Kitty, (2) Putty, (3) a new Kitty profile and (4) from an Ubuntu 12.04 Gnome Terminal. In all cases, the problem persists.
    • Admin
      Admin over 11 years
      Is it possible that resetting xterm configuration helps?
    • Admin
      Admin over 11 years
      Please better define the problem. What Ubuntu version (local machine and/or remote host) and Gnome Terminal version are causing this issue? Any other variations should be their own question, or asked elsewhere.
  • Mateng
    Mateng over 11 years
    I tried that, but the problem persists
  • Drake Clarris
    Drake Clarris over 11 years
    did you try term as VT100 instead of linux? what about stty erase <backspace> (<backspace> being where you actually hit the key)
  • Mateng
    Mateng over 11 years
    With (Arrow Up):$ stty erase '^[[A' stty: invalid integer argument '\033[A'. With [Backspace]: $ stty erase '^?' it works. With [Tab]: $ stty erase ' ' no error, but then [Backspace] is back to odd behaviour.
  • Mateng
    Mateng over 11 years
    I tried export TERM=VT100, but no avail.
  • gopi1410
    gopi1410 over 11 years
    yep, same problem with Cygwin too. both do not work..
  • Drake Clarris
    Drake Clarris over 11 years
    Cygwin is mostly what I use it on as my work PC is Windows. stty erase only sets backspace - you said that works, so use that. Looks like you can try stty tab0 - the 0 can be any number between 0 and 3, but I've never used that command, so maybe play with it, but from what I read 0 should be what you need
  • Mateng
    Mateng over 11 years
    stty tab0 does not help. I guess, some kind of general reconfiguration of xterm is necessary. Or the keymap is simply wrong?
  • Mateng
    Mateng over 11 years
    Seems legit. If gopi1410 agrees, the 50 reps are yours.
  • gopi1410
    gopi1410 over 11 years
    @Mateng: agreed, & a link to your answer added to make it complete
  • KrisWebDev
    KrisWebDev over 8 years
    Run as root: sudo chsh -s /bin/bash
  • goncalotomas
    goncalotomas about 8 years
    @Worked for me more than 3 years later. Thank you so much! You're awesome!
  • Whome
    Whome over 6 years
    Worked great for ssh'ing into a raspberry pi!
  • Xen2050
    Xen2050 over 6 years
    What does your block of code do? create a term config somehow? Would be nice to have some explanation, running mystery code isn't the best idea, even their man pages aren't super clear on the default effect of infocmp, or how this is useful
  • user1448926
    user1448926 about 6 years
    @Xen2050: I've added an explanation for each command. infocmp without any option is equivalent to infocmp -I $TERM. This is described in the man page but in two parts: "If no options are specified and zero or one termnames are specified, the -I option will be assumed. [...] The -I, -L, and -C options will produce a source listing for each terminal named. -I use the terminfo names If no termnames are given, the environment variable TERM will be used for the terminal name."
  • Kirill Lykov
    Kirill Lykov about 2 years
    worked for google cloud