3 Ways to Fix SSH Locale Environment Variable Error

3 Ways to Fix SSH Locale Environment Variable Error

3 Ways to Fix SSH Locale Environment Variable Error – Introduction

Fix SSH Locale Environment Variable Error Now!

When attempting to connect to a remote server using SSH (Secure Shell), a problem known as the SSH Locale Environment Variable Error may arise. This error often occurs when the local machine (the client) and the distant server’s locale settings are out of sync.

When the client’s locale settings and the server’s locale settings disagree, problems arise in the processing and presentation of data. Characters that are garbled or wrongly displayed, trouble running certain commands, or problems with scripts and programs that rely on locale-specific settings are some typical indications of this mistake.

Locale’s major groups of environment variables

A locale in Linux is made up of four groups of environment variables.

  • LANGUAGE
  • LC_ALL
  • LC_*:  LC_TYPE, LC_NUMERIC, LC_TIME…
  • LANG

These environment variables specify your Linux distribution’s system language, currency, date/time format, and other settings. To view your locale environment variables, run the locale command in the terminal:

locale

 

Output

LANG=zh_CN.UTF-8

LANGUAGE=zh_CN

LC_CTYPE=”zh_CN.UTF-8″

LC_NUMERIC=en_US.UTF-8

LC_TIME=en_US.UTF-8

LC_COLLATE=”zh_CN.UTF-8″

LC_MONETARY=en_US.UTF-8

LC_MESSAGES=”zh_CN.UTF-8″

LC_PAPER=en_US.UTF-8

LC_NAME=en_US.UTF-8

LC_ADDRESS=en_US.UTF-8

LC_TELEPHONE=en_US.UTF-8

LC_MEASUREMENT=en_US.UTF-8

LC_IDENTIFICATION=en_US.UTF-8

LC_ALL=

 

You see that the result from the previous section includes variables from all four categories.

In Ubuntu’s system settings > language support, you may visually set the LANGUAGE, LANG, and LC_* variables.

Fix SSH Locale Environment Variable Error

The following command may be used in Systemd-based Linux distributions (Debian 8+, Ubuntu 15.04+, Fedora, CentOS7+, and Arch Linux) to set each locale environment variable.

sudo localectl set-locale variable_name=value

For example, set LANG=en_US.UTF-8.

sudo localectl set-locale LANG=en_US.UTF-8

To implement locale changes, a reboot or re-login may be necessary.

SSH Locale Environment Variable Error

The following locale-related error could appear when you ssh into a remote Linux server.

Failed to set locale, defaulting to C

Or

perl: warning: Setting locale failed.

perl: warning: Please check that your locale settings:

LANGUAGE = (unset),

LC_ALL = (unset),

LC_TIME = “zh_CN.UTF-8”,

LC_MONETARY = “zh_CN.UTF-8”,

LC_ADDRESS = “zh_CN.UTF-8”,

LC_TELEPHONE = “zh_CN.UTF-8”,

LC_NAME = “zh_CN.UTF-8”,

LC_MEASUREMENT = “zh_CN.UTF-8”,

LC_IDENTIFICATION = “zh_CN.UTF-8”,

LC_NUMERIC = “zh_CN.UTF-8”,

LC_PAPER = “zh_CN.UTF-8”,

LANG = “en_US.UTF-8”

are supported and installed on your system.

perl: warning: Falling back to the standard locale (“C”).

locale: Cannot set LC_CTYPE to default locale: No such file or directory

locale: Cannot set LC_MESSAGES to default locale: No such file or directory

locale: Cannot set LC_ALL to default locale: No such file or directory

 

Why does this locale error happen? That’s because your SSH client passes your local computer’s locale environment variables to the distant Linux server, which lacks the necessary locale generated.

This happens a lot if you are not a native English speaker. Normally you would configure a non-English language on your local computer, but most Linux servers by default only have the C locale (aka POSIX locale) and English locales generated.

Here are three ways to fix this problem:

  1. 1st Method

