3

I set up an Ubuntu VPS from Digital Ocean recently.

When I log in as root, I'm able to navigate around the terminal properly

When I sudo as any other user, I get some extremely strange terminal behavior

  • I can't move my cursor left. It overrwites it with strange control characters, eg. rvm ^[[D
  • I can't use the up arrow to navigate previous commands. I get something similar - $ ^[[A^[[A^[[A
  • Vim is absolutely un-usable. Moving in any direction causes a strange combination of inserting the above control characters or "overwriting" existing characters. I can't delete either.
  • Tab completion doesn't exist at all. Same output as above.

Since this all works when logged in as root, I suspect it's something software related which makes me hopeful it can be fixed.

Any thoughts? Thanks!

  • Hate when this happens... I have no solution tho :( – Tim Jun 10 '15 at 20:24
  • 1
    Check what shell the user is using echo $SHELL. Certain shells work differently. BASH shell, or /bin/bash allows the arrow keys for movement. To switch to bash, just type in bash at the command prompt. – Terrance Jun 10 '15 at 20:26
  • Wow, that worked perfectly! You were right, it was using /bin/sh. The followup question would be - how do I get it to always use bash as its shell? Should I put export SHELL=/bin/bash in the ~/.profile file ? It seems strange that root defaults to using bash but the created users dont – user2490003 Jun 10 '15 at 20:32
  • 1
    The command sudo usermod -s /bin/bash <username> should do it. – Terrance Jun 10 '15 at 20:34
  • I am going to put that as an answer. – Terrance Jun 10 '15 at 20:34
3

bash should be set for the shell for the user for the arrow keys to work. To find out what shell they are using, type in the following from a terminal window while logged in as the user:

echo $SHELL

if it is not bash, the following will add the shell variable to the user:

sudo usermod -s /bin/bash <username>

Hope that helps.

| improve this answer | |
  • 1
    Perfect answer. Also my original mistake for anyone stumbling across this was not creating the user with the proper shell in the first place. useradd defaults to /bin/sh so I deleted the user and readded it with useradd -m <user> --shell $SHELL, although the usermod would've been more proper :) – user2490003 Jun 10 '15 at 21:18
1

Note that if you want to change the default shell, you should edit the value of the SHELL variable in /etc/default/useradd to be "/bin/bash". That way, new users should automatically get /bin/bash as their shell (unless overridden on the command line).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.