1

So, i don't understand whats happening here.

I've set up a Debian 10.2 Server and configured like i did before with other Servers. Everything works fine, and because it's a local Machine and i am the only user, i used root for everything. Now i wanted to disable ssh root-login.

But if I use a non-root user to login via SSH, it can't find basic commands like "service" or "reboot". (Bash: Service: Command not found.)

Even stranger, i can't even access those things when i use "su root". I am indeed the root user, but still cannot access/find those commands.

When logged in directly with root-user, everything works as it should.

4
  • The default .profile already does this, and additionally i've tried to set the PATH inside the non-root .profile file, but doesn't work too. I have not changed any PATH before, so why should i have to edit it now? Is there something new to Debian 10? I don't use Sudo.. and it doesn't work with "su root" so why should it work with "su -"
    – Johnny Doe
    Commented Nov 22, 2019 at 14:56
  • 1
    unix.stackexchange.com/questions/35338/… Commented Nov 22, 2019 at 15:04
  • Ok thanks, i got it now. I just have to use "su -" but thats not an explanation why it is like it is.
    – Johnny Doe
    Commented Nov 22, 2019 at 15:06
  • unix.stackexchange.com/questions/232782/…
    – Jeff Schaller
    Commented Nov 22, 2019 at 15:08

1 Answer 1

2

Your user's PATH environment variable does not contain the path where these files are located. When you use su -, root's environment variables get loaded into your session. See man su:

   -, -l, --login
          Start the shell as a login shell with an environment similar
          to a real login:

             o      clears all the environment variables except TERM and
                    variables specified by --whitelist-environment

             o      initializes the environment variables HOME, SHELL,
                    USER, LOGNAME, and PATH

             o      changes to the target user's home directory

             o      sets argv[0] of the shell to '-' in order to make
                    the shell a login shell

To better understand this, let's look at where one of these binaries is, and compare root's PATH with yours:

  1. do su -
  2. do which service. This will tell you where the service binary would be loaded from if you were to run the command service.
  3. do echo $PATH. This will show you root's PATH. You will note that the directory where service can be found is listed here.
  4. do exit to become your non-root user again.
  5. do echo $PATH. You'll see that the directory you identified in step 2 is not here.

This is a normal default setup in certain environments/distros where certain administrative programs like service, fdisk, etc. are kept in a directory such as /usr/sbin or /sbin, with such directories kept off of normal users' PATHs.

1

You must log in to answer this question.

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