“Command not found” when using ssh and non absolute commands

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












2















I want to use a command over ssh:



ssh myuser@myhost mycommand


but doing so I always get:



sh: mycommand: command not found


using following obviously works:



ssh myuser@myhost /usr/local/bin/mycommand


and i understand why: it's because the command is somehow executed over a non-login shell.



Using the full command or any other parameters in my ssh command is not an option in my scenario. My command is executed by a script I cannot touch and worked on every host yet except this one.



The host that's giving me the problem is a Synology NAS and the /etc/passwd setting for that myuser is:



myuser:x:1048:100::/var/services/homes/myuser:/bin/sh



Again:



I can:



  • ssh as myuser into myhost

  • execute as myuser using the absolute path provided by which
    mycommand


  • execute mycommand (non absolute) when already on myhost (via ssh)

I can't but want:



  • execute: ssh myuser@myhost mycommand (non absolute, no additional
    parameters)









share|improve this question
























  • Linking in the related: unix.stackexchange.com/a/15212/117549

    – Jeff Schaller
    Jan 8 at 17:25











  • I know you don't want extra parameters, but if you can relent on that requirement (and assuming your login shell is bash) -> ssh user@host bash -lic mycommand

    – glenn jackman
    Jan 8 at 17:48















2















I want to use a command over ssh:



ssh myuser@myhost mycommand


but doing so I always get:



sh: mycommand: command not found


using following obviously works:



ssh myuser@myhost /usr/local/bin/mycommand


and i understand why: it's because the command is somehow executed over a non-login shell.



Using the full command or any other parameters in my ssh command is not an option in my scenario. My command is executed by a script I cannot touch and worked on every host yet except this one.



The host that's giving me the problem is a Synology NAS and the /etc/passwd setting for that myuser is:



myuser:x:1048:100::/var/services/homes/myuser:/bin/sh



Again:



I can:



  • ssh as myuser into myhost

  • execute as myuser using the absolute path provided by which
    mycommand


  • execute mycommand (non absolute) when already on myhost (via ssh)

I can't but want:



  • execute: ssh myuser@myhost mycommand (non absolute, no additional
    parameters)









share|improve this question
























  • Linking in the related: unix.stackexchange.com/a/15212/117549

    – Jeff Schaller
    Jan 8 at 17:25











  • I know you don't want extra parameters, but if you can relent on that requirement (and assuming your login shell is bash) -> ssh user@host bash -lic mycommand

    – glenn jackman
    Jan 8 at 17:48













2












2








2








I want to use a command over ssh:



ssh myuser@myhost mycommand


but doing so I always get:



sh: mycommand: command not found


using following obviously works:



ssh myuser@myhost /usr/local/bin/mycommand


and i understand why: it's because the command is somehow executed over a non-login shell.



Using the full command or any other parameters in my ssh command is not an option in my scenario. My command is executed by a script I cannot touch and worked on every host yet except this one.



The host that's giving me the problem is a Synology NAS and the /etc/passwd setting for that myuser is:



myuser:x:1048:100::/var/services/homes/myuser:/bin/sh



Again:



I can:



  • ssh as myuser into myhost

  • execute as myuser using the absolute path provided by which
    mycommand


  • execute mycommand (non absolute) when already on myhost (via ssh)

I can't but want:



  • execute: ssh myuser@myhost mycommand (non absolute, no additional
    parameters)









share|improve this question
















I want to use a command over ssh:



ssh myuser@myhost mycommand


but doing so I always get:



sh: mycommand: command not found


using following obviously works:



ssh myuser@myhost /usr/local/bin/mycommand


and i understand why: it's because the command is somehow executed over a non-login shell.



Using the full command or any other parameters in my ssh command is not an option in my scenario. My command is executed by a script I cannot touch and worked on every host yet except this one.



The host that's giving me the problem is a Synology NAS and the /etc/passwd setting for that myuser is:



myuser:x:1048:100::/var/services/homes/myuser:/bin/sh



Again:



I can:



  • ssh as myuser into myhost

  • execute as myuser using the absolute path provided by which
    mycommand


  • execute mycommand (non absolute) when already on myhost (via ssh)

I can't but want:



  • execute: ssh myuser@myhost mycommand (non absolute, no additional
    parameters)






shell ssh sshd synology






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 10 at 19:07









Rui F Ribeiro

39.6k1479132




39.6k1479132










asked Jan 8 at 17:09









SimonSimon

215




215












  • Linking in the related: unix.stackexchange.com/a/15212/117549

    – Jeff Schaller
    Jan 8 at 17:25











  • I know you don't want extra parameters, but if you can relent on that requirement (and assuming your login shell is bash) -> ssh user@host bash -lic mycommand

    – glenn jackman
    Jan 8 at 17:48

















  • Linking in the related: unix.stackexchange.com/a/15212/117549

    – Jeff Schaller
    Jan 8 at 17:25











  • I know you don't want extra parameters, but if you can relent on that requirement (and assuming your login shell is bash) -> ssh user@host bash -lic mycommand

    – glenn jackman
    Jan 8 at 17:48
















Linking in the related: unix.stackexchange.com/a/15212/117549

– Jeff Schaller
Jan 8 at 17:25





Linking in the related: unix.stackexchange.com/a/15212/117549

– Jeff Schaller
Jan 8 at 17:25













I know you don't want extra parameters, but if you can relent on that requirement (and assuming your login shell is bash) -> ssh user@host bash -lic mycommand

– glenn jackman
Jan 8 at 17:48





I know you don't want extra parameters, but if you can relent on that requirement (and assuming your login shell is bash) -> ssh user@host bash -lic mycommand

– glenn jackman
Jan 8 at 17:48










2 Answers
2






active

oldest

votes


















