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?
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?
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)
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.
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"
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
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
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