2012-04-10

zsh, ssh, mosh and environmental fun

I stumbled into a weird problem today trying out mosh
⚫ gbin@local /proc % mosh distant
Could not request local forwarding.
mosh requires a UTF-8 locale.
Connection to **** closed.
I have there my shell set to /bin/zsh on the distant machine. But if I do there :
⚫ gbin@local / % ssh distant
⚫ distant ~ # locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
So why ? I noticed that :
⚫ gbin@local / % ssh distant locale
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
I followed the UTF-8 Gentoo Guide But something subtle is missing in there. "ssh distant command" is loading a zsh environment because it is my default shell but NOT the profile. So if you want to have a basic LANG setting already set to remote execute a command you need to have a /etc/zsh/zshenv set on your remote machine. I stole this from an old zsh ebuild that was doing that correctly :
⚫ gbin@distant zsh % cat /etc/zsh/zshenv 
[[ -e "/etc/profile.env" ]] && source /etc/profile.env
if [[ $(/usr/bin/whoami) == 'root' ]]
then
    export PATH="/bin:/sbin:/usr/bin:/usr/sbin:${ROOTPATH}"
else
    export PATH="/bin:/usr/bin:${PATH}"
fi
unset ROOTPATH
This gonna take your locale settings from the /etc/env.d/02locale as the gentoo doc describes, but this time early enough to have mosh working.

1 comment:

  1. See https://github.com/keithw/mosh/issues/74 , by the way.

    ReplyDelete