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'
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?
Simply CMD-SHIFT-P then "Remote-SSH: Connect to Host..." and the ssh . config entry you just added is automatically listed - you simply select it and voila, vscode connects to your remote vagrant vm!
The best way to add your pub_key is to use ssh-copy-id binary/command: $ ssh-copy-id -i ~/. ssh/id_rsa. pub -p 2222 vagrant@localhost /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/<username>/.
By default this is port 22. config. ssh.
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$
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_*
you can add your own variables here as needed or use default prefix LC_
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With