The problem is most likely caused by the fact that LC_CTYPE is somehow, somewhere set to "UTF-8", which is not a valid locale name. So you need to figure out how it happens and delete that incorrect setting.

Answer from Gunnar Hjalmarsson on askubuntu.com
🌐
LinuxBabe
linuxbabe.com › home › 3 ways to fix ssh locale environment variable error
3 Ways to Fix SSH Locale Environment Variable Error - LinuxBabe
March 26, 2021 - AcceptEnv LANG LC_CTYPE LC_NUMERIC ... Simply comment out all of them and restart SSH daemon. We can also disable SSH locale environment variable forwarding to fix this error....
Discussions

Python locale error: unsupported locale setting - Stack Overflow
222 How to set the locale inside a Debian/Ubuntu Docker container? 256 pip install - locale.Error: unsupported locale setting More on stackoverflow.com
🌐 stackoverflow.com
How to fix a locale setting warning from Perl - Stack Overflow
When I run perl, I get the warning: perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LANG = "en_US.UTF... More on stackoverflow.com
🌐 stackoverflow.com
opensuse - Failed to set locale. Fix your system - Unix & Linux Stack Exchange
A 32-bit server with openSUSE Tumbleweed: While logging in, I received this warning: /usr/bin/manpath: can't set the locale; make sure $LC_* and $LANG are correct To fix the above error, I run th... More on unix.stackexchange.com
🌐 unix.stackexchange.com
bash - How not to pass the locale through an ssh connection command - Stack Overflow
I have some aliases for ssh, example: alias buildWork="ssh work '~/build_app'" The problem is that the ssh command passes some variables like $LC_CTYPE that causes some errors. How to pr... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Satyanash
satyanash.net › software › 2020 › 05 › 29 › locale-issues-ssh-into-a-vm.html
Locale issues when SSHing into a VM - Satyajeet Kanetkar
May 29, 2020 - Change or remove the AcceptEnv directive which is set to the below value, by default: # remove/change/comment this line: AcceptEnv LANG LC_* You will of course, need to reload the sshd daemon for the changes to take effect. This is the ideal solution, as it allows you complete control over what default locales are used by your users and is also isolated from the the behaviour of individual ssh clients.
Top answer
1 of 16
630

Here is how to solve it on Mac OS X v10.7 (Lion) or Cygwin (Windows 10):

Add the following lines to your bashrc or bash_profile file on the host machine:

# Setting for the new UTF-8 terminal support in Lion
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

If you are using Z shell (zsh), edit file zshrc:

# Setting for the new UTF-8 terminal support in Lion
LC_CTYPE=en_US.UTF-8
LC_ALL=en_US.UTF-8
2 of 16
571

Your OS doesn't know about en_US.UTF-8.

You didn't mention a specific platform, but I can reproduce your problem:

% uname -a
OSF1 hunter2 V5.1 2650 alpha
% perl -e exit
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LC_ALL = (unset),
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

My guess is you used ssh to connect to this older host from a newer desktop machine. It's common for /etc/ssh/sshd_config to contain

AcceptEnv LANG LC_*

which allows clients to propagate the values of those environment variables into new sessions.

The warning gives you a hint about how to squelch it if you don't require the full-up locale:

% env LANG=C perl -e exit
%

or with Bash:

$ LANG=C perl -e exit
$ 

For a permanent fix, choose one of

  1. On the older host, set the LANG environment variable in your shell's initialization file.
  2. Modify your environment on the client side, e.g., rather than ssh hunter2, use the command LANG=C ssh hunter2.
  3. If you have administrator rights, stop ssh from sending the environment variables by commenting out the SendEnv LANG LC_* line in the local /etc/ssh/ssh_config file. (Thanks to this answer. See Bug 1285 for OpenSSH for more.)
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › using the raspberry pi › troubleshooting
Trouble with setting Locale settings - Raspberry Pi Forums
November 12, 2023 - LANGUAGE does not need to be set unless you want to list multiple options in order of preference. In GNU systems, de_DE without .UTF-8 implies ISO-8859-1, which is not what you want and is the main reason for the errors. Are you connecting by SSH from a non-GNU system, passing in environment variables that do not make any sense to Raspberry Pi OS?
Top answer
1 of 7
190

That's because your locale in your local machine is set to German, which SSH forwards to and tries to use on the server, but your server does not have it installed.

