在安装Solaris中文版后,许多用户都会遇到一个令人困扰的问题——通过SSH远程连接时,终端显示的中文全部变成乱码,导致无法正常操作。实际上,问题的根本原因在于系统的默认语言配置,只需将locale切换为英文模式即可有效解决。下面直接提供具体操作步骤,简洁明了。
首先,需要开启配置文件的写入权限,因为默认情况下该文件是只读的:
#chmod u+w /etc/default/init
接着,使用vi编辑器打开该文件:
#vi /etc/default/init
文件内容大致如下(版本注释等信息无需关注,重点看后续几行):
#
# Copyright 1992, 1999-2002 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#ident "@(#)init.dfl 1.7 02/12/03 SMI"
#
# This file is /etc/default/init. /etc/TIMEZONE is a symlink to this file.
# This file looks like a shell script, but it is not. To maintain
# compatibility with old versions of /etc/TIMEZONE, some shell constructs
# (i.e., export commands) are allowed in this file, but are ignored.
#
# Lines of this file should be of the form VAR=value, where VAR is one of
# TZ, LANG, CMASK, or any of the LC_* environment variables. value may
# be enclosed in double quotes (") or single quotes (').
#
TZ=PRC
CMASK=022
LANG=EN //设置为英文语言
#LANG=zh_CN.UTF-8 //原默认中文配置,已注释掉
核心修改只有两处:将 LANG 的值改为 EN(代表英文),同时将原本默认的 zh_CN.UTF-8 那一行注释掉。保存文件后重启系统,再次通过SSH连接,中文乱码问题便会自然消失。
这个实用技巧在众多Sun/Oracle老系统上依然有效,尤其是那些仍在运行Solaris 10甚至更早版本的环境。实测表明,修改后所有终端输出都切换为英文,既避免了编码冲突,也提升了远程管理的便捷性。当然,如果你希望保留中文界面同时解决乱码,则需要另行配置SSH客户端的编码设置,但那属于另一个话题了。
