Skip to content

Instantly share code, notes, and snippets.

@c2h2
Last active January 5, 2026 03:41
Show Gist options
  • Select an option

  • Save c2h2/7ae3396db950f378b7bc9e792a82806c to your computer and use it in GitHub Desktop.

Select an option

Save c2h2/7ae3396db950f378b7bc9e792a82806c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Configure UTF-8 locale for mosh server (run as root)
set -e
[[ $EUID -ne 0 ]] && echo "Please run as root" && exit 1
[[ -f /etc/os-release ]] && . /etc/os-release || { echo "Cannot detect OS"; exit 1; }
echo "==> Configuring UTF-8 locale for mosh on $ID..."
case "$ID" in
ubuntu|debian)
sed -i 's/^# *en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen 2>/dev/null || true
locale-gen en_US.UTF-8
update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 ;;
centos|rhel|fedora)
command -v dnf &>/dev/null && dnf install -y glibc-langpack-en || yum install -y glibc-langpack-en
localectl set-locale LANG=en_US.UTF-8 ;;
arch|manjaro)
sed -i 's/^#en_US.UTF-8/en_US.UTF-8/' /etc/locale.gen
locale-gen && localectl set-locale LANG=en_US.UTF-8 ;;
*)
echo "Unsupported OS: $ID. Run manually: locale-gen en_US.UTF-8" && exit 1 ;;
esac
echo -e "\n==> Locale verification:"
locale -a | grep -i utf-8 || locale -a | grep -i utf8
echo -e "\n✓ Done! Log out and back in for changes to take effect."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment