Add sbin to user PATH in Debian

Debian does not add sbin to your path by default. I have no idea why. I know sbin is supposed to be administrative tools that you would only want to run as root, however, there are some useful ones that don't require root, and even if they need root, why hide them from useful tools like auto complete?

Apparentely it's not a new disucssion - this Debian mailing list thread dates back to a decade ago!

Regardless, I want it in my path - the easiest way that I've found is to modify the top of /etc/profile to remove the if statement that sets path if you're user id 0 (root) or not:

Before:

if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/games"
fi


After:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"


Save the file, log out and log back in and you're all set. Note that this affects all users on your system.

Comments

Thomas said…
Hi,
thanks for posting.

I have just a small extension to fix this issue for 'non-login xterms in Debian Wheezy'. It took hours to figure this out, which is the main reason for this comment.
The solution was to do equivalent changes also in /etc/login.defs .

#
# /etc/login.defs , Debian 7.0
#
# *REQUIRED* The default PATH settings, for superuser and normal users.
ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

Regards,
Thomas
Ernesto Ongaro said…
Thanks Thomas, appreciate the feedback
Anonymous said…
Good post! Is there a way to add a path line for just one other user, and not for everyone?
Anonymous said…
Anonymous: @Aug 5. 2013

You can accomplish this by editing your /home/user/.profile.
Thomas said…
Hi again,

as in February 2013, Google guided me 1st to your side.
By now - since Debian 7.1 - the sbin-problem occurs again.
Maybe I did something wrong, but nothing seem to fix the PATH anymore.


So, here is a piece of code for ~/.bashrc.
The 1st line replaces one string by another - simple, but works.
The 2nd part ensures that sbins are in PATH, and also may add some other bin-dirs (entries are only added, if (1) directory exists and (2) not already included).

Regards,
Thomas

#
# ~/.bashrc
# should be sourced by ~/.profile
#
# a simple way to solve the sbin-path-problem is to replace the string
# "/usr/local/bin:/usr/bin:/bin" by
# "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# and that's it.
PATH=$(echo $PATH | sed s/'\/usr\/local\/bin:\/usr\/bin:\/bin'/'\/usr\/local\/sbin:\/usr\/local\/bin:\/usr\/sbin:\/usr\/bin:\/sbin:\/bin'/)
#
# 2nd part
# you may want to add additional bin-dirs ("/usr/lib/gmt/bin", "$HOME/bin" in my case),
# and/or ensure, that the sbins are in the PATH necessarily
#
for dir in "/usr/lib/gmt/bin" "/sbin" "/usr/sbin" "/usr/local/sbin" "$HOME/bin"
do
if [ -d "$dir" ] ; then
if ! $(echo ":$PATH:" | grep -q ":$dir:") ; then
PATH="$dir:$PATH"
fi
fi
done
unset dir


#
# ~/.profile
#
# something like the following should be present
#
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
#
# 2013-10-03: moved to ~/.bashrc
#
# set PATH so it includes user's private bin if it exists
# if [ -d "$HOME/bin" ] ; then
# PATH="$HOME/bin:$PATH"
# fi
#
Thomas said…
Hello Ernesto,
I want to correct my post above, and sorry for capturing your blog.

In a fresh installed wheezy:
"$HOME/bin" is set correctly - no need to edit ~./profile, nor to add it ~/.bashrc
My box don't do so, but anyway.

Regards,
Thomas

Popular posts from this blog

Dealing with Nested Documents in MongoDB and Talend (aka Baking a Cake)

Batch convert Asterisk GSM WAV files to mp3