1

https://stackoverflow.com/questions/12996397/command-not-found-when-using-sudo is exactly what I am looking for but none of the answers worked for me. I am using Arch Linux. I am trying to run a command in the present working directory

Workspace$ sudo ./SomeBinary -some_args
sudo: ./<SomeBinary>: command not found
sudo pwd
/home/SomeUser/Workspace

My /etc/sudoers file

Defaults env_keep += "LANG LANGUAGE LINGUAS LC_* _XKB_CHARSET"
Defaults env_keep += "HOME"
Defaults env_keep += "XAPPLRESDIR XFILESEARCHPATH XUSERFILESEARCHPATH"
Defaults env_keep += "QTDIR KDEDIR"
Defaults env_keep += "XDG_SESSION_COOKIE"
Defaults env_keep += "XMODIFIERS GTK_IM_MODULE QT_IM_MODULE QT_IM_SWITCHER"
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Defaults mail_badpass
Defaults log_output
Defaults!/usr/bin/sudoreplay !log_output
Defaults!/usr/local/bin/sudoreplay !log_output
Defaults!REBOOT !log_output

root ALL=(ALL) ALL

%wheel ALL=(ALL) ALL

%sudo   ALL=(ALL:ALL) ALL

#includedir /etc/sudoers.d

I have mounted the working directory with remote directory using sshfs.

sshfs RemoteUbuntu.local:/media/ExtHDD/Workspace ~/Workspace

Remote is BTRFS formated.

closed as unclear what you're asking by jasonwryan, Thomas, schily, Jesse_b, Jeff Schaller Aug 5 '18 at 13:16

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    What's the binary you're trying to run? – slm Aug 5 '18 at 4:22
  • can you ls -l /home/SomeUser/Workspace? Is it possible the binary isn't in that directory? Or maybe you don't have execute permissions on it? – Jesse_b Aug 5 '18 at 12:17
  • If it's a shell script, does the she-bang executor exist? – Jeff Schaller Aug 5 '18 at 13:15
1

There's something else at play here, I suspect with the ./SomeBinary. I ran these two tests on a CentOS 7 box using sudo and they both worked without issue.

$ cat sudy.bash
#!/bin/bash

whoami
echo "hi"
pwd

Which results in this output:

$ sudo ./sudy.bash
root
hi
/home/vagrant

And if I copied the whoami executable to my /home/vagrant directory and ran it:

$ which whoami
/usr/bin/whoami

$ cp /usr/bin/whoami .

$ ll whoami
-rwxr-xr-x 1 vagrant vagrant 28984 Aug  5 00:23 whoami

And when I run it via sudo:

$ sudo ./whoami
root

Command not found

Curiously the only way I could induce that message with sudo is when the execute bit is removed from my sudy.bash script. For example:

$ chmod -x sudy.bash
run as myself
$ ./sudy.bash
-bash: ./sudy.bash: Permission denied
run via sudo
$ sudo ./sudy.bash
sudo: ./sudy.bash: command not found

NOTE: The same thing happens with the copied sudo ./whoami as well.

  • Yeah, My working directory is mounted with sshfs! When I am running it from a plain directory, sudo executes good. Thanks! Can you suggest how to make it work on mounted directory? – Necktwi Aug 5 '18 at 5:20
  • @neckTwi - can you provide the output of df -h . for where you're running sudo? Also why not mention that critical detail in the Q? Seems odd that you wouldn't mention such a pivotal piece of info. – slm Aug 5 '18 at 5:22
  • @neckTwi - what's the sshfs mounting command look like? I mounted a remote directory in this manner and ran whoami over the mounted share and it works fine. – slm Aug 5 '18 at 5:49
  • The executable that's failing is apparently on a mounted sshfs - digitalocean.com/community/tutorials/…. – slm Aug 5 '18 at 6:12
  • My bad, I should have mentioned it. I have updated the question. Thank you! – Necktwi Aug 5 '18 at 6:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.