13

I have a problem described here

This problem appears because host machine put locale to guest via ssh.

What is the proper way to solve this?

How I can force vagrant ssh to do this:

LC_ALL=en_US.UTF-8 vagrant ssh

each time?

Community
  • 1
  • 1
kharandziuk
  • 12,020
  • 17
  • 63
  • 121

6 Answers6

18

I propose override host locale in Vagrantfile

Vagrant.configure(2) do |config|

  config.vm.box = "ubuntu/vivid64"

  ENV['LC_ALL']="en_US.UTF-8"

end 

The change is not visible outside Vagrant (host env variables remains unchanged)

michaldo
  • 4,195
  • 1
  • 39
  • 65
  • Please add some explanation to your answer. Code-only answers are generally considered to be of low quality – Tristan Jan 04 '16 at 01:41
  • I guess it works. but there is a question: Can the `ENV['LC_ALL']="en_US.UTF-8"` eventually change something on the host machine? – kharandziuk Jan 04 '16 at 09:58
  • 1
    My host remains unchanged, so I think the change is local only (BTW, I simplified my answer a little) – michaldo Jan 04 '16 at 20:07
1

I had the same problem on OSX (the solution is similar for Linux) when connecting to my Vagrant Ubuntu boxes.

I simply "solved" it by editing /etc/ssh_config (or /etc/ssh/ssh_config on Linux) and commenting the following line:

# SendEnv LANG LC_*

This basically stops ssh from sending the LANG and LC_ALL (all LC_ variables) to the remote host, resulting in using the default on the box. In this case en_US.UTF-8.

Obviously this will cause your remote connections to always use the default locale which may not be what you want.

I believe that you can also set the ssh preferences per host but never did so. I you are interested into that, it might be worth looking.

ereOn
  • 53,676
  • 39
  • 161
  • 238
1

My answer: I just add a line to my ansible playbook. But it isn't an answer in terms of only Vagrant

- name: set locale
  lineinfile: dest=/etc/default/locale line="LC_ALL=C"
kharandziuk
  • 12,020
  • 17
  • 63
  • 121
1
LC_ALL=en_US.UTF-8
LC_CTYPE=en_US.UTF-8

add these lines to ~/.bash_profile of VM, and restart VM via vagrant

Mohammad Shahid Siddiqui
  • 3,730
  • 2
  • 27
  • 12
1

Expanding on Havok's answer, you can make the VM provisioning ensure that a locale (en_US.UTF-8 below) is created, and used whenever you SSH into the VM (by running the necessary shell commands for configuring locales). In the Vagrantfile:

config.vm.provision "shell", inline: <<-EOF
  apt-get update
  apt-get install -y locales  # install locales support
  echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen
  locale-gen  # enable locales in `/etc/locale.gen`
  update-locale LANG=en_US.UTF-8  # setup default VM locale
  sed -i -E 's/^(\s*AcceptEnv\b)/#\1/' /etc/ssh/sshd_config  # avoid SSH overriding it
EOF
0

The proper way is to configure the ssh daemon in the virtual machine to do not accept this environment variables.

Modify in your development environment the file /etc/ssh/sshd_config and comment the AcceptEnv line like this:

$ cat /etc/ssh/sshd_config | grep AcceptEnv
# AcceptEnv LANG LC_*

If you're using Docker as provider you can put in your Dockerfile:

sed -i 's/AcceptEnv/# AcceptEnv/' /etc/ssh/sshd_config

You need to generate and set the default locale too. You can do that with:

# Set the locale
ENV LANG en_US.UTF-8
RUN locale-gen en_US.UTF-8 && update-locale LANG=en_US.UTF-8
Havok
  • 5,776
  • 1
  • 35
  • 44