開始輸入,可搜尋發票、服務、域名、工單,以及 更多...
SSH 是管理 Linux 伺服器最常用的方式。本文介紹如何用 SSH 登入 Linux 伺服器:Windows 10/11 可直接使用 PowerShell 或 Windows Terminal 自帶的 ssh 命令,也可以使用 PuTTY、Xshell 等圖形工具;macOS 與 Linux 直接在終端中連線。文中命令適用於 Debian、Ubuntu、CentOS、Rocky Linux、AlmaLinux 等主流發行版的 IMIDC VPS 與獨立伺服器。
登入前請確認四項資訊:伺服器公網 IP、SSH 埠(預設 22)、使用者名稱(通常為 root,部分 Ubuntu 映象為 ubuntu)以及密碼或私鑰。這些資訊可以在開通郵件中找到,也可以登入客戶中心 → 我的產品與服務 → 選擇伺服器 → 管理 頁面檢視。下文以示例 IP 203.0.113.10 演示,請替換為你自己的 IP。
IP address: 203.0.113.10
SSH port: 22
Username: root
Password: (from the welcome email or client area)
Windows 10 1809 及以上版本、Windows 11 已內建 OpenSSH 客戶端。按 Win + X 開啟“終端”或 PowerShell,執行以下命令即可連線。如果修改過 SSH 埠,用 -p 指定埠。
# Check that the built-in OpenSSH client is available
ssh -V
# Connect with the default port 22
ssh [email protected]
# Connect with a custom port, e.g. 2222
ssh -p 2222 [email protected]
如果提示“ssh 不是內部或外部命令”,說明系統未安裝 OpenSSH 客戶端,可用管理員身份執行 PowerShell 安裝:
# Run in PowerShell as Administrator only if "ssh" is not recognized
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Client*'
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
PuTTY:開啟後在 Host Name 中填寫 IP,Port 填寫埠,Connection type 選擇 SSH,點選 Open,然後在“login as”處輸入使用者名稱,再輸入密碼。可在 Saved Sessions 中儲存會話,下次雙擊即可連線。Xshell:新建會話,填寫主機與埠,在“使用者身份驗證”中填寫使用者名稱與密碼(或選擇金鑰),儲存後雙擊連線。兩者都只需要下面這些基本引數:
Host: 203.0.113.10
Port: 22
Connection type: SSH
Login as: root
macOS 開啟“終端”(Terminal)或 iTerm2,Linux 開啟任意終端,直接使用 ssh 命令。絕大多數系統已預裝客戶端,極少數精簡系統可按發行版安裝:
# macOS / Linux terminal
ssh [email protected]
ssh -p 2222 [email protected]
# Debian / Ubuntu: install the client if missing
sudo apt update && sudo apt install -y openssh-client
# CentOS / Rocky / AlmaLinux: install the client if missing
sudo dnf install -y openssh-clients
第一次連線某臺伺服器時,客戶端會顯示主機金鑰指紋並詢問是否繼續。輸入 yes 後指紋會儲存到本地 known_hosts 檔案,以後連線不再提示。對安全要求較高時,可以先通過 VNC 控制臺登入伺服器檢視真實指紋,確認一致後再輸入 yes。輸入密碼時螢幕不會顯示任何字元,這是正常的保護機制,輸完直接回車即可。
The authenticity of host '203.0.113.10 (203.0.113.10)' can't be established.
ED25519 key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
# On the server (e.g. via the VNC console) print the real fingerprint to compare
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub
| 報錯 | 常見原因與處理 |
|---|---|
| Permission denied | 使用者名稱或密碼錯誤,或伺服器已停用密碼/root 登入;核對大小寫,必要時在客戶中心重置密碼。 |
| Connection refused | 埠不對或 sshd 未執行;確認埠,或通過 VNC 控制臺檢查 sshd 服務。 |
| Connection timed out | IP 錯誤、伺服器未開機、防火牆攔截或本地網路限制。 |
| REMOTE HOST IDENTIFICATION HAS CHANGED | 伺服器重灌系統後主機金鑰變化,刪除本地舊記錄即可。 |
# Remove the old host key after a reinstall, then connect again
ssh-keygen -R 203.0.113.10
# Show verbose debug output when a connection fails
ssh -v [email protected]
SSH 出於安全考慮不回顯密碼,也不顯示星號。直接輸入(或右鍵貼上)後回車即可,貼上時注意不要帶上多餘的空格。
多數是中間網路裝置清理了空閒連線。可在本地 SSH 配置檔案中新增心跳引數,讓客戶端定期傳送保活包:
# ~/.ssh/config (Windows: C:\Users\<you>\.ssh\config)
Host *
ServerAliveInterval 30
ServerAliveCountMax 4
功能上都能滿足日常管理。自帶 ssh 無需安裝、命令與 Mac/Linux 一致,便於配合金鑰使用;PuTTY、Xshell 更適合需要儲存大量會話、習慣圖形介面的使用者。
如按以上步驟操作後仍無法解決,歡迎提交工單聯絡 IMIDC 7×24 技術支援。提交時請註明伺服器 IP、作業系統、已執行的命令和報錯截圖,工程師可以更快定位問題。