2














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.






share|improve this answer

























  • Thank you for your very detailed answer! Especially 1 and 2 look very promissing. I should have mentioned that I have root rights on host and can edit whatever I want. I guess that for 1 I need to set the enviroment for each user on host. I'll give it a test in a few hours when I'm back in the network.

    – Simon
    Jan 8 at 20:39











  • @Simon #2 is a system-wide one, so if you need it for a bunch of users, that's probably the option you want to pick. At least if you can edit the config (no idea what Synology allows).

    – derobert
    Jan 8 at 20:59











  • thanks again for your answer, I started to investigate the reason why I even have this problem to begin with and I decided to go another, more simplier but maybe also dirtier (?) way. (see my answer)

    – Simon
    Jan 9 at 9:42


















1














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






share|improve this answer
























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493287%2fcommand-not-found-when-using-ssh-and-non-absolute-commands%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    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.






    share|improve this answer

























    • Thank you for your very detailed answer! Especially 1 and 2 look very promissing. I should have mentioned that I have root rights on host and can edit whatever I want. I guess that for 1 I need to set the enviroment for each user on host. I'll give it a test in a few hours when I'm back in the network.

      – Simon
      Jan 8 at 20:39











    • @Simon #2 is a system-wide one, so if you need it for a bunch of users, that's probably the option you want to pick. At least if you can edit the config (no idea what Synology allows).

      – derobert
      Jan 8 at 20:59











    • thanks again for your answer, I started to investigate the reason why I even have this problem to begin with and I decided to go another, more simplier but maybe also dirtier (?) way. (see my answer)

      – Simon
      Jan 9 at 9:42















    2














    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.






    share|improve this answer

























    • Thank you for your very detailed answer! Especially 1 and 2 look very promissing. I should have mentioned that I have root rights on host and can edit whatever I want. I guess that for 1 I need to set the enviroment for each user on host. I'll give it a test in a few hours when I'm back in the network.

      – Simon
      Jan 8 at 20:39











    • @Simon #2 is a system-wide one, so if you need it for a bunch of users, that's probably the option you want to pick. At least if you can edit the config (no idea what Synology allows).

      – derobert
      Jan 8 at 20:59











    • thanks again for your answer, I started to investigate the reason why I even have this problem to begin with and I decided to go another, more simplier but maybe also dirtier (?) way. (see my answer)

      – Simon
      Jan 9 at 9:42













    2












    2








    2







    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.






    share|improve this answer















    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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 8 at 17:57

























    answered Jan 8 at 17:50









    derobertderobert

    73k8153210




    73k8153210












    • Thank you for your very detailed answer! Especially 1 and 2 look very promissing. I should have mentioned that I have root rights on host and can edit whatever I want. I guess that for 1 I need to set the enviroment for each user on host. I'll give it a test in a few hours when I'm back in the network.

      – Simon
      Jan 8 at 20:39











    • @Simon #2 is a system-wide one, so if you need it for a bunch of users, that's probably the option you want to pick. At least if you can edit the config (no idea what Synology allows).

      – derobert
      Jan 8 at 20:59











    • thanks again for your answer, I started to investigate the reason why I even have this problem to begin with and I decided to go another, more simplier but maybe also dirtier (?) way. (see my answer)

      – Simon
      Jan 9 at 9:42

















    • Thank you for your very detailed answer! Especially 1 and 2 look very promissing. I should have mentioned that I have root rights on host and can edit whatever I want. I guess that for 1 I need to set the enviroment for each user on host. I'll give it a test in a few hours when I'm back in the network.

      – Simon
      Jan 8 at 20:39











    • @Simon #2 is a system-wide one, so if you need it for a bunch of users, that's probably the option you want to pick. At least if you can edit the config (no idea what Synology allows).

      – derobert
      Jan 8 at 20:59











    • thanks again for your answer, I started to investigate the reason why I even have this problem to begin with and I decided to go another, more simplier but maybe also dirtier (?) way. (see my answer)

      – Simon
      Jan 9 at 9:42
















    Thank you for your very detailed answer! Especially 1 and 2 look very promissing. I should have mentioned that I have root rights on host and can edit whatever I want. I guess that for 1 I need to set the enviroment for each user on host. I'll give it a test in a few hours when I'm back in the network.

    – Simon
    Jan 8 at 20:39





    Thank you for your very detailed answer! Especially 1 and 2 look very promissing. I should have mentioned that I have root rights on host and can edit whatever I want. I guess that for 1 I need to set the enviroment for each user on host. I'll give it a test in a few hours when I'm back in the network.

    – Simon
    Jan 8 at 20:39













    @Simon #2 is a system-wide one, so if you need it for a bunch of users, that's probably the option you want to pick. At least if you can edit the config (no idea what Synology allows).

    – derobert
    Jan 8 at 20:59





    @Simon #2 is a system-wide one, so if you need it for a bunch of users, that's probably the option you want to pick. At least if you can edit the config (no idea what Synology allows).

    – derobert
    Jan 8 at 20:59













    thanks again for your answer, I started to investigate the reason why I even have this problem to begin with and I decided to go another, more simplier but maybe also dirtier (?) way. (see my answer)

    – Simon
    Jan 9 at 9:42





    thanks again for your answer, I started to investigate the reason why I even have this problem to begin with and I decided to go another, more simplier but maybe also dirtier (?) way. (see my answer)

    – Simon
    Jan 9 at 9:42













    1














    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






    share|improve this answer





























      1














      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






      share|improve this answer



























        1












        1








        1







        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






        share|improve this answer















        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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 9 at 10:49

























        answered Jan 9 at 9:41









        SimonSimon

        215




        215



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493287%2fcommand-not-found-when-using-ssh-and-non-absolute-commands%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)