Router#configure terminal
Router(config)#hostname R2 //配置ssh的時(shí)候路由器的名字不能為router
R2(config)#ip domain-name cisco.com //配置SSH必需
R2(config)#username best password best1
注:添加一個(gè)用戶:best,口令:best1
R2(config)#line vty 0 4
R2(config-line)#transport input ssh //只允許用SSH登錄(注意:禁止telnet和從交換引擎session!)
2. 配置SSH服務(wù):
R2(config)#crypto key generate rsa
The name for the keys will be: R2.cisco.com
注:SSH的關(guān)鍵字名就是hostname + . +ip domain-name
Choose the size of the key modulus in the range of 360 to 2048 for your
General Purpose Keys. Choosing a key modulus greater than 512 may take
a few minuts
How many bits in the modulus [512]: 注:選擇加密位數(shù),cisco推薦使用1024
Generating RSA keys ...
[OK]
用命令show ip ssh也能看到:
SSH Enabled - version 1.5
Authentication timeout: 120 secs; Authentication retries:
現(xiàn)在SSH服務(wù)已經(jīng)啟動(dòng),如果需要停止SSH服務(wù),用以下命令:
R2(config)#crypto key zeroize rsa
3.設(shè)置SSH參數(shù)
配置好了SSH之后,通過show run命令我們看到SSH默認(rèn)的參數(shù):超時(shí)限定為120秒,認(rèn)證重試次數(shù)為3次,可以通過下面命令進(jìn)行修改:
R2(config)#ip ssh {[time-out seconds]} │ [authentication-retries interger]}
如果要把超時(shí)限定改為180秒,則應(yīng)該用:
R2(config)# ip ssh time-out 180
如果要把重試次數(shù)改成5次,則應(yīng)該用:
R2(config)# ip ssh authentication-retries
這樣,SSH已經(jīng)在路由器上配置成功了,就能夠通過SSH進(jìn)行安全登錄了。
注意:最后如果從別的設(shè)備用ssh登錄這臺(tái)路由器會(huì)出現(xiàn)以下內(nèi)容:
R1#ssh -l best 192.168.0.2
Password:
R2>en
% Error in authentication.
為什會(huì)出現(xiàn)以上內(nèi)容?
因?yàn)樵赗2上沒有配置enable password/secret xxxx
R2配置上enable secret 5 $1$fJxo$suWiTzmfdj/vkvXfRHBcw/
那么在R1上:
R1#ssh -l best 192.168.0.2
Password:
聯(lián)系客服