How to set global variable visible even for sudo commands?

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
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.
ubuntu environment-variables java maven
add a comment |Â
up vote
1
down vote
favorite
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.
ubuntu environment-variables java maven
Related: What environment do I get with sudo?
â steeldriver
Aug 8 at 23:34
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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.
ubuntu environment-variables java maven
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.
ubuntu environment-variables java maven
ubuntu environment-variables java maven
asked Aug 8 at 23:28
lot
1083
1083
Related: What environment do I get with sudo?
â steeldriver
Aug 8 at 23:34
add a comment |Â
Related: What environment do I get with sudo?
â steeldriver
Aug 8 at 23:34
Related: What environment do I get with sudo?
â steeldriver
Aug 8 at 23:34
Related: What environment do I get with sudo?
â steeldriver
Aug 8 at 23:34
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
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.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
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.
add a comment |Â
up vote
3
down vote
accepted
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.
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
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.
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.
answered Aug 9 at 1:03
slmâ¦
238k65491662
238k65491662
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461404%2fhow-to-set-global-variable-visible-even-for-sudo-commands%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Related: What environment do I get with sudo?
â steeldriver
Aug 8 at 23:34