SLES 15 Server SSH 遠端連線 操作手冊
目錄
概述
本操作手冊說明如何在純文字模式(無 GUI)的 SLES 15 Server 上安裝與設定 SSH,讓其他主機可以透過網路遠端連線。
環境與前提
- 作業系統:SLES 15 SPx Server
- 權限:需具備 root 或 sudo 權限
- 網路:已設定固定 IP,且可自行操作防火牆與路由器/NAT
安裝 OpenSSH Server
# 切換至 root
su -
# 更新套件庫並安裝 openssh-server
zypper refresh
zypper install -y openssh
配置 SSH Daemon
-
編輯主設定檔
/etc/ssh/sshd_config
# 確保監聽所有介面,或註解掉預設 ListenAddress #ListenAddress 0.0.0.0 #ListenAddress :: # (選用)允許 root 直接登入 #PermitRootLogin yes
-
重新載入/重啟 SSHD
systemctl restart sshd
-
驗證 SSHD 正在監聽
ss -tlnp | grep sshd # 預期看到: # LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=…,fd=…))
防火牆放行 SSH 埠
使用 firewalld(SLES 15 預設)
# 永久放行 SSH service
firewall-cmd --permanent --add-service=ssh
# 重新載入規則
firewall-cmd --reload
# 驗證
firewall-cmd --list-services | grep ssh
啟動並設定開機自動啟動
# 啟動 SSHD
systemctl start sshd
# 設定開機自動啟動
systemctl enable sshd
驗證與測試連線
-
同網段內測試
ssh <username>@<SLES15_內網IP>
-
跨網段/外部網路測試
- 確保路由器或防火牆已將公網 TCP 22(或自訂埠)轉發至 SLES15
ssh -p <外部埠> <username>@<公開IP>
- 確保路由器或防火牆已將公網 TCP 22(或自訂埠)轉發至 SLES15
路由器/NAT 轉發設定(選用)
-
家用或企業路由器
- WAN TCP 22 → LAN
<SLES15_IP>:22
- 或 WAN TCP 2222 → LAN
<SLES15_IP>:22
(改用 2222 埠,可減少掃描)
- WAN TCP 22 → LAN
-
雲端 VM(AWS/GCP/Azure)
- Security Group / Firewall Rule:開放 TCP 22(或其他自訂埠)
安全建議
- 關閉 root 密碼登入:
PermitRootLogin no
- 使用金鑰認證,並禁用密碼驗證:
PasswordAuthentication no
- 修改預設埠:
Port 2222
- 定期檢查日誌:
journalctl -u sshd --no-pager | tail -n 50
- 安裝 Fail2Ban(防止暴力破解):
zypper install -y fail2ban systemctl enable fail2ban systemctl start fail2ban
備註
- 所有設定修改後,請先在本機測試:
ssh -p 22 localhost
- 確保防火牆與 SSHD 設定都正確後,外部網路才能順利連入。