SSH 取代 Telnet 是網管必修課。本文整合 Cisco 路由器密碼體系 (Enable Secret、Console/AUX/VTY) 與 SSH Server 完整配置流程:域名、RSA 金鑰、SSH 參數、VTY 限制 SSH、AAA 本地認證,並解決常見「需 domain-name 生成金鑰」、「AAA new-model 依賴」等坑點。
! 特權密碼 (僅用 Secret,MD5 不可逆)
enable secret Admin@Secret2024
! Console 線路
line console 0
password Console@Pass2024
login
logging synchronous
exec-timeout 5 0
! VTY 線路 (預留 Telnet 密碼,後續將關閉 Telnet)
line vty 0 4
password Vty@Pass2024
login
hostname R1
ip domain-name corp.local
crypto key generate rsa general-keys modulus 2048
! The name for the keys will be: R1.corp.local
ip ssh version 2
ip ssh authentication-retries 3
ip ssh time-out 60
ip ssh logging events
aaa new-model
aaa authentication login default local
line vty 0 15
transport input ssh
login authentication default
access-class 23 in
username admin privilege 15 secret Admin@Secret2024
username netop privilege 7 secret NetOp@Pass2024
access-list 23 permit 192.168.100.0 0.0.0.255
| 問題 | 原因 | 解決 |
|---|---|---|
生成金鑰報錯 % Please define a domain-name first | 缺 ip domain-name | 先配置 ip domain-name corp.local |
SSH 連線被拒 Connection refused | VTY 未 transport input ssh 或未 crypto key generate | 檢查 VTY、重新生成金鑰 |
| 輸入密碼正確但登入失敗 | 未 aaa new-model 或 login authentication default 缺失 | 啟用 aaa new-model、aaa authentication login default local |
| Console 也被 AAA 接管無法登入 | aaa new-model 後所有線路預設用 AAA | Console 另配 login authentication CONSOLE_AUTH,aaa authentication login CONSOLE_AUTH none (或 local) |
| 金鑰模數 1024 被視為弱 | 合規要求 ≥ 2048 | crypto key generate rsa modulus 2048 (需先 crypto key zeroize rsa) |
ssh -l admin 192.168.1.1 成功登入,show users 顯示 vty 連線。telnet 192.168.1.1 連線被拒 (Connection refused)。show ip ssh 顯示 SSH 版本 2、認證重試 3、超時 60s。show run | section line vty 確認 transport input ssh、login authentication default、access-class 23 in。