"Command not found" when using ssh and non absolute commands

Probably, your $PATH doesn't include /usr/local/bin. Since this is ssh, there are three approaches that come to mind:

  1. If PermitUserEnvironment is enabled in the sshd config, you ought to be able to set PATH in ~/.ssh/environment (that's a file in your home directory on the server — the NAS).

  2. If you can edit the sshd config, then you should be able to use SetEnv PATH=/bin:/usr/bin:/usr/local/bin (etc.) to set a path. At least if it's using OpenSSH.

  3. It's possible you could use the ssh client's SetEnv option to send the server a PATH, depending on the server config. You could set this in your ~/.ssh/config file, on your client machine.

Note that both OpenSSH server and client config files can have options limited to particular clients/servers. For example, in the client config, you could do something like this:

Host myhost
    SetEnv PATH=/bin:/usr/bin:/usr/local/bin

to only do that for one server. Note that block continues until the next block starts (e.g, another Host … block) — the indenting is just for visual clarity.

OpenSSH config files are documented in the ssh_config and sshd_config manual pages.


Ok so on further investigation I noticed that on all of my other hosts mycommand is indeed in /usr/bin not in /usr/local/bin. The reason for this is, that every package manager has installed it in /usr/bin except for the weird "software store" (or whatever it is called) from synology.

I went the "dirty" way and just created a symlink: /usr/bin/mycommand > /usr/local/bin/mycommand:

ln -s /usr/local/bin/mycommand /usr/bin/mycommand

Now for everyone facing a similar problem: there is a reason why a /usr/local/bin exists and there might be risks with my solution. But it's the easiest and fastest and I already spent way to much time on this problem. In my situation all ssh-keys will be limited anyways to one command only so I don't really care.

Anyways: if you want to read more about the difference between those two locations I recommend this post: https://askubuntu.com/a/308048