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

Linux VPS 遠程修改 Root 密碼教程:Putty 連接、passwd 命令、安全加固全流程

編輯:關於伺服器

剛拿到 Linux VPS,服務商提供的默認 Root 密碼通常簡單、有規律、甚至公開於郵件/控制台,極易遭暴力破解。首要安全動作:立即通過 Putty SSH 連接修改為高強度隨機密碼。本文提供圖文全流程與加固清單。

準備工作

  • 下載 Putty (官網) 或使用 Windows 10+ 內建 ssh / PowerShell / Windows Terminal。
  • 獲取 VPS 公網 IP、SSH 端口 (默認 22)、Root 密碼。

Putty 連接與修改密碼步驟

  1. 打開 Putty,Host Name 輸入 root@VPS_IP (或 IP,Port 22),Connection Type 選 SSH。
    Putty 連接配置
  2. 點「Open」,首次連接彈出安全警告「Server's host key not cached」,點「是」信任。
    Putty 登入成功
  3. 登入提示 login as: 輸入 root,回車;password: 輸入默認密碼 (不顯示字符),回車。登入成功顯示 [root@hostname ~]#。
  4. 執行修改密碼命令:
    passwd root
    提示 New password: 輸入新密碼 (不顯示),回車;
    提示 Retype new password: 再次輸入相同新密碼,回車。
    顯示 passwd: all authentication tokens updated successfully. 即成功。
    passwd 修改密碼過程
  5. 輸入 exit 退出,重新用新密碼登入驗證。

密碼強度標準 (必達)

  • 長度 ≥ 16 字符
  • 包含:大寫 + 小寫 + 數字 + 特殊符號 (!@#$%^&*()_+-=[]{}|;:,.<>?)
  • 非字典單詞、非個人信息、非鍵盤走勢 (如 qwerty、123456)
  • 建議使用密碼管理器 (Bitwarden/1Password/KeePass) 生成並存儲。

修改密碼後必做加固 (三板斧)

  1. 禁用 Root 直接 SSH 登入
    編輯 /etc/ssh/sshd_config:
    PermitRootLogin no
    PubkeyAuthentication yes
    PasswordAuthentication no (需先部署 SSH 金鑰)
    systemctl reload sshd
  2. 修改 SSH 端口 (非 22)
    Port 22222 (避開常見掃描端口)
    systemctl reload sshd
    防火牆/安全組同步放行新端口。
  3. 部署 Fail2Ban 防暴力破解
    yum install -y fail2ban / apt install -y fail2ban
    配置 /etc/fail2ban/jail.local:
    [sshd]
    enabled = true
    port = 22222
    filter = sshd
    logpath = /var/log/auth.log
    maxretry = 3
    bantime = 3600
    systemctl enable --now fail2ban

驗證清單

  • 新密碼可登入,舊密碼失效。
  • Root 直接 SSH 被拒 (Permission denied)。
  • 新端口可連接,22 端口拒絕/超時。
  • Fail2Ban 封禁測試:故意輸錯 3 次密碼,觀察 IP 是否被 iptables 封禁。

「拿到 VPS 先改密、禁 Root、換端口、上 Fail2Ban」四步走,將暴力破解風險降低 99%+,為後續業務部署鋪平安全基石。

Copyright © Windows教程網 All Rights Reserved