15

Clearly my file exists in /usr/bin

$ ls /usr/bin/ngrok
/usr/bin/ngrok

However, when I attempt to chown it I receive an error

$ sudo chown my_user:users /usr/bin/ngrok
chown: cannot dereference '/usr/bin/ngrok': No such file or directory

Further attempts to run it also fail!

$ ngrok
bash: ngrok: command not found
$ sudo /usr/bin/ngrok
sudo: /usr/bin/ngrok: command not found

What is happening here?

  • The third point could happen as well if '/usr/bin/' is not in your PATH. You should have tested with /usr/bin/ngrok to be a complete symmetry of the following case with sudo. – Patrick Mevzek Feb 5 '18 at 16:47
52

/usr/bin/ngrok will be a symlink that points nowhere (or rather to a non-existing file). Check with ls -l.

  • 13
    The "cannot dereference" error is the dead giveaway here. You don't "dereference" a normal file, you open it. – Kevin Feb 5 '18 at 7:13
  • 1
    Or readlink -f /usr/bin/ngrok to find where the link should point to. – Eric Duminil Feb 5 '18 at 13:19
  • or namei -l /usr/bin/ngrok – hanshenrik Feb 6 '18 at 16:09
4

Given the chown error, the most likely possibility is that it's a symlink, as answered by Sven. However, just for reference in case somebody ends up here for cases where the file exists and is not a link, but gives a command-not-found/file-not-found error, one more possibility is that the executable is dynamically linked and for some reason it's not able to load libraries:

  • missing library (run ldd on the binary to see those)
  • missing loader
  • apparmor denying access to a library or loader
  • ...

Also, for a script, if the interpreter in the shebang could not be executed for similar reasons, you'd get the same error.

  • Even more confusing, this can indeed result in an enigmatic "no such file or directory.". – rackandboneman Feb 6 '18 at 10:11
0

You also have the option of changing ownership of the symlink itself with

chown -h my_user:users /usr/bin/ngrok

if you don't wish (or have permission) to change ownership of the target file.

  • 2
    I'm not certain how this answers the question - the question is "What is happening here?" and the problem is that the target file doesn't exist. This doesn't solve the problem and it doesn't answer the question. – wizzwizz4 Feb 5 '18 at 20:57
  • 1
    @wizzwizz4 I suppose you can also interpret the question as "the file does exist (the symlink is a file), why does it tell me otherwise and why can't I change its ownership?" This answer covers that interpretation. Sven's just assumes (probably correctly) the OP wants to work with the target file. – JoL Feb 5 '18 at 22:24
  • 1
    @muru This is not applicable on a Linux system, which does not have permissions for symlinks. Actually, Linux is one of the few (is the only?) of POSIX-family OSes that does have the ability to set symlink owner/group. See the Linux chown(1) man page. Possible reasons Linux does this are discussed at unix.stackexchange.com/questions/33180/… – Andrew Henle Feb 6 '18 at 2:53
  • 2
    @AndrewHenle and how does that help? Changing owner/group for a symlink makes no difference here since the permissions applied when executing are always of the target file. So you could have a link owned by whoever, but changing the ownership on that link makes absolutely no difference to the permissions considered when executing it. – muru Feb 6 '18 at 2:57
  • 1
    @muru and how does that help? Read the question I already linked since it specifically asks: "In linux it's possible to change the owner or the group owner of a symbolic link (symlink). I was wondering why someone would want to do that, since permissions of a symlink are not used when accessing a file through it" – Andrew Henle Feb 6 '18 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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