如何在Vagrant中使用config.ssh.forward_env? [英] How to use config.ssh.forward_env in Vagrant?

查看:216
本文介绍了如何在Vagrant中使用config.ssh.forward_env?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用 config.ssh.forward_env 设置。我在使用Vagrant 1.8.1。这是我的Vagrantfile:

I want certain environment variables from my host system to be visible inside my Vagrant VM, using the config.ssh.forward_env setting. I'm using Vagrant 1.8.1. Here's my Vagrantfile:

Vagrant.configure(2) do |config|
  config.vm.box = 'ubuntu/trusty64'
  config.ssh.forward_env = ['FOO']
end

创建后,我运行了以下命令:

After creating it, I ran these commands:

vagrant up
export FOO=bar
vagrant ssh -c 'echo $FOO'

我预计最后一行输出 bar ,而是输出一个空行(后跟连接到127.0.0.1关闭)。我做错了什么?

I expected the final line to output bar, but instead it outputs a blank line (followed by Connection to 127.0.0.1 closed.). What am I doing wrong?

推荐答案

TL; DR

fhenri@machine$ export LC_MYVAR=TEST
fhenri@machine$ vagrant ssh -c 'echo $LC_MYVAR'
TEST
Connection to 127.0.0.1 closed.
fhenri@machine$ 

如文档所述, config所以为了使用sendEnv传递变量,你必须配置你的主机来接受env变量,默认情况下(希望我的例子),因为.ssh.forward_env 作为 sendEnv 通常的设置允许 LC _ * 通过,您可以查看 / etc / ssh / sshd_config

As said in the doc, config.ssh.forward_env works as sendEnv so to pass variables using sendEnv you must configure your host to accept env variables, by default (and hoping my example above should work) the common setup allows LC_* through, you can review the authorized variables in /etc/ssh/sshd_config

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

您可以根据需要添加您自己的变量,或使用默认前缀LC _

you can add your own variables here as needed or use default prefix LC_

这篇关于如何在Vagrant中使用config.ssh.forward_env?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