简体   繁体   English

找不到ssh环境变量bash命令

[英]ssh environment variable bash command not found

I try to start some command from ssh non-interactive ssh connection. 我尝试从ssh 非交互式 ssh连接启动一些命令。 I use ant-sshexec connection for that. 我为此使用ant-sshexec连接。

In order to set everything up I used this article: http://www.raphink.info/2008/09/forcing-environment-in-ssh.html 为了进行所有设置,我使用了这篇文章: http : //www.raphink.info/2008/09/forcing-environment-in-ssh.html

I use ~/.ssh/environment. 我使用〜/ .ssh / environment。 In order to do that, I set PermitUserEnvironment to "yes" in sshd_config and restarted sshd. 为此,我在sshd_config中将PermitUserEnvironment设置为“ yes”,然后重新启动sshd。

In my .ssh/environment I have this content: 在我的.ssh / environment中,我具有以下内容:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/ubuntu/java/jdk1.6.0_27/bin

JAVA_HOME=/home/ubuntu/java/jdk1.6.0_27

#PATH=/home/ubuntu/java/jdk1.6.0_27/bin:$PATH

#PLAY_HOME=/home/ubuntu/play

and I have the error when try to connect using non-interactive connection: 当尝试使用非交互式连接进行连接时出现错误:

 [sshexec] Could not execute the java executable, please make sure the JAVA_HOME environment variable is set properly (the java executable should reside at JAVA_HOME/bin/java). 

But I added the java to the path.. 但是我在路径中添加了Java。

The man page for sshd(8) says this about ~/.ssh/environment : sshd(8)的手册页介绍了有关~/.ssh/environment

    It can only contain empty lines, comment lines (that start with
    ‘#’), and assignment lines of the form name=value.

That is, it is not a shell script at all. 也就是说,它根本不是shell脚本。 You have double quotes, variable expansion and an alias definition. 您有双引号,变量扩展和别名定义。 None of that will work. 这些都不起作用。 Try this: 尝试这个:

PATH=/home/ubuntu/java/jdk1.6.0_27/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
JAVA_HOME=/home/ubuntu/java/jdk1.6.0_27
PLAY_HOME=/home/ubuntu/play

Also ensure that the permissions on the ~/.ssh/environment are as described in the man page — no group or other write permissions on the file. 另外,还要确保~/.ssh/environment上的权限与手册页中所述的一样-文件上没有组权限或其他写权限。

If you are concerned with locking yourself out of the account with a broken environment, test by logging onto the host first and running test commands such like this: 如果您担心在损坏的环境中将自己锁定在帐户之外,请先登录到主机并运行如下测试命令,以进行测试:

ssh localhost 'echo $JAVA_HOME'

You can ensure that the environment variables are set as you expect them and if something goes wrong, you are still logged onto the host allowing you to reverse your changes. 您可以确保按照预期设置环境变量,并且如果出现问题,仍可以登录到主机,以撤消更改。

You used multiple environement variable for path . 您对path使用了多个环境变量。 But don't export from command what i see. 但是不要从命令中导出我所看到的。

You should do it like that way. 您应该那样做。

export PATH="A"
export PATH="$PATH:B"
export PATH="$PATH:C"

Also you can get this type of help from there. 您也可以从那里获得此类帮助。 So please post it to unix. 因此,请将其发布到Unix。

https://unix.stackexchange.com/questions/12391/how-to-run-my-c-program-from-anywhere-within-the-system-ubuntu-10-10 https://unix.stackexchange.com/questions/12391/how-to-run-my-c-program-from-anywhere-within-the-system-ubuntu-10-10

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM