Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Windows 7 使用 PuTTY 遠端登入 Ubuntu 12.04 (SSH 服務安裝與設定全記錄)

編輯:Win7 常見問題解答

在 Windows 7 上透過 PuTTY 以 SSH 協定遠端管理 Ubuntu Linux,是系統管理員與開發者的基本功。本文完整記錄從 Ubuntu 安裝 OpenSSH Server、啟動服務、驗證連線、Windows 端 PuTTY 設定到成功登入的全過程,含指令與畫面對照。

Ubuntu 端:安裝與啟用 SSH Server

1. 安裝 openssh-server

開啟終端機,輸入:

sudo apt-get update
sudo apt-get install openssh-server

安裝過程會自動產生 RSA/DSA/ECDSA 金鑰並啟動 ssh 服務。

Ubuntu 安裝 SSH

2. 驗證 SSH 服務狀態

ps -e | grep ssh
# 輸出應包含 sshd 行,代表服務正在執行
sudo service ssh status
# 或 systemctl status ssh (較新版本)

3. 取得 Ubuntu IP 位址

ifconfig
# 或 ip addr show
# 尋找 inet 開頭的區域網路 IP (如 192.168.x.x 或 10.x.x.x)
Ubuntu ifconfig 輸出

Windows 7 端:網路連通性測試

開啟命令提示字元,ping Ubuntu IP:

ping 192.168.1.100  (替換為實際 IP)
# 回應正常代表網路通暢

Windows 7 端:PuTTY 設定與連線

  1. 下載 PuTTY (putty.exe,免安裝綠色版),雙擊執行。
  2. 設定連線參數:
    • Host Name (IP address):輸入 Ubuntu IP
    • Port:22 (SSH 預設)
    • Connection type:SSH
    • Saved Sessions:輸入名稱 (如 Ubuntu-Server) → 點擊 Save 儲存
  3. 點擊「Open」啟動連線。
  4. 首次連線會跳出「安全性警示」 (金鑰指紋未快取),點擊「是」信任並快取。
  5. 輸入 Ubuntu 使用者帳號 (如 wahaha) 按 Enter,再輸入密碼 (輸入時不顯示字元) 按 Enter。
PuTTY 設定視窗
PuTTY 登入成功

常見問題排解

現象可能原因解決方向
Connection refused / Network errorSSH 服務未啟動、防火牆封鎖 22 埠、IP 錯誤Ubuntu 執行 sudo service ssh start;檢查 ufw status 或 iptables;確認 IP
Access denied / Permission denied帳號/密碼錯誤、Root 登入被禁止、鍵盤配置不同確認帳密;/etc/ssh/sshd_config 檢查 PermitRootLogin;嘗試一般帳號登入後 su -
連線逾時網路不通、虛擬機網路模式錯誤 (NAT vs Bridge)虛擬機請用「橋接模式」讓 Ubuntu 取得實體網段 IP;確認 ping 通

進階:金鑰認證 (免密碼登入,更安全)

  1. Windows 端:PuTTYgen 產生 RSA 金鑰對,儲存私鑰 (.ppk) 與公鑰。
  2. Ubuntu 端:mkdir -p ~/.ssh && chmod 700 ~/.ssh,將公鑰內容追加至 ~/.ssh/authorized_keys,chmod 600 authorized_keys。
  3. PuTTY 設定:Connection → SSH → Auth → Private key file 選擇 .ppk 檔。
  4. 再次連線即可免密碼登入。

完成上述設定,您即可從 Windows 7 安全、高效地遠端管理 Ubuntu 伺服器,進行指令操作、檔案傳輸 (搭配 WinSCP/PSCP) 等各項維運工作。

Copyright © Windows教程網 All Rights Reserved