Linux 使用单个命令通过 ssh 找不到命令,在连接到终端后找到

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10562722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:16:49  来源:igfitidea点击:

Command not found via ssh with single command, found after connecting to terminal

linuxssh

提问by Marek Bardoński

Possible Duplicate:
Why does an SSH remote command get fewer environment variables then when run manually?

可能的重复:
为什么 SSH 远程命令在手动运行时获得的环境变量更少?

If I put command

如果我把命令

ssh user@$IP ant

ssh 用户@$IP 蚂蚁

then I receive

然后我收到

bash: ant: command not found

bash: ant: 命令未找到

but when I log into

但是当我登录时

ssh user@$IP

ssh 用户@$IP

and put

并放

ant

蚂蚁

then work fine.

然后工作正常。

Ant is installed on remote and local machines. Where is the problem?

Ant 安装在远程和本地机器上。问题出在哪儿?

I've tried to find solution in google and found nothing.

我试图在谷歌中找到解决方案,但一无所获。

Thanks in advance for help!

预先感谢您的帮助!

--EDIT--

- 编辑 -

I need to invoke some bash scripts, don't want to change all paths to full path.

我需要调用一些 bash 脚本,不想将所有路径更改为完整路径。

采纳答案by Chris Montanaro

By default profiles aren't loaded when connecting via ssh. To enable this behaviour, set the following option in /etc/ssh/sshd_config:

默认情况下,通过 ssh 连接时不会加载配置文件。要启用此行为,请在 /etc/ssh/sshd_config 中设置以下选项:

PermitUserEnvironment yes

afterward restart ssh

然后重启ssh

/etc/init.d/ssh restart

回答by Benj

Specify the absolute path to ant, if I recall correctly your profile doesn't get run when you run a remote sshcommand.

指定到 的绝对路径ant,如果我没记错的话,当您运行远程ssh命令时,您的配置文件不会运行。