1

I'm having a little issue with my PATH when I use sudo :

My PATH from user shell :

/usr/local/bin:/usr/bin:/bin:/opt/bin

My PATH from root shell, via su or root login on TTY :

/usr/sbin:/usr/bin:/sbin:/bin

My PATH from root shell, via sudo -s :

/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin

As you can see, when using sudo, the order of /bin, /usr/bin and /usr/local/bin is reversed.

It's quite annoying, mainly when I use Vim. I'm used to having vi a symlink to vim. The configuration of symlinks on my Gentoo system is :

/bin/vi     -> busybox
/usr/bin/vi -> vim

So in most cases, simply typing vi brings up Vim, but if I use sudo vi, I end up with the Busibox vi, due to change in PATH order !

I couldn't find out how sudo builds this new path, is there a way to change it ?

2
  • do you use /bin/vi ? You could maybe symlink it to /usr/bin/vi
    – exussum
    Jan 7, 2014 at 23:21
  • @user1281385 This symlick is part of the internal Gentoo system, and might be useful in recovery situations. I don't want to delete it.
    – Levans
    Jan 8, 2014 at 9:14

1 Answer 1

4

Check the /etc/sudoers file or /etc/sudoers.d directory. You should see something like:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin
1
  • I didn't have such a line, but adding it with correct order did the trick.
    – Levans
    Jan 8, 2014 at 9:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .