16

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?

ti7
  • 215
  • 2
  • 9
Jorik
  • 177
  • 1
  • 3
  • 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 05 '18 at 16:47

3 Answers3

52

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

Sven
  • 98,649
  • 14
  • 180
  • 226
5

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.

muru
  • 589
  • 8
  • 26
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.

weasel5i2
  • 125
  • 2
  • 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 05 '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 05 '18 at 22:24
  • This is not applicable on a Linux system, which does not have permissions for symlinks. – muru Feb 06 '18 at 01:41
  • 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](http://man7.org/linux/man-pages/man1/chown.1.html). Possible reasons Linux does this are discussed at https://unix.stackexchange.com/questions/33180/why-change-the-owner-of-a-symbolic-link-in-linux/33181 – Andrew Henle Feb 06 '18 at 02: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 06 '18 at 02:57
  • 1
    @muru *and how does that help?* Read [the question I already linked](https://unix.stackexchange.com/questions/33180/why-change-the-owner-of-a-symbolic-link-in-linux/33181) 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 06 '18 at 08:53
  • 1
    @AndrewHenle OK, let me rephrase: how does that help *here*? – muru Feb 06 '18 at 08:56
  • 1
    @muru Your statement "This is not applicable on a Linux system" is wrong. – Andrew Henle Feb 06 '18 at 10:53
  • 1
    @AndrewHenle He already admitted that. But applying that to a Linux system does not help anyway. – glglgl Feb 06 '18 at 10:56
  • @glglgl Read the question that I linked for some answers as to how permissions and ownership of a symlink might be useful (not very, IMO, but someone else might think differently) – Andrew Henle Feb 06 '18 at 11:03
  • 1
    @AndrewHenle Again, this is quite interesting, but not useful for the OP which wonders why their ngrok doesn't exist although it seems to exist. That is what was meant with _here_. – glglgl Feb 06 '18 at 11:08
  • @AndrewHenle that is only part of my statement. The rest didn't vanish into thin air. – muru Feb 06 '18 at 11:10