Mosh: Fresh mosh install exits immediately with locale errors and "did not find mosh server startup message"

Created on 18 Aug 2016  路  18Comments  路  Source: mobile-shell/mosh

(I am not a Linux person, help a n00b out)

I followed the instructions on the Getting Started page to install mosh locally on my Macbook running OSX and then installed mosh on my Ubuntu server running on Digital Ocean.

I am able to SSH into the box with ssh root@myhostname, but running mosh root@myhostname shows the following:

The locale requested by LC_CTYPE=UTF-8 isn't available here.
Running `locale-gen UTF-8' may be necessary.

The locale requested by LC_CTYPE=UTF-8 isn't available here.
Running `locale-gen UTF-8' may be necessary.

mosh-server needs a UTF-8 native locale to run.

Unfortunately, the local environment (LC_CTYPE=UTF-8) specifies
the character set "US-ASCII",

The client-supplied environment (LC_CTYPE=UTF-8) specifies
the character set "US-ASCII".

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE=UTF-8
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.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=
Connection to hostname closed.
/usr/local/bin/mosh: Did not find mosh server startup message.

How to resolve this?

Most helpful comment

In my case, put these lines in ~/.bashrc
(both on server and local machine)

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

Edit: recently, when I try on another machine, I have to put those line in ~/.profile. So, you should try with ~/.bashrc and ~/.profile

All 18 comments

The message is trying to tell you that your client has the LC_CTYPE environment variable set to "UTF-8", and the server doesn't have any locale by this name. You will have the same problem with ssh, except it will be initially silent and you'll only learn about it when you try to run a locale-sensitive program (when you'll get corrupt output or a warning). Mosh is really eager to avoid letting the user get in a broken situation--hence the verbose error message.

You'll need to figure out where that LC_CTYPE variable is getting set on the client. You don't need it set at all, because you already have LANG=en_US.UTF-8, which is enough. You might open your language preferences and frob them and see what happens. You can run the locale command on the client to see the effects. Good luck!

Ah. You're in South Africa. Perhaps this is coming from complex system language configuration on your Mac?

It'd be interesting to figure out what's going on so we can address this in a FAQ for Mac users. Can you look at a couple of things for us?

  • What's your first "Preferred Language" in System Properties -> Language and Region?
  • Your terminal program may have a different setting. In Terminal, that's Profiles, [your-profile], Advanced, "Text Encoding" (and the "Set locale..." button immediately underneath.
  • Lastly, in terminal, type env | grep ^L[AC] and copy the output along.

try echo LANG=en_US.UTF-8 > /etc/locale.confon both machine

In my case (also in South Africa), after doing export LANG=en_ZA.UTF-8 on the macOS client, and then locale-gen en_ZA.UTF-8 on the Ubuntu server just to be sure, I could mosh to the server without any issues.

In my case, put these lines in ~/.bashrc
(both on server and local machine)

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

Edit: recently, when I try on another machine, I have to put those line in ~/.profile. So, you should try with ~/.bashrc and ~/.profile

In short: My mac had SSH configured to send locales and my Linux server had SSH configured to accept them.

/etc/ssh/sshd_config had

Host *
        SendEnv LANG LC_*

Commenting those lines out fixed the problem.

(Posting this here since this is where Google led me when I had this problem.
Hint for the actual solution was found here:
https://stackoverflow.com/a/29609673/1148030 )

https://askubuntu.com/a/1060694/11857

Those steps work well.

apt-get update
apt-get install -y locales
locale-gen "en_US.UTF-8"
update-locale LC_ALL="en_US.UTF-8"

Log out and log in.

export LC_ALL=en_US.UTF-8

@pelamfi FYI in your comment you have /etc/ssh/sshd_configinstead of /etc/ssh/ssh_config. These are two different files - daemon vs client. Just for random googlers. Thanks!

hi guys, should we provide a clean solution any where else, better on README or homepage, since this error message really punched me a lot.

I'm just new to mosh, and just can't get a quick shot. I've tried a lot in the last one hour, but none of them worked. of course I didn't read through this or any other issue threads carefully. could I get a clean and effective solution to just get my fresh installed mosh worked on a fresh mac os machine?

On WSL 2 adding export LANG=en_US.UTF-8 worked for me

I have en_CA.UTF-8 (canadian english) set on my Arch Linux machine, and I'd prefer to keep it that way if possible. It should be just as "UTF-8 native" as en_US.UTF-8, just with a few different spelling conventions. Is there a way to make this work without changing my default locale?

Sure, it's definitely possible, but if you want to have your client machine's LANG set to en_CA.UTF-8 (or any set of locale-related environment variables), then your server will need a locale built that is retrievable from that set of locale-related environment variables. (This is typically done by running locale-gen or dpkg-reconfigure locales or something similar on the server.) That's true whether you're connecting via Mosh or SSH -- the server needs to speak the same "language" as the client. Mosh is a lot louder about noticing the broken configuration instead of letting it be detected by locale-sensitive applications after the connection is established. But it's not a Mosh-specific problem.

The server also has en_CA.UTF-8 available, and I have run locale-gen on both client and server.

Well, what's the full error message you get from Mosh?

The locale requested by LANG=en_CA.UTF-8 isn't available here.
Running `locale-gen en_CA.UTF-8' may be necessary.

mosh-server needs a UTF-8 native locale to run.

Unfortunately, the local environment ([no charset variables]) specifies
the character set "US-ASCII",

The client-supplied environment (LANG=en_CA.UTF-8) specifies
the character set "US-ASCII".

locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_CA.UTF-8
LC_CTYPE="en_CA.UTF-8"
LC_NUMERIC="en_CA.UTF-8"
LC_TIME=en_GB.UTF-8
LC_COLLATE="en_CA.UTF-8"
LC_MONETARY="en_CA.UTF-8"
LC_MESSAGES="en_CA.UTF-8"
LC_PAPER="en_CA.UTF-8"
LC_NAME="en_CA.UTF-8"
LC_ADDRESS="en_CA.UTF-8"
LC_TELEPHONE="en_CA.UTF-8"
LC_MEASUREMENT="en_CA.UTF-8"
LC_IDENTIFICATION="en_CA.UTF-8"
LC_ALL=

Does the server have to have the global default locale set to the same as the client locale...?

I don't think there really is a "global default locale" in C or POSIX -- in general, your processes are going to set the locale from the locale-related environment variables.

The problem here may be that the client has LANG set to "en_CA.UTF-8" but LC_TIME is set to "en_GB.UTF-8". This doesn't appear to correspond to a locale that exists on the server. You can probably unset LC_TIME on the client and then your locale-aware programs might work. Or you could generate a matching locale on the server...

There it is, unsetting LC_TIME works. Thanks a ton!

In short: My mac had SSH configured to send locales and my Linux server had SSH configured to accept them.

/etc/ssh/sshd_config had

Host *
        SendEnv LANG LC_*

This is what solved the problem for me. My configuration was slightly different though. I had to comment out: AcceptEnv LANG LC_*

From here I learned I was messing with mosh and ssh inner workings. ssh is configured for the client to send all its locale variables for the server to use them. The problem arises when one of the LC* variables does not actually exist in the server.

I just realized that the variable to modify is clearly stated in the error message:

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

My Mac's 'LC_CTYPEwas justUTF-8which was not found in the server, which had onlyen_US.UTF-8` available. Setting in my Mac:

export LC_CTYPE="en_US.UTF-8" 

solved the problem to me .

Was this page helpful?
0 / 5 - 0 ratings