sudo problems
I am running RedHat server with .NET Core 2.1.
I can happily run dotnet commands such as dotnet build, dotnet run etc.
However, if I try and sudo dotnet as in : sudo dotnet run I get the error sudo: dotnet: command not found.
Can anyone suggest why this is happening.
Andy
Responses
Hi Andrew,
What does "sudo -l" shows? This would show which commands user could run using sudo. Also, check if you could run commands using sudo with complete path to the binaries, something like "sudo /usr/bin/myprogram" and check if that works, if so, then it could be due to path parameter not properly for that user.
One thing that I don't understand here is that when you could run command without using "sudo" then why do you use sudo?
If there is path problem then you may set/correct the PATH variable defined in the file ".bash_profile" under user home directory for any local user. For example, if i wish to include "mybin" directory under path so that I can run those commands from any where within my user account, then I'd add "$HOME/mybin" to the PATH variable and then either logout-login or source this file. After which "echo $PATH" would show this "/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/redhat/.local/bin:/home/redhat/bin:/home/redhat/mybin". Now, I could run binaries or executable defined under "mybin" directory without specifying path.
I hope this helps.
Hi Andrew,
I guess I was able to trace it out. It is because of the "secure_path" parameter that has been set in "/etc/sudoers" file which by defaults looks for binaries in "/sbin:/bin:/usr/sbin:/usr/bin" path only, so appending additional paths to this would work. As I've tested this on my vm.
For testing purpose, I have created a file "list-files" (script) to list out files under "mybin" folder in my users home directory (/home/redhat) and path has been set as appropriate:
<AnsibleCoding>id
uid=1000(redhat) gid=1000(redhat) groups=1000(redhat),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
<AnsibleCoding>echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/redhat/.local/bin:/home/redhat/bin:/home/redhat/mybin
The script works when called anywhere inside my home directory, however, doesn't when called with sudo, since 'sudo' was looking out for the binary inside the "secure_path" location:
<AnsibleCoding>list-files
total 64
drwx------. 6 redhat redhat 205 Oct 10 21:09 .
drwxr-xr-x. 5 root root 44 Oct 10 15:25 ..
drwxrwxr-x. 12 redhat redhat 4096 Sep 25 06:46 ansible-project
-rw-------. 1 redhat redhat 23110 Oct 10 21:11 .bash_history
-rw-r--r--. 1 redhat redhat 18 Mar 7 2017 .bash_logout
-rw-r--r--. 1 redhat redhat 234 Oct 10 12:30 .bash_profile
-rw-r--r--. 1 redhat redhat 231 Mar 7 2017 .bashrc
drwxrwxr-x. 2 redhat redhat 24 Oct 10 21:09 mybin
drwx------. 2 redhat redhat 57 Sep 12 07:40 .ssh
-rw-------. 1 redhat redhat 9004 Oct 10 21:09 .viminfo
-rw-r--r--. 1 root root 47 Sep 11 13:44 .vimrc
Calling user : redhat
<AnsibleCoding>sudo list-files
sudo: list-files: command not found
<AnsibleCoding>logout
[root@localhost ~]# grep secure_path /etc/sudoers
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
So appending the required path would work. However, please be careful, as this would get executed as root user.
After modifications of "secure_path" parameter in '/etc/sudoers' file:
[root@localhost ~]# grep secure_path /etc/sudoers
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/home/redhat/mybin
[root@localhost ~]# su - redhat
Last login: Wed Oct 10 21:12:02 EDT 2018 on pts/1
<AnsibleCoding>sudo list-files
total 64
drwx------. 6 redhat redhat 205 Oct 10 21:09 .
drwxr-xr-x. 5 root root 44 Oct 10 15:25 ..
drwxrwxr-x. 12 redhat redhat 4096 Sep 25 06:46 ansible-project
-rw-------. 1 redhat redhat 22896 Oct 10 21:16 .bash_history
-rw-r--r--. 1 redhat redhat 18 Mar 7 2017 .bash_logout
-rw-r--r--. 1 redhat redhat 234 Oct 10 12:30 .bash_profile
-rw-r--r--. 1 redhat redhat 231 Mar 7 2017 .bashrc
drwxrwxr-x. 2 redhat redhat 24 Oct 10 21:09 mybin
drwx------. 2 redhat redhat 57 Sep 12 07:40 .ssh
-rw-------. 1 redhat redhat 9004 Oct 10 21:09 .viminfo
-rw-r--r--. 1 root root 47 Sep 11 13:44 .vimrc
Calling user : root
I hope this helps you.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
