165

I have installed ubuntu minimal(mini.iso) on my vm. I then used recovery mode to login as root and create an account with useradd -m admin and then set a password with passwd admin.

When I login on the new account, instead of the normal prompt I only see a $ sign. If I try to tab-complete a command or file name it prints a normal tab. If I try to use the arrow keys it prints ^[[A, ^[[B, ^[[C or ^[[D. Also, ls no longer adds colors.

None of these problems were in recovery mode. How can I fix this?

4
  • 1
    The $ prompt is for a user. root's prompt is #. The arrow keys do not work in terminal, you need to type in something like unity to run the Unity shell
    – Simon
    Jul 28, 2013 at 20:12
  • 3
    @SimplySimon The up and down arrow keys are supposed to switch through previous commands, the left and right arrow keys are supposed to scroll through the current command, and tab should complete the command or file name. The path should be written to the left of the $...
    – user145166
    Jul 28, 2013 at 20:18
  • Very true, of course they do. sorry
    – Simon
    Jul 28, 2013 at 20:22
  • 1
    sudo chsh -s /bin/bash root works for me
    – Raskul
    Apr 9, 2021 at 21:06

10 Answers 10

292

That probably means that the new user account was created with /bin/sh as its login shell (which symlinks to the dash shell by default) instead of /bin/bash - you can change a user's login shell with the 'chsh' command

chsh -s /bin/bash

or to change another user's login shell (need to be root to do this obviously)

sudo chsh -s /bin/bash <username>

(you will need to start a new login session for the change to take effect). You may also need to copy the default .bashrc from /etc/skel to get things like the color prompt and default LS_COLORS.

In future you might want to use the 'adduser' command instead of 'useradd' - it sets up a more complete user environment including things like a default .profile and .bashrc - as well as setting the login shell to 'bash'

6
  • 20
    Additional tip: A user may change this for their own account without requiring sudo rights (just omit sudo in above command). Feb 17, 2015 at 16:20
  • 9
    Actually, you don't have to log out. Just invoke it by typing in /bin/bash at the prompt. Same thing goes if you modify your bash.rc file. To see the changes you do the same thing.
    – SDsolar
    May 14, 2018 at 18:41
  • The colors still aren't back in the ls command.
    – User1986
    Feb 4, 2023 at 15:20
  • 1
    @User1986 do you have the default ~/.bashrc file in the user's home directory? You can copy it from the /etc/skel/ directory Feb 4, 2023 at 15:21
  • Thanks! That fixed it. Btw, you answered this question 9 YEARS ago, and replied within 22 seconds to my comment. Impressive!
    – User1986
    Feb 4, 2023 at 15:24
5

I was unable to use tab completion when connecting via VNC to a headless XFCE4. The answer listed here did not work but this did:

Edit Keyboard Shortcuts in xml file:

sudo nano ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml

Find:

<property name="&lt;Super&gt;Tab" type="string" value="switch_window_key"/>

Change it to:

<property name="&lt;Super&gt;Tab" type="empty"/>

Logout/reboot and should be good to go

3

I just installed Vim and everything was solved. At first, I thought that it was installed on the original version of Ubuntu since I was able to use Vi command, but it was not the case.

sudo apt-get install vim 

solved the problem.

2
  • 1
    The selected answer didn't work for me, but this did. Mar 5, 2019 at 2:08
  • 4
    This answer is completely unrelated to the question. How does it helps the problem?
    – trolzen
    Jul 16, 2021 at 22:46
3
sudo sh -c "if [ -e $(which bash) ]; then rm $(which sh) && ln -s $(which bash) /bin/sh; fi"

My problem was that /bin/sh was symlinked to /bin/dash.

0

In my case it turned out to be a function that I had created in my .bash-aliases file called "test". If you are still having these errors, go through your custom aliases in .bashrc, .bash_profile, and .bash_aliases, temporarily removing any suspect additions and try bash auto-complete again.

0

If everything else is working, but just certain filename completion (autocomplete) attempts fail, it might be that you lack permission to search a directory that is a component of the path.

Suppose you want the listing for some other user's .bash_profile file. The following ls command will work; because sudo runs the ls command with the required permission.

$ sudo ls -al /home/someone_else/.bash_profile    

However, if you try to use filename completion, the tab completion does nothing.

$ sudo ls -al /home/someone_else/.bash_pr<tab>   # does not complete

That is because the bash completion is operating before sudo gets invoked. The command might as well be:

$ ls -al /home/someone_else/.bash_pr<tab>   

Because permission to search that directory is lacking, the command completion does nothing.

To temporarily run with greater permissions, you can start a new shell with sudo.

$ sudo bash

The ls command can now be run without the sudo predicate, and autocomplete works. (Note that the prompt switches from $ to #.)

# ls -al /home/someone_else/.bash_pr<tab>   

Just make sure you kill the shell when your task is completed; a shell with this much power is dangerous.

# exit
0

You can also experience tab-completion failure if you're trying to tab-complete a filename with a wrong (or missing) suffix for the command it's being used with in the tab completion.

As an example, tab completion failed on the command+file: totem ~/Videos/SomefilenameWithNoSuffix but worked perfectly after I had renamed the .mkv to ~/Videos/SomefilenameWithNoSuffix.mkv

0

Some answers can fix this issue. However, to make the state permanently, I think you should do this.

To check the current terminal, type this on your ssh terminal.

echo $TERM

If it were unknown or something weird, you can change by doing this:

echo 'export TERM=linux' >> ~/.bash_profile

You can also check the bash_profile using vim or whatever:

vim ~/.bash_profile
0

I believe it depends on the terminal and the environment the terminal operates in. There are various issue sources which may affect the case.

However, in Konsole terminal connected through SSH to a remote server or Docker container, on clean Debian Bookworm, the following works as a charm (for a test):

Start Clean Debian Bookworm Environment

docker run -it --rm -- debian:bookworm bash;

Inside Debian Container

declare userId=1000;
declare userName='user';
declare groupId="$userId";
declare groupName="$userName";

# Create group for User.
groupadd -g "$groupId" -- "$groupName" || exit 1;

# Create User with associated group, new home directory, and shell specified.
useradd -mNg "$groupId" -u "$userId" -s '/bin/bash' -- "$userName" || exit 1;

# Set User environment variable "TERM" for advanced input and output processing on login.
# @see Manual Bash section "Invocation".
printf -- $'export TERM=\'%s\';\n' 'screen-256color' >> "/home/${userName}/.profile";

# Switch User.
su - "$userName";

If required, delete the User:

# Remove User with the User group and directory.
deluser --verbose -- "$userName" &&
rm -rfv -- "/home/${userName}";
-1

This will solve all: paste and press . After that you will be able to auto-complete from the history, using arrow up.

bind '"\e[A": history-search-backward'

Taken from: https://unix.stackexchange.com/questions/5366/command-line-completion-from-command-history Also you can use Ctrl + R to see your history.

1
  • It will work for all modifications of Linux Jul 9, 2018 at 13:37

You must log in to answer this question.