我正在使用一个名为vlad的产品,它正在与我的Ubuntu服务器进行非交互式的ssh连接,但问题是它看不到任何环境variables。
我一直在疯狂Googlesearch,但无法find解决scheme。 我已经尝试将variables添加到我的服务器上的用户的.ssh / environment文件中,并且还更改/ etc / ssh / sshd_config中的设置,但是没有快乐。
谁能帮忙?
干杯,
克里斯
检查你的/ etc / ssh / ssh_config(在客户端上)并查看SendEnv选项。 在我的情况下,我有SendEnv LANG LC_* 。
man ssh_config中有一些interresting通知
如果你有控制ssh命令本身,你可以尝试这样的事情:
ssh user@remoteserver MYVAR1="$MYVAR1" MYVAR2="$MYVAR2" command
我也使用“tee”(为了视觉清晰)和heredoc发送远程bash脚本:
tee << '+++' | ssh user@remoteserver MYVAR1="$MYVAR1" MYVAR2="$MYVAR2" bash set -x echo "hey, your variable is $MYVAR1" echo "and your other variable is $MYVAR2" +++
你有在服务器上的~/.bashrc定义的环境variables吗? 有时候有些东西会读取~/.profile 。 我做的一个技巧是将~/.profile符号链接到~/.bashrc ,
例如:
ln -s ~/.bashrc ~/.profile
我的猜测是你的环境variables是在错误的文件中。 有两个不同的文件来源于login/交互式shell。
看看这个post:
“login”和“交互式”bash shell之间有什么区别?
编辑:好的,现在用于非交互式login:
你用钥匙login吗? 如果是的话,你可以把它添加到你的authorized_keys文件中:
environment="NAME=value" Specifies that the string is to be added to the environment when logging in using this key. Environment variables set this way override other default environment values. Multiple options of this type are permitted. Environment processing is disabled by default and is controlled via the PermitUserEnvironment option. This option is automatically disabled if UseLogin is enabled.
(从人sshd)
服务器上该用户的shell是什么? 如果是bash,那么包含所有variables的〜/ .bash_profile或〜/ .profile(或类似“./etc/ environment”)应该可以工作。 如果不是bash,考虑改变:)
@Dom(我不能发表评论):对我来说,它正在工作/etc/ssh/sshd_config
AcceptEnv LANG LC_*