Running programs as sudo doesn't work












1















Installing tools and other using command line in Ubuntu 18.04 with sudo works perfectly.
example: sudo apt install ... works perfectly.
Running tools and programs via the command line as sudo doesn't work at all.
Running the same programs and tools as normal user works perfectly.
Example: start gtkwave as normal user makes the gtkwave GUI pop up.
Start gtkwave as sudo, asks for password and then ends in:
sudo: gtkwave: command not found.



I must say that some tools invoked on the command line as sudo work flawlessly, for example I can start Atom from the command line as a normal user and as sudo.



Is this maybe because the tools/programs not running as sudo are not installed in the common Linux folders like /bin or /usr/bin but as programs under /opt (these are added to the path and have necessary environments set)?



Does anybody have any idea why this happens?










share|improve this question

























  • can you do an echo $PATH with and without sudo and check if the path has the library needed to run the program?

    – blvdeer
    Dec 28 '18 at 16:43






  • 1





    If gtkwave works normal user then why are you trying to run it as root user? Again was it designed to work with sudo?

    – George Udosen
    Dec 28 '18 at 16:43
















1















Installing tools and other using command line in Ubuntu 18.04 with sudo works perfectly.
example: sudo apt install ... works perfectly.
Running tools and programs via the command line as sudo doesn't work at all.
Running the same programs and tools as normal user works perfectly.
Example: start gtkwave as normal user makes the gtkwave GUI pop up.
Start gtkwave as sudo, asks for password and then ends in:
sudo: gtkwave: command not found.



I must say that some tools invoked on the command line as sudo work flawlessly, for example I can start Atom from the command line as a normal user and as sudo.



Is this maybe because the tools/programs not running as sudo are not installed in the common Linux folders like /bin or /usr/bin but as programs under /opt (these are added to the path and have necessary environments set)?



Does anybody have any idea why this happens?










share|improve this question

























  • can you do an echo $PATH with and without sudo and check if the path has the library needed to run the program?

    – blvdeer
    Dec 28 '18 at 16:43






  • 1





    If gtkwave works normal user then why are you trying to run it as root user? Again was it designed to work with sudo?

    – George Udosen
    Dec 28 '18 at 16:43














1












1








1








Installing tools and other using command line in Ubuntu 18.04 with sudo works perfectly.
example: sudo apt install ... works perfectly.
Running tools and programs via the command line as sudo doesn't work at all.
Running the same programs and tools as normal user works perfectly.
Example: start gtkwave as normal user makes the gtkwave GUI pop up.
Start gtkwave as sudo, asks for password and then ends in:
sudo: gtkwave: command not found.



I must say that some tools invoked on the command line as sudo work flawlessly, for example I can start Atom from the command line as a normal user and as sudo.



Is this maybe because the tools/programs not running as sudo are not installed in the common Linux folders like /bin or /usr/bin but as programs under /opt (these are added to the path and have necessary environments set)?



Does anybody have any idea why this happens?










share|improve this question
















Installing tools and other using command line in Ubuntu 18.04 with sudo works perfectly.
example: sudo apt install ... works perfectly.
Running tools and programs via the command line as sudo doesn't work at all.
Running the same programs and tools as normal user works perfectly.
Example: start gtkwave as normal user makes the gtkwave GUI pop up.
Start gtkwave as sudo, asks for password and then ends in:
sudo: gtkwave: command not found.



I must say that some tools invoked on the command line as sudo work flawlessly, for example I can start Atom from the command line as a normal user and as sudo.



Is this maybe because the tools/programs not running as sudo are not installed in the common Linux folders like /bin or /usr/bin but as programs under /opt (these are added to the path and have necessary environments set)?



Does anybody have any idea why this happens?







command-line 18.04 sudo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 16:45









karel

58k12128146




58k12128146










asked Dec 28 '18 at 16:39









defossezdefossez

365




365













  • can you do an echo $PATH with and without sudo and check if the path has the library needed to run the program?

    – blvdeer
    Dec 28 '18 at 16:43






  • 1





    If gtkwave works normal user then why are you trying to run it as root user? Again was it designed to work with sudo?

    – George Udosen
    Dec 28 '18 at 16:43



















  • can you do an echo $PATH with and without sudo and check if the path has the library needed to run the program?

    – blvdeer
    Dec 28 '18 at 16:43






  • 1





    If gtkwave works normal user then why are you trying to run it as root user? Again was it designed to work with sudo?

    – George Udosen
    Dec 28 '18 at 16:43

















can you do an echo $PATH with and without sudo and check if the path has the library needed to run the program?

– blvdeer
Dec 28 '18 at 16:43





can you do an echo $PATH with and without sudo and check if the path has the library needed to run the program?

– blvdeer
Dec 28 '18 at 16:43




1




1





If gtkwave works normal user then why are you trying to run it as root user? Again was it designed to work with sudo?

– George Udosen
Dec 28 '18 at 16:43





If gtkwave works normal user then why are you trying to run it as root user? Again was it designed to work with sudo?

– George Udosen
Dec 28 '18 at 16:43










1 Answer
1






active

oldest

votes


















1














By default, sudo searches for programs using its own secure_path that is defined in the /etc/sudoers file. From man sudoers:




 secure_path   Path used for every command run from sudo.  If you don't
trust the people running sudo to have a sane PATH environ‐
ment variable you may want to use this. Another use is if
you want to have the “root path” be separate from the “user
path”. Users in the group specified by the exempt_group
option are not affected by secure_path. This option is not
set by default.



