1

I have installed Maven on Ubuntu 16.04 following instructions.

I edited /etc/environmentand added path to maven/bin folder to $PATH variable.

Under my normal user everything works just fine, but when I try to run e.g. sudo mvn test it tells me that mvn is unknown command. Restart didn't help.

Error:

/bin/sh: 1: mvn: not found

I am also little perplexed by /bin/sh piece - I am using bash.

So where should I put path to maven binary to make even sudo commands see it? Thank you.

lot
  • 113

1 Answers1

3

When using sudo your $PATH is getting overridden for security reasons by a line like this in your /etc/sudoers file:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

Example

Even though an entry such as this is present in /etc/environment:

$ cat /etc/environment
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/tmp

And it appears to be picked up:

$ sudo env | grep PATH
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/tmp

And we have a script in /tmp:

$ ls -l /tmp/blah.bash
-rwxrwxr-x 1 vagrant vagrant 20 Aug  8 20:57 /tmp/blah.bash

And this script will print whoami when run:

$ cat /tmp/blah.bash
#!/bin/bash

whoami

Sudo won't let us do it:

$ sudo blah.bash
sudo: blah.bash: command not found

Changing sudo's secure path

But if I edit my /etc/sudoers file:

$ sudo visudo
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/tmp

Now it works:

$ sudo blah.bash
root

Security

Think long and hard about why you're adding additional directories to sudo's secure path. This is set up like this for a very good reason. Do not take lightly the addition of extra paths for sudo commands!

Adding extra directories exposes you and your users to additional risks which you many not realize until it's too late.

slm
  • 369,824