系統管理員每天遠程管理服務器,協議選擇關乎資產生死。Telnet明文傳輸、無認證、無加密,早應退出歷史舞台;SSH加密傳輸、公鑰認證、端口可變、強算法支持,是唯一合規選擇。
| 維度 | Telnet | SSH (OpenSSH) |
|---|---|---|
| 全稱 | Telecommunications Network | Secure Shell |
| 默認端口 | 23 | 22 (可改) |
| 傳輸內容 | 明文(含密碼) | 加密(對稱加密數據+非對稱密鑰交換) |
| 認證機制 | 無/明文密碼 | 密碼/公鑰/憑證/鍵盤交互/Host-based |
| 完整性校驗 | 無 | HMAC-SHA2/UMAC等 |
| 適用場景 | 僅內網設備調試/端口連通性測試 | 所有生產環境遠程管理/文件傳輸/隧道/代理 |
| 工具支持 | Putty/MTTty/SecureCRT/Telnet客戶端 | Putty/MTTty/SecureCRT/OpenSSH Client/Win10內置SSH |
# 檢查本地Apache 80端口
telnet localhost 80
# 輸出 Connected to localhost → 服務正常
# Connection refused → 服務未啟動/防火牆阻擋
# 檢查SSH 22端口
telnet localhost 22
# 輸出 SSH-2.0-OpenSSH_8.9p1 → 服務正常且可見版本横幅
# 1. 修改默認端口(減少自動掃描噪音)
Port 2222 # 或 10089 等高位端口
# 2. 禁用Root遠程登錄
PermitRootLogin no
# 3. 僅允許公鑰認證,禁用密碼
PubkeyAuthentication yes
PasswordAuthentication no
AuthenticationMethods publickey
# 4. 限制用戶/組
AllowUsers admin@192.168.1.* ops@10.0.0.*
# 或 AllowGroups sshusers
# 5. 協議與算法硬化
Protocol 2
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com
# 6. 客戶端保活防斷連
ClientAliveInterval 30
ClientAliveCountMax 3
# 7. 禁用空密碼/挑戰響應
PermitEmptyPasswords no
ChallengeResponseAuthentication no
# 8. 登錄優雅提示
Banner /etc/ssh/banner.txt # 含法律警告/授權聲明
修改後:sshd -t 語法檢查 → systemctl reload sshd 熱重載。
# 客戶端生成Ed25519密鑰對(推薦)
ssh-keygen -t ed25519 -a 100 -C "user@host-$(date +%F)"
# 分發公鑰到服務器
ssh-copy-id -i ~/.ssh/id_ed25519.pub -p 2222 user@server
# 服務器授權文件權限
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys
下一篇將深入Linux系統級安全加固(內核參數/文件系統/審計/強制訪控),敬請期待。