Note that in spite of the last line there, the default Ubuntu /etc/sudoers does set it:



Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"


so neither the invoking user's PATH nor root's PATH will effect whether programs are located when using sudo.



If you really want programs in locations such as /opt to be executable via sudo, you will need to either




  • use the full path e.g. sudo /opt/somepath/bin/prog


  • modify the sudoers secure_path to include the locations - if you decide to do this, please use sudo visudo to catch any syntax errors (else you risk locking yourself out of sudo altogether).



However, you should probably read Why should users never use normal sudo to start graphical applications? before proceeding.






share|improve this answer
























  • Thanks for the explication! very helpful.

    – defossez
    Dec 29 '18 at 17:38











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1105164%2frunning-programs-as-sudo-doesnt-work%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














By default, sudo searches for programs using its own secure_path that is defined in the /etc/sudoers file. From man sudoers:




 secure_path   Path used for every command run from sudo.  If you don't
trust the people running sudo to have a sane PATH environ‐
ment variable you may want to use this. Another use is if
you want to have the “root path” be separate from the “user
path”. Users in the group specified by the exempt_group
option are not affected by secure_path. This option is not
set by default.



Note that in spite of the last line there, the default Ubuntu /etc/sudoers does set it:



Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"


so neither the invoking user's PATH nor root's PATH will effect whether programs are located when using sudo.



If you really want programs in locations such as /opt to be executable via sudo, you will need to either




  • use the full path e.g. sudo /opt/somepath/bin/prog


  • modify the sudoers secure_path to include the locations - if you decide to do this, please use sudo visudo to catch any syntax errors (else you risk locking yourself out of sudo altogether).



However, you should probably read Why should users never use normal sudo to start graphical applications? before proceeding.






share|improve this answer
























  • Thanks for the explication! very helpful.

    – defossez
    Dec 29 '18 at 17:38
















1














By default, sudo searches for programs using its own secure_path that is defined in the /etc/sudoers file. From man sudoers:




 secure_path   Path used for every command run from sudo.  If you don't
trust the people running sudo to have a sane PATH environ‐
ment variable you may want to use this. Another use is if
you want to have the “root path” be separate from the “user
path”. Users in the group specified by the exempt_group
option are not affected by secure_path. This option is not
set by default.



Note that in spite of the last line there, the default Ubuntu /etc/sudoers does set it:



Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"


so neither the invoking user's PATH nor root's PATH will effect whether programs are located when using sudo.



If you really want programs in locations such as /opt to be executable via sudo, you will need to either




  • use the full path e.g. sudo /opt/somepath/bin/prog


  • modify the sudoers secure_path to include the locations - if you decide to do this, please use sudo visudo to catch any syntax errors (else you risk locking yourself out of sudo altogether).



However, you should probably read Why should users never use normal sudo to start graphical applications? before proceeding.






share|improve this answer
























  • Thanks for the explication! very helpful.

    – defossez
    Dec 29 '18 at 17:38














1












1








1







By default, sudo searches for programs using its own secure_path that is defined in the /etc/sudoers file. From man sudoers:




 secure_path   Path used for every command run from sudo.  If you don't
trust the people running sudo to have a sane PATH environ‐
ment variable you may want to use this. Another use is if
you want to have the “root path” be separate from the “user
path”. Users in the group specified by the exempt_group
option are not affected by secure_path. This option is not
set by default.



Note that in spite of the last line there, the default Ubuntu /etc/sudoers does set it:



Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"


so neither the invoking user's PATH nor root's PATH will effect whether programs are located when using sudo.



If you really want programs in locations such as /opt to be executable via sudo, you will need to either




  • use the full path e.g. sudo /opt/somepath/bin/prog


  • modify the sudoers secure_path to include the locations - if you decide to do this, please use sudo visudo to catch any syntax errors (else you risk locking yourself out of sudo altogether).



However, you should probably read Why should users never use normal sudo to start graphical applications? before proceeding.






share|improve this answer













By default, sudo searches for programs using its own secure_path that is defined in the /etc/sudoers file. From man sudoers:




 secure_path   Path used for every command run from sudo.  If you don't
trust the people running sudo to have a sane PATH environ‐
ment variable you may want to use this. Another use is if
you want to have the “root path” be separate from the “user
path”. Users in the group specified by the exempt_group
option are not affected by secure_path. This option is not
set by default.



Note that in spite of the last line there, the default Ubuntu /etc/sudoers does set it:



Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"


so neither the invoking user's PATH nor root's PATH will effect whether programs are located when using sudo.



If you really want programs in locations such as /opt to be executable via sudo, you will need to either




  • use the full path e.g. sudo /opt/somepath/bin/prog


  • modify the sudoers secure_path to include the locations - if you decide to do this, please use sudo visudo to catch any syntax errors (else you risk locking yourself out of sudo altogether).



However, you should probably read Why should users never use normal sudo to start graphical applications? before proceeding.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 28 '18 at 22:48









steeldriversteeldriver

66.4k11107179




66.4k11107179













  • Thanks for the explication! very helpful.

    – defossez
    Dec 29 '18 at 17:38



















  • Thanks for the explication! very helpful.

    – defossez
    Dec 29 '18 at 17:38

















Thanks for the explication! very helpful.

– defossez
Dec 29 '18 at 17:38





Thanks for the explication! very helpful.

– defossez
Dec 29 '18 at 17:38


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1105164%2frunning-programs-as-sudo-doesnt-work%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Mont Emei

Province de Neuquén

Journaliste