Linux SSH终端显示乱码

Dorimu 发布于 16 天前 24 次阅读


问题描述

  • locale 发现 LANG=C
  • locale 设置为 C 时,系统不会使用 UTF-8 编码,可能导致 GUI 或终端显示异常(如出现 ~A 等乱码字符)。

解决方法

设置正确的 locale 运行以下命令生成并启用 UTF-8 编码的 locale

sudo apt update && sudo apt install locales  # 确保 locales 已安装
sudo dpkg-reconfigure locales

在菜单中选择: en_US.UTF-8(英文 UTF-8) 或 zh_CN.UTF-8(中文 UTF-8)

然后设置环境变量:

echo 'export LANG=en_US.UTF-8' >> ~/.bashrc
echo 'export LC_ALL=en_US.UTF-8' >> ~/.bashrc
source ~/.bashrc

之后重启即可

寻找些有趣的事情......
最后更新于 2025-07-17