问题原文
原帖链接 · Silver · CC BY-SA 3.0
Suppose I have two hosts: A and B with users a and b. B is Windows machine with Cygwin installed, if this matters.
B is configured to be accessed from A through SSH without password (it contains A's public RCA key), so I can run commands on it from A in the following way:
ssh b@B [command]
But when I try to run a command, that requires to access an environment variable, the command fails:
[15:54:08] - a@A - ~
$ ssh b@B 'echo $ANT_HOME'
returns empty string.
The same command, if connected directly (not through SSH) is executed correctly:
b@B ~
$ echo $ANT_HOME
/cygdrive/c/PROGRA~1/apache-ant-1.9.0
The latter is possible because the relevant variables were exported in "bash_profile":
export JAVA_HOME="/cygdrive/c/PROGRA~1/Java/jdk1.7.0_45"
export ANT_HOME="/cygdrive/c/PROGRA~1/apache-ant-1.9.0"
but for some reason this is not applied to the SSH case.
Some additional info that may be useful.
Host B has Windows XP + Cygwin. CYGWIN sshd is run under SYSTEM account. JAVA_HOME and ANT_HOME are defined in "system" environment variables part in Windows.
When I run "$ ssh b@B env" command, it does not print ANT_HOME or JAVA_HOME, but if I include them in sshd_config file, it does. But even then simple command ssh b@B 'echo $ANT_HOME' does not work as I would expect.
Please give me a hint what needs to be done to run the command through SSH.
已采纳解答
原帖链接 · periket2000 · CC BY-SA 4.0
From the man pages of my server:
- Reads the file ~/.ssh/environment, if it exists, and users are allowed to change their environment. See the PermitUserEnvironment option in sshd_config(5).
You need to declare the environment variables and allow them in the remote server location /etc/ssh/sshd_config, by enabling the property PermitUserEnvironment as PermitUserEnvironment yes and set your environment variables in ~/.ssh/environment.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
