Fix Vagrant Locale Bug – Disable “AcceptEnv LANG LC_*” in sshd_config

Vagrant makes it very easy to provision virtual machines for testing.

Incorrect locales are a common problem with some boxes. For example, PostgreSQL ‘createuser’ migth complain about locales, but only when used over ‘vagrant ssh’.

The vagrant box incorrectly accepts client (host system) locale when using ‘vagrant ssh’. This results in errors, such as PostgreSQL ‘createuser’ complaining “perl: warning: Setting locale failed.”. These problems could up in many programs.

Test Environment

Running on an Ubuntu 14.04 LTS amd64 host,

host$ vagrant init ubuntu/trusty32
host$ vagrant up
host$ vagrant ssh

If you have problems starting and installing VirtualBox and Vagrant on Ubuntu 14.04 host, see my fix.

Make Locale Bug Happen

vagrant$ sudo apt-get update
vagrant$ sudo apt-get -y install postgresql
vagrant$ sudo -u postgres createdb $(whoami)
perl: warning: Setting locale failed.

Fix: Comment Out AcceptEnv

A simple fix (that should really be included in the trusty32 box) is to ignore client locale sent by SSH. This is only needed on vagrant, not on real servers. On the vagrant box:

vagrant$ sudoedit /etc/ssh/sshd_config

Find (ctrl-W) the line that allows client to pass locale, and comment it out:

#AcceptEnv LANG LC_*

Reload SSH, then log out and back.

vagrant$ sudo service ssh reload
vagrant$ exit
host$ vagrant ssh


Try the problematic command again

vagrant$ sudo -u postgres createdb $(whoami)

You can see that it runs without problems.

Posted in Uncategorized | Tagged , , , , , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Picks

  • Boxing Clock for AndroidOcton8 Diving T-ShirtsShaking Tower Panda Android GameLearn Chinese with Android
  • Student projects