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 sure how to approach troubleshooting this.
Demonstrating:
Tab completion works as the normal user zachary
, who pressed tab to list completions in the first image:
But as user root
, it doesn't list services as completions (only files):
Any help would be greatly appreciated.
This is disabled by default on Ubuntu.
Read your
/root/.bashrc
: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 runlogin
to make you completely root. When runningsudo su -
orsudo -i
it really does completely logs you in as that user. Here, by example of the environment variable$HOME
, more of this difference:Ok so I've figured it out, sort of.
Things that work:
Things that don't work:
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.
You can do following steps to get completion for
sudo
in bash:.bashrc
.if [ "$PS1" ]; then
complete -cf sudo
fi
The
complete
command generates lists of completions for command names (-c
) and files name (-f
) for sudo.sudo -s
Tab or any other command you want to use.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
)echo $SHELL
replies/bin/bash
so I'm running bash, but it's not working. Now I runbash
and my shell looks the same still.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.I had the same problem. What I tried is:
/usr/sbin/visudo
as root userAdd this line to it then save and exit:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
Open new session and try to run command now
That's it; you have done it.