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

Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
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
add a comment |
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
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
shell ssh sshd synology
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
Probably, your $PATH doesn't include /usr/local/bin. Since this is ssh, there are three approaches that come to mind:
If
PermitUserEnvironmentis enabled in the sshd config, you ought to be able to setPATHin~/.ssh/environment(that's a file in your home directory on the server — the NAS).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.It's possible you could use the ssh client's
SetEnvoption to send the server a PATH, depending on the server config. You could set this in your~/.ssh/configfile, 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.
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Probably, your $PATH doesn't include /usr/local/bin. Since this is ssh, there are three approaches that come to mind:
If
PermitUserEnvironmentis enabled in the sshd config, you ought to be able to setPATHin~/.ssh/environment(that's a file in your home directory on the server — the NAS).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.It's possible you could use the ssh client's
SetEnvoption to send the server a PATH, depending on the server config. You could set this in your~/.ssh/configfile, 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.
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
add a comment |
Probably, your $PATH doesn't include /usr/local/bin. Since this is ssh, there are three approaches that come to mind:
If
PermitUserEnvironmentis enabled in the sshd config, you ought to be able to setPATHin~/.ssh/environment(that's a file in your home directory on the server — the NAS).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.It's possible you could use the ssh client's
SetEnvoption to send the server a PATH, depending on the server config. You could set this in your~/.ssh/configfile, 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.
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
add a comment |
Probably, your $PATH doesn't include /usr/local/bin. Since this is ssh, there are three approaches that come to mind:
If
PermitUserEnvironmentis enabled in the sshd config, you ought to be able to setPATHin~/.ssh/environment(that's a file in your home directory on the server — the NAS).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.It's possible you could use the ssh client's
SetEnvoption to send the server a PATH, depending on the server config. You could set this in your~/.ssh/configfile, 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.
Probably, your $PATH doesn't include /usr/local/bin. Since this is ssh, there are three approaches that come to mind:
If
PermitUserEnvironmentis enabled in the sshd config, you ought to be able to setPATHin~/.ssh/environment(that's a file in your home directory on the server — the NAS).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.It's possible you could use the ssh client's
SetEnvoption to send the server a PATH, depending on the server config. You could set this in your~/.ssh/configfile, 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.
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
add a comment |
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
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Jan 9 at 10:49
answered Jan 9 at 9:41
SimonSimon
215
215
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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