LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 04-18-2024, 04:29 AM   #1
cmk77
Member
 
Registered: May 2006
Location: netherlands
Distribution: debian, rocky, slackware
Posts: 131

Rep: Reputation: 25
why is /usr/sbin not in root's path?


I've been using debian bullseye for a while now and noticed that /usr/sbin is not by default in root's path, contrary to other distros. This leads some (third-party) scripts to fail, for instance because they cannot find ldconfig. What, if any, would be the reason debian ommits /usr/sbin from root's path?

Code:
$ whoami
root
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
$

Last edited by cmk77; 04-18-2024 at 04:34 AM.
 
Old 04-18-2024, 04:59 AM   #2
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 51

Rep: Reputation: 0
I used to use the following at windows (CYGWIN bash.exe)
~/.bashrc file:
Code:
$ /usr/bin/gawk.exe '{ if( ( 8 <= NR ) && ( 11 >= NR ) )  { print $0 } }'  ~/.bash_profile
if [[ -f ~/.bashrc ]]]
then
        . ~/.bashrc
fi
Few contents inside ~/.bashrc file:
Code:
if [[ -d /usr/sbin ]]
then
        echo "$PATH" | /usr/bin/grep -E "^/usr/sbin:|:/usr/sbin:|:/usr/sbin$" 2>&1 |\
        /usr/bin/grep -E -v "^$" >/dev/null 2>&1
        Ret=$?
        if [[ 0 -ne $Ret ]]
        then
                export PATH="/usr/sbin:$PATH"
        fi
fi
if [[ -d /usr/bin ]]
then
        echo "$PATH" | /usr/bin/grep -E "^/usr/bin:|:/usr/bin:|:/usr/bin$" 2>&1 |\
        /usr/bin/grep -E -v "^$" >/dev/null 2>&1
        Ret=$?
        if [[ 0 -ne $Ret ]]
        then
                export PATH="/usr/bin:$PATH"
        fi
fi
if [[ -d /bin ]]
then
        echo "$PATH" | /usr/bin/grep -E "^/bin:|:/bin:|:/bin$" 2>&1 |\
        /usr/bin/grep -E -v "^$" >/dev/null 2>&1
        Ret=$?
        if [[ 0 -ne $Ret ]]
        then
                export PATH="/bin:$PATH"
        fi
fi
if [[ -d /sbin ]]
then
        echo "$PATH" | /usr/bin/grep -E "^/sbin:|:/sbin:|:/sbin$" 2>&1 |\
        /usr/bin/grep -E -v "^$" >/dev/null 2>&1
        Ret=$?
        if [[ 0 -ne $Ret ]]
        then
                export PATH="/sbin:$PATH"
        fi
fi
I agree that we can similar kind of changes inside /etc/bash.bashrc using root(Windows Admin) user.
 
Old 04-18-2024, 05:14 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,719

Rep: Reputation: 5911Reputation: 5911Reputation: 5911Reputation: 5911Reputation: 5911Reputation: 5911Reputation: 5911Reputation: 5911Reputation: 5911Reputation: 5911Reputation: 5911
I am guessing you are using su to login as root. su still uses the user's path environment but su - switches to root's environment. debian does not add /usr/sbin to the user's path while others do.
 
1 members found this post helpful.
Old 04-18-2024, 06:47 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,313
Blog Entries: 3

Rep: Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723
Yes, if you are switching to root using su then you will need the -l option to start with an environment similar to a real root login.
 
Old 04-18-2024, 09:16 AM   #5
cmk77
Member
 
Registered: May 2006
Location: netherlands
Distribution: debian, rocky, slackware
Posts: 131

Original Poster
Rep: Reputation: 25
Indeed, I was using su without flags, thanks for clarifying.
- debian does have /usr/sbin in root's path (but not in a user's path)
- su without -l preserves that user's environment
 
Old 04-18-2024, 11:10 AM   #6
_blackhole_
Member
 
Registered: Mar 2023
Distribution: FreeBSD
Posts: 88

Rep: Reputation: 67
Quote:
Originally Posted by cmk77 View Post
What, if any, would be the reason debian ommits /usr/sbin from root's path?
Absolutely no idea, but it's just annoying. There are certain commands in /sbin you may want to run as a normal user (such as ifconfig).

