2

ifconfig is located in /sbin/ifconfig. I don't have problem issuing ifconfig command in root user.

The problem started when I created a new user.

root@Ubuntu:~# useradd -m user
root@Ubuntu:~#

root@Ubuntu:~# passwd user
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
root@Ubuntu:~# 

root@Ubuntu:~# su user
user@Ubuntu:/root$ id
uid=1003(user) gid=1003(user) groups=1003(user)
user@Ubuntu:/root$ 

ifconfig is not found in the new user.

user@Ubuntu:~$ ifconfig
-su: ifconfig: command not found
user@Ubuntu:~$ 

Temporary workaround is execute it from full path /sbin/ifconfig

user@Ubuntu:~$ whereis ifconfig
ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz
user@Ubuntu:~$ 

user@Ubuntu:~$ /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr AA:AA:AA:AA:AA:AA
          inet addr:10.0.0.1  Bcast:10.0.0.255  Mask:255.255.255.0
user@Ubuntu:~$

ifconfig was not found as /sbin is no longer configured in the new user environment.

user@Ubuntu:~$ echo $PATH
/home/user/bin:/home/user/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin
user@Ubuntu:~$ 

user@Ubuntu:~$ echo $PATH | grep sbin
user@Ubuntu:~$ 

I don't see this issue on root user as /sbin is part of $PATH by default.

root@Ubuntu:~# ifconfig 
eth0      Link encap:Ethernet  HWaddr AA:AA:AA:AA:AA:AA
          inet addr:10.0.0.1  Bcast:10.0.0.255  Mask:255.255.255.0

root@Ubuntu:~# echo $PATH | grep sbin
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
root@Ubuntu:~# 
  1. The question is why /sbin is not included by default? Doesn't this make things harder for user?

  2. How to make sure /sbin is added automatically in $PATH instead of modifying it manually for each users?

5
  • How did you create the user? What is the output of cat /etc/environment?
    – pa4080
    Nov 3, 2017 at 16:46
  • Thanks @pa4080 for your feedback. useradd -m <newuser> .bashrc .bash_history .bash_logout .profile also been created. user@Ubuntu:~$ cat /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" user@Ubuntu:~$ Nov 3, 2017 at 16:48
  • 2
    Possibly the behaviour you are seeing is because (by default) useradd sets the user's login shell as /bin/sh rather than /bin/bash Nov 3, 2017 at 16:57
  • @steeldriver Default shell for new user is /bin/bash However I don't see this in /etc/passwd user@Ubuntu:~$ echo $SHELL /bin/bash user@Ubuntu:~$ user@Ubuntu:~$ egrep 'ubuntu|user' /etc/passwd ubuntu:x:1000:1000:Ubuntu:/home/ubuntu:/bin/bash user:x:1002:1002::/home/user: user@Ubuntu:~$ Nov 3, 2017 at 17:09
  • @CharlotteRussell how exactly are you logging in to the root account? There appears to be a potential issue whereby su - and/or su -l does not cause pam_env to read /etc/environment. See for example Why doesn't su - re-read /etc/environment? Nov 3, 2017 at 17:12

1 Answer 1

5

The /sbin directory is for system maintenance and/or administrative tools. So only administrators are allowed to use it and you don't have this directory in your $PATH. You can read more in the Filesystem Hierarchy Standard FHS.

The right place to add new value to $PATH variable are user's ~/.profile file or system /etc/profile file. Usually there is already a line with $PATH so you need just to add /sbin to the start of the line. Or just add this line at the end of the file:

PATH="/sbin:$PATH"

Also you can edit /etc/skel/.profile file. This file will be copied to a user's home directory when you create a new one. But if you want to have this feature for all users, change /etc/profile.

3
  • I guess this is implied in this answer but not explicit: non-root user should not need sbin in their path. sudo will be able to find the binary; tab-completion works as well. If not then there is a bug in Ubuntu. Apr 6, 2020 at 3:54
  • @FranklinYu tab completion does not work if the program is only in an sbin folder which is not on the PATH. How would it work ? May 8, 2020 at 13:12
  • 1
    @CiprianTomoiagă It works on Debian. Note that by “work” I mean that tab completion will check binaries in sbin only when completing commands starting with sudo. May 9, 2020 at 4:01

You must log in to answer this question.

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