You can create the required locales on the Linux server to resolve this problem. On your server, open the /etc/locale.gen file first.

sudo nano /etc/locale.gen

To uncomment, locate the required locale and delete the # symbol. Find the following code to create the zh_CN.UTF-8 locale, for instance:

#zh_CN.UTF-8 UTF-8

Delete the # symbol. Save the document, then exit. then execute the subsequent command to produce it.

sudo locale-gen

To determine which locales to produce, locale-gen consults the /etc/locale.gen file. By uncommenting various lines in that file, you may easily create different locales.

  1. 2nd Method

Your SSH server can be instructed to reject the client locale environment setting. On your Linux server, open the SSH server configuration file.

sudo nano /etc/ssh/sshd_config

Look for the next line.

AcceptEnv LANG LC_*

Make it into

AcceptEnv no

Save the document, then exit. Restart the SSH daemon after that.

sudo systemctl restart ssh

RHEL, CentOS, and Fedora require you to run

sudo systemctl restart sshd

There are many SSH options for locales on Fedora/CentOS servers.

AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES

AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT

AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE

Simply remove all of the comments, then restart the SSH daemon.

  1. 3rd Method

To resolve this issue, we may also turn off SSH locale environment variable forwarding. On your local computer, open the SSH client configuration file.

sudo nano /etc/ssh/ssh_config

Look for this line:

SendEnv LANG LC_*

To comment it out, add a # to the front. Save the document, then exit.

 

Final Thoughts

Now you can Fix SSH Locale Environment Variable Error. If you don’t know what you’re doing, you should never ignore cautions or messages connected to the locale. These are frequently a sign of deeper systemic problems that might not be immediately obvious.

Character encoding, date and time formats, currency symbols, and the language used for messages and prompts are just a few examples of the geographical and linguistic preferences defined by locale settings. During the connection procedure, SSH sends this data between the client and the server.

It required more than a few hops to get to the underlying cause in this example, as is the case with most fascinating errors because the cause and effect were so disjointed. Normally, one would never think that their local machine may be the cause of a remote machine fault. I continue to be surprised by how innocuous the LC_CTYPE=UTF-8 environment option on my computer seems.

Don’t forget to comment which linux commands you liked the most.

You can learn about linux more deeply by clicking the link below

https://linuxiron.com/what-is-linux-a-whole-introduction/

Learn about the linux commands by clicking the links below

https://linuxiron.com/echo-command-in-linux/

https://linuxiron.com/how-to-use-nice-renice-commands-in-linux/

https://linuxiron.com/how-to-use-kill-commands-in-linux/

https://linuxiron.com/a-beginners-guide-to-htop-for-process-management/

https://linuxiron.com/15-useful-yum-commands-in-linux/

https://linuxiron.com/how-to-use-the-top-command-in-linux/

https://linuxiron.com/17-ps-command-to-monitor-linux-process-with-examples-linuxiron/

https://linuxiron.com/12-cat-commands-in-linux-with-examples/

https://linuxiron.com/archiving-and-compressing-files-and-directories-in-linux/

https://linuxiron.com/how-to-run-the-du-command-in-linux/

Q. In SSH, how do you set an environment variable?

Open Edit the system environment variables from the START menu. Choose the environment’s parameters: Choose Edit after selecting your Path system variable. Choose to add a new variable and specify the OpenSSH folder’s location.

Q. How do I change Ubuntu’s local time?

Run the tzselect command in your command-line interface (CLI) or in the Terminal to accomplish this. Then, enter after choosing the preferred timezone. Using the timedatectl command is one of the best ways to change the timezone permanently on Ubuntu.

Q. How do I change the locale in Ubuntu?

The /etc/default/locale file contains the default configurations. You can manually edit this file or use the update-locale utility to make changes. A list of all the LC_* environment variables may be found at. The language of the window manager or user interface is likewise affected by the LC_MESSAGES setting.

Leave a Comment

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