In Debian, my method is to set the $PATH variable early in ~/.profile as follows:

Code:
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
[...]
Log out and back in.

Even when the path is set as above, you should still su to root as follows in order to use root's environment:
Code:
$ su -l
 
Old Yesterday, 07:30 PM   #7
friendlysalmon8827
Member
 
Registered: Dec 2023
Distribution: Anfroid,Debian
Posts: 93

Rep: Reputation: 5
The reason that certain utilities and system programs aren't directly in the root or super users' path is because the /sbin folder is a symbolic link back to the user sbin folder.
 
Old Yesterday, 07:50 PM   #8
murugesandins
Member
 
Registered: Apr 2024
Location: Bangalore Karnataka India
Distribution: CYGWIN_NT
Posts: 51

Rep: Reputation: 0
~/.bashrc or ~/.mkshrc or ~/.kshrc for all users including root

Quote:
Originally Posted by cmk77 View Post
Indeed, I was using su without flags, thanks for clarifying.
- debian does have /usr/sbin in root's path (but not in a user's path)
- su without -l preserves that user's environment
if I am facing this issue:
I should have added following code inside ~/.bashrc or ~/.kshrc or ~/.mkshrc based on different OS
for all users including root user
Code:
OS=$(/usr/bin/uname -s 2>&1 | /usr/bin/sed "s/-[0-9]*\.[0-9]*\-[0-9]*//;")
case $OS in
        "Linux")
                if [[ -f /usr/bin/grep ]]
                then
                        EGREP="/usr/bin/grep -E"
                elif [[ -f /usr/bin/egrep ]]
                then
                        EGREP="/usr/bin/egrep"
                fi
                ;;
        "SunOS")
                if [[ -f /usr/bin/grep ]]
                then
                        EGREP="/usr/bin/grep -E"
                elif [[ -f /usr/bin/egrep ]]
                then
                        EGREP="/usr/bin/egrep"
                fi
                ;;
        "AIX")
                if [[ -f /usr/bin/grep ]]
                then
                        EGREP="/usr/bin/grep -E"
                elif [[ -f /usr/bin/egrep ]]
                then
                        EGREP="/usr/bin/egrep"
                fi
                ;;
        "HP-UX")
                if [[ -f /usr/bin/grep ]]
                then
                        EGREP="/usr/bin/grep -E"
                elif [[ -f /usr/bin/egrep ]]
                then
                        EGREP="/usr/bin/egrep"
                fi
                ;;
        "CYGWIN_NT")
                if [[ -f /usr/bin/grep ]]
                then
                        EGREP="/usr/bin/grep -E"
                elif [[ -f /usr/bin/egrep ]]
                then
                        EGREP="/usr/bin/egrep"
                fi
                ;;
        *)
                #echo use related path to grep
                if [[ -f /usr/bin/grep ]]
                then
                        EGREP="/usr/bin/grep -E"
                elif [[ -f /usr/bin/egrep ]]
                then
                        EGREP="/usr/bin/egrep"
                fi
                ;;
esac
if [[ -d /usr/sbin ]]
then
        echo $PATH 2>&1 |\
        $EGREP "^/usr/sbin:|:/usr/sbin:|:/usr/sbin$" >/dev/null 2>&1
        Ret=$?
        if [[ 0 -ne $Ret ]]
        then
                export PATH="/usr/sbin:$PATH"
        else #DEBUG01
                echo "\$PATH having /usr/sbin" #DEBUG02
        fi
else #DEBUG03
        /usr/bin/ls -ltrd /usr/sbin #DEBUG04
fi
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/usr/sbin/httpd: symbol lookup error: /usr/sbin/httpd: undefined symbol: apr_atomic_x dasoberdick Slackware 16 10-11-2014 02:36 AM
/usr/sbin/pmi and /usr/sbin/hibernate Woodsman Slackware 1 08-31-2013 10:41 PM
Error: Cannot find 'ssh-keygen' in '/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin' venu.navat Linux - Software 3 03-08-2012 04:00 AM
/bin, /sbin, /usr/bin, /usr/sbin - why are there 4? EmrldDrgn Linux - Newbie 3 11-18-2008 09:59 PM
As root, not seeing /sbin and /usr/sbin in path weghman Linux - Newbie 3 04-25-2004 01:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 05:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration