Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

PuTTY 連接失敗「Network error: Connection refused」與亂碼終極解決方案

編輯:關於伺服器

PuTTY 連接 Linux 伺服器最常見的兩大問題:連接被拒絕、終端機亂碼。本文提供系統性排查與永久修復方案。

問題一:Connection Refused

排查清單

  1. 網路通達性:ping IP、telnet IP 22
  2. SSH 服務狀態:systemctl status sshd / service ssh status
  3. 防火牆/安全組:雲廠商控制台放行 22 埠、伺服器 iptables/firewalld/ufw
  4. SSH 配置:/etc/ssh/sshd_config → Port 22、PermitRootLogin yes、PasswordAuthentication yes
  5. 重啟服務:systemctl restart sshd

快速修復腳本(Root 執行)

# 安裝 SSH(若未裝)
apt-get update && apt-get install -y openssh-server  # Debian/Ubuntu
yum install -y openssh-server                        # CentOS/RHEL

# 關鍵配置
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
grep -q '^UseDNS' /etc/ssh/sshd_config || echo 'UseDNS no' >> /etc/ssh/sshd_config
systemctl restart sshd

# 關閉防火牆(測試用,生產請精準放行)
systemctl stop firewalld && systemctl disable firewalld
# 或
ufw allow 22

問題二:終端機亂碼

唯一核心修復:PuTTY 字符集設為 UTF-8

  1. PuTTY 視窗 → 左側 Category → Window → Translation
  2. Remote character set:選 UTF-8 PuTTY Translation設定
  3. (可選)Window → Appearance → Font:選 Consolas/DejaVu Sans Mono 等等寬字體
  4. Session → 儲存設定

為何其他方法不可取

  • 修改伺服器 /etc/sysconfig/i18n 強制 GB18030:破壞系統一致性、影響其他客戶端
  • export LC_ALL=zh_CN.utf8:僅當前 Shell 生效、不解決 PuTTY 顯示層問題
  • 字體設為 Fixedsys + GB2312:舊版相容做法,現代系統一律 UTF-8

驗證步驟

# 連接後執行
echo "中文測試"
ls /etc/ | head
# 應正常顯示中文檔名,無亂碼
Copyright © Windows教程網 All Rights Reserved