You've got several options:

  • Generate the locale. Generate the German locale on the server with sudo locale-gen de.

  • Stop forwarding locale from the client. Do not forward the locale environment variable from your local machine to the server. You can comment out the SendEnv LANG LC_* line in the local /etc/ssh/ssh_config file.

  • Stop accepting locale on the server. Do not accept the locale environment variable from your local machine to the server. You can comment out the AcceptEnv LANG LC_* line in the remote /etc/ssh/sshd_config file.

  • Set the server locale to English. Explicitly set the locale to English on the server. As an example, you can add the following lines to your remote ~/.bashrc or ~/.profile files:

    export LANGUAGE="en"
    export LANG="C"
    export LC_MESSAGES="C"
    

If you don't have root access to the server, the Stop forwarding locale from the client option might be the best (and only) way to go.

2 of 7
31

This can happen sometimes on fresh minimal/alternate installs or in other situations. The fix is pretty simple. Try these, in the following order, testing after each to see if the situation is fixed:

1. Reconfigure locales

  • sudo dpkg-reconfigure locales
    • if that doesn't work,

2. Reinstall locale language-pack

  • sudo apt-get --reinstall install language-pack-de
    • if that doesn't work,

3. Manually force locale settings (persistent)

  • sudo update-locale LC_ALL=de_DE.UTF-8 LANG=de_DE.UTF-8
Top answer
1 of 1
5

The easiest way to "prevent" the exporting of the environment is to overwrite them in your user account on the server side. To do so you can create a .bashrc file (or the appropriate initialization file for your shell) and overwrite the unwanted variables.

example minimal .bashrc file:

unset LC_TIME

alternatively set the variable to some sane value:

export LC_TIME=en_US.UTF-8

If you really want to prevent sending some of environment variables then you will most likely need root access on the client and/or the server machine.

On the client side you can edit /etc/ssh/ssh_config and remove or alter the SendEnv line. Most distributions today have that set up to send the locale environment variables (LC_*).

There is a user config file (~/.ssh/config) where you can also set SendEnv. But there you can only append to the list from the system config file, not overwrite. That is why you can only truly disable this option when you have root access.

Alternatively, on the server side you can edit /etc/ssh/sshd_config (note the extra d at sshd_config. the d stands for daemon) and remove or alter the AcceptEnv line. Most distributions today have that set up to accept the locale environment variables (LC_*).

Look up the explanations for SendEnv in the man page for ssh_config and AcceptEnv in the man page for sshd_config.

For the sake of completeness: there is also a PermitUserEnvironment in sshd_config. As the name says, it allows the user to set up some files which will initialize some variables. If PermitUserEnvironment is enabled you can take care of the rest as user, but I have never encountered a system with PermitUserEnvironment enabled.

Find elsewhere
🌐
cPanel
support.cpanel.net › hc › en-us › articles › 360047756234-How-to-fix-perl-warning-Setting-locale-failed
How to fix "perl: warning: Setting locale failed" – cPanel
November 5, 2024 - Perl: warning: Please check that your locale settings: LANGUAGE = "", LC_ALL = (unset), LANG = "en_US.UTF-8 LC_ALL=en_US.UTF-8" are supported and installed on your system. Perl: warning: Falling back to the standard locale ("C"). One way to work around this without having to change your client machine's language settings is by simply specifying the variables directly before your SSH connection.
🌐
Galdin Raphael
galdin.dev › blog › fixing-that-weird-locale-error-when-sshing-to-a-server
Fixing that weird locale error when SSHing to a server | Galdin Raphael
August 23, 2018 - perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LC_CTYPE = "UTF-8", LANG = "C" are supported and installed on your system. perl: warning: Falling back to the ...
🌐
codestudy
codestudy.net › blog › linode-lish-bash-warning-setlocale-lc-all-cannot-change-locale-en-us-utf-8
Fixing 'bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)' in Linode Lish When Copying Disks Over SSH — codestudy.net
If you’ve worked with Linode’s Lish (Linode Shell) or SSH to manage your Linode instances, you may have encountered the warning: `bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)`. This error typically appears when copying disks over SSH (e.g., using `dd`, `scp`, or ...
🌐
GitHub
github.com › warpdotdev › Warp › issues › 406
SSH: avoiding setlocale warning on remote hosts · Issue #406 · warpdotdev/Warp
November 12, 2021 - Usual workaround in Terminal.app and iTerm2 includes disabling the environment variable transmission in preferences and setting the locale in the remote .bashrc or rely on the default configuration.
Author   serasset
🌐
DEV Community
dev.to › yugabyte › ssh-and-warning-setlocale-lcctype-cannot-change-locale-utf-8-no-such-file-or-directory-5cnf
ssh and 'warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory' - DEV Community
May 22, 2022 - This post is about when you encounter the following dreaded line after applying an update on Mac OSX when logging into a linux system with ssh: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory · This is just a message, and it allows you to carry on. However, much that uses "locales" (language specifics) can stop functioning, or generate errors.