Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

On most of our servers, tab completion of service names after typing in the service command no longer works, as root. It works just fine as non-root. This is on Ubuntu 12.04. I'm not even sure where to start looking or what logs to look at to troubleshoot this.

E.g.:

Tab completion works.

Tab completion works

Now it doesn't.

Now it does not

Any help would be greatly appreciated.

share|improve this question
add comment

4 Answers

This is disabled by default on Ubuntu.

Read your /root/.bashrc:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi

Bash completion is all commented out. Apparently there's a reason for it I'm not aware of (recovery single user mode perhaps?).

The reason for why it does work when you do sudo su, sudo -s, sudo bash is that it doesn't really run login to make you completely root. When running sudo su - or sudo -i it really does completely logs you in as that user. Here, by example of the environment variable $HOME, more of this difference:

gert@gert-laptop:~$ id
uid=1000(gert) gid=1000(gert) groups=1000(gert),4(adm),7(lp),24(cdrom),27(sudo),[...]
gert@gert-laptop:~$ echo $HOME
/home/gert
gert@gert-laptop:~$ sudo -s
root@gert-laptop:~# id
uid=0(root) gid=0(root) groups=0(root)
root@gert-laptop:~# echo $HOME
/home/gert
root@gert-laptop:~# exit
gert@gert-laptop:~$ sudo su -
root@gert-laptop:~# id
uid=0(root) gid=0(root) groups=0(root)
root@gert-laptop:~# echo $HOME
/root
share|improve this answer
add comment
up vote 1 down vote accepted

Ok so I've figured it out, sort of.

Things that work:

  • sudo -i
  • sudo su -


Things that don't work:

  • sudo -s
  • sudo su
  • sudo bash

So it appears to me that in the former case, you're actually creating a new login shell, so bashrc, profile, etc are loaded correctly, either from ~ or from /etc/skel. In the latter case you're just "executing bash as root" and not actually loading all those critical functions into the shell for autocomplete and the like.

Caveat: My explanation might be 100% wrong. But the top group does work.

share|improve this answer
add comment

You can do following steps to get completion for sudo in bash:

  1. Open your .bashrc.
  2. Insert the following lines and save the file
    if [ "$PS1" ]; then
    complete -cf sudo
    fi
    The complete command generates lists of completions for command names (-c) and files name (-f) for sudo.
  3. Open a new bash and type sudo -sTab or any other command you want to use.
share|improve this answer
add comment

I had the same problem with root not auto-completing. I unsuccessfully tried a couple other ways including messing around with the .bashrc and installing a couple packages. What finally worked for me was as simple as just running bash. So you do your sudo su and tab just lists (in /root)

root@xxxxxxxx:~# service<tab>
root@xxxxxxxx:~# service .<tab><tab>
./             .aptitude/     .bashrc        .viminfo  
../            .bash_history  .profile  

echo $SHELL replies /bin/bash so I'm running bash, but it's not working. Now I run bash and my shell looks the same still.

root@xxxxxxxx:~# bash
root@xxxxxxxx:~# service <tab><tab>
acpid                        plymouth-upstart-bridge  
apache2                      portmap  
apparmor                     portmap-wait  

Now it's working. Just keep in mind that you'll have to double exit to exit the bash you just launched and then exit the sudo su session so you don't leave a root terminal open.

root@xxxxxxxx:~# uname -mrs
Linux 3.8.0-33-generic x86_64  
root@xxxxxxxx:~# lsb_release -d
Description:    Ubuntu 12.04.3 LTS
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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