Cisco IOS Cookbook 中文精簡版 3-23 用戶訪問和權限管理

 3.1.  設置用戶名和密碼
提問 爲每個單獨的人員設置不同的用戶名和密碼
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#username neoshi  password ioscookbook    (username weak nopassword
Router1(config)#aaa new-model
Router1(config)#aaa authentication login local_auth local
Router1(config)#line vty 0 4
Router1(config-line)#login authentication local_auth
Router1(config-line)#exit
Router1(config)#end
Router1#
註釋 設置單獨的用戶名和密碼的好處就不用多說了,這裏只提一個就是在日誌中會顯示誰做了修改,比如%SYS-5-RELOAD: Reload requested by kdooley on vty0 (172.25.1.1).另外在username這個命令裏面還有一個autocommand的選項,實現登錄以後自動執行某個特定的命令的作用,下面的例子就是一個用戶名爲run無密碼,登錄以後顯示完端口狀態就自動退出的例子,很好用吧
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#aaa new-model
Router1(config)#aaa authentication login default local
Router1(config)#aaa authorization exec default local
Router1(config)#username run nopassword noescape
Router1(config)#username run autocommand show ip interface brief
Router1(config)#end
Router1#

3.2.  加密密碼
提問 加密密碼從而在配置文件中不明文顯示
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#enable password oreilly
Router1(config)#line vty 0 4
Router1(config-line)#password cookbook
Router1(config-line)#line con 0
Router1(config-line)#password cookbook
Router1(config-line)#line aux 0
Router1(config-line)#password cookbook
Router1(config-line)#exit
Router1(config)#service password-encryption
Router1(config)#end
Router1#
註釋 這種加密方式很弱,很容易被破解
3.3.  Using Better Password-Encryption Techniques
提問 使用強度高的加密方式而不是思科缺省的加密技術
回答
Router1#configure terminal  
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#enable secret ORAbooks
Router1(config)#end
Router1#
在IOS 12.2(8)T後也可以對username的密碼做高強度的加密
Router#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#username ijbrown secret oreilly
Router(config)#end
Router#

註釋 由於這種加密方式使用的是MD5所以破解難度相對增大了。對於enable secret的密碼有個小技巧就是密碼設定正常沒有?,不過可以通過^V+?的方式來輸入。
3.4.  移去配置文件中的密碼信息
提問 不想在配置文件中顯示密碼
回答 使用腳本略去
註釋 簡單的用show tech命令也可以
3.5.  解密思科的弱密碼
提問 破解思科缺省的密碼算法
回答 使用腳本略去
註釋 可以使用BOSON網站上的免費工具
3.6.  顯示當前登錄用戶
提問 顯示當前登錄設備的用戶
回答
Router1#show users (who
註釋 無
3.7.  發信息給其它用戶
提問 試圖發送信息給登錄在同一設備的其它用戶
回答
Router1#send *
Router1#send console 0
Router1#send vty 2
Router1#send 66

註釋 很好用的特性,比如當你重啓的時候需要告訴別人,文本信息^+Z結束
3.8.  修改可用VTY數目
提問 增加或者減少可登錄用戶的數目
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#line vty 0 9
Router1(config-line)#exit
Router1(config)#end
Router1#

註釋 缺省可登錄vty數目爲5,不能刪除,對於增加的可以使用no line vty x 刪除,不能不能刪除單獨的vty,是刪除所有大於x的vty
3.9.  修改VTY的超時時長
提問 修改超時避免用戶登錄超時被系統斷開
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#line vty 0 4
Router1(config-line)#exec-timeout 0 0   (exec-timeout 240 0
Router1(config-line)#exit
Router1(config)#end
Router1#

註釋 缺省用戶10分鐘空閒就會被踢掉系統,0 0可以用不超時,第一個0是分鐘,第二個0是秒。同時爲了防止有些用戶掉死但是還佔用vty端口的情況,建議使用下面命令來防止:
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#service tcp-keepalives-in
Router1(config)#end
Router1#
3.10.  限制用戶登錄可以使用的協議
提問 只允許用戶用特定的協議來進行系統登錄
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#line vty 0 4
Router1(config-line)#transport input telnet
Router1(config-line)#exit
Router1(config)#end
Router1#

註釋 缺省情況下除了可以telnet登錄,還支持以下協議登錄lat pad v120 lapb-ta rlogin ssh
3.11.  配置用戶登錄可用總時長Enabling Absolute Timeouts on VTY Lines
提問 對用戶登錄總時長進行限制,不論是否在空閒還是活動
回答 Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#line vty 0 4
Router1(config-line)#absolute-timeout 5
Router1(config-line)#logout-warning 30
Router1(config-line)#exit
Router1(config)#end
Router1#

註釋 無
3.12.  部署Banners
提問 設置登錄時顯示的警示性信息
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#banner exec  # This is an exec banner #
Router1(config)#banner login # This is a login banner #
Router1(config)#banner motd  $ This is a motd banner  $
Router1(config)#end
Router1#

註釋 不用使用welcome之類的字樣,下面是一個FBI的路由器登錄banner做參考
Router1(config)#banner login #
Enter TEXT message.  End with the character '#'.

+--------------------------------------------------------------------+
|                              WARNING                               |
|                              -------                               |
| This system is solely for the use of authorized users for official |
| purposes.  You have no expectation of privacy in its use and to    |
| ensure that the system is functioning properly, individuals using  |
| this computer system are subject to having all of their activities |
| monitored and recorded by system personnel. Use of this system     |
| evidences an express consent to such monitoring and agreement that |
| if such monitoring reveals evidence of possible abuse or criminal  |
| activity, system personnel may provide the results of such         |
| monitoring to appropriate officials.                               |
+--------------------------------------------------------------------+
#
Router1(config)#end
Router1#
3.13.  在特定端口禁用Banners顯示
提問 aux口用於modem連接,爲了避免出現問題希望關閉banner顯示
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#line aux 0     
Router1(config-line)#no motd-banner
Router1(config-line)#no exec-banner
Router1(config-line)#exit
Router1(config)#end
Router1#

註釋
3.14.  禁用Line登錄
提問 禁止在AUX或者Line端口進行設備登錄
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#line aux 0
Router1(config-line)#transport input none
Router1(config-line)#no exec
Router1(config-line)#exec-timeout 0 1
Router1(config-line)#no password
Router1(config-line)#exit
Router1(config)#end
Router1#
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#access-list 98 deny any log
Router1(config)#line vty 0 4
Router1(config-line)#transport input none
Router1(config-line)#exec-timeout 0 1
Router1(config-line)#no exec
Router1(config-line)#access-class 98 in
Router1(config-line)#exit
Router1(config)#end
Router1#

註釋 無
3.15.  爲管理員保留特定的登錄端口
提問 防止所有的登錄端口都被佔用,爲管理員留一個後門
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#access-list 9 permit 172.25.1.1
Router1(config)#line vty 4
Router1(config-line)#access-class 9 in
Router1(config-line)#exit
Router1(config)#end
Router1#
或者
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#access-list 9 permit 172.25.1.1
Router1(config)#line vty 5 7
Router1(config-line)#rotary 25
Router1(config-line)#access-class 9 in
Router1(config-line)#exit
Router1(config)#end
Router1#

註釋 在使用第二種rotary命令時就相應的改變登錄時的端口號碼,不是缺省的23,而是3000+rotary的號碼25=3025
3.16.  限制特定地址的Telnet登錄  
提問 只允許特定的機器進行Telnet登錄
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#access-list 99 permit 172.25.1.0 0.0.0.255
Router1(config)#access-list 99 deny any log               
Router1(config)#line vty 0 4
Router1(config-line)#access-class 99 in
Router1(config-line)#exit
Router1(config)#end
Router1#
註釋 無
3.17.  對Telnet訪問進行日誌記錄
提問 記錄每次telnet的日誌
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#access-list 90 permit any log
Router1(config)#line vty 0 4
Router1(config-line)#access-class 90 in
Router1(config-line)#exit
Router1(config)#end
Router1#
註釋 需要注意的是不管登錄成功還是失敗,在日誌中都是顯示的permitted:
%SEC-6-IPACCESSLOGS: list 90 permitted 172.25.1.1 1 packet
3.18.  設置發起Telnet的源地址
提問 有時對端設備有安全設置只允許特定的地址發起telnet請求
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#ip telnet source-interface loopback0
Router1(config)#end
Router1#
或者
Router1#telnet 172.25.1.5 /source-interface loopback0
註釋 缺省情況路由器會使用到目的地所使用的端口來做Telnet的源地址
3.19.  自動登錄
註釋 使用腳本略去,其實用SecueCRT很容易設定
3.20.  使用SSH登錄
提問 啓用SSH這種加密的登錄方式
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#hostname Router1
Router1(config)#ip domain-name neoshi.net
Router1(config)#crypto key generate rsa
The name for the keys will be: Router1.oreilly.com
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 minutes.

How many bits in the modulus [512]: 1024
Generating RSA keys ...
[OK]

Router1(config)#
Jun 27 15:04:15: %SSH-5-ENABLED: SSH 1.5 has been enabled
Router1(config)#ip ssh time-out 120
Router1(config)#ip ssh authentication-retries 4
Router1(config)#end
Router1#
註釋 從IOS 12.3(4)T開始支持SSH v2,之前只支持v1,首先要確認你的IOS版本,然後確認支持安全特性3DES,才能開啓SSH的特性
3.21.       改變IOS命令的特權等級
提問 修改特定IOS命令的特權等級
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#privilege exec level 1 show startup-config
Router1(config)#end
Router1#
註釋 缺省情況路由器支持16種特權等級,命令一般歸屬於0,1和15三種特權等級,在特權等級0下面只支持disable, enable, exit, help, 和logout命令,1下面不能對配置進行修改,15就是enable的特權等級
3.22.  基於用戶的特權等級Defining Per User Privileges
提問 給不同的用戶賦予不同的特權等級
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#aaa new-model
Router1(config)#aaa authentication login default local
Router1(config)#aaa authorization exec default local
Router1(config)#username neoshi privilege 10 password ioscookbook
Router1(config)#privilege exec level 10 show ip route
Router1(config)#privilege exec level 1 show ip      
Router1(config)#privilege exec level 1 show   
Router1(config)#end
Router1#
註釋 通常的0,1和15三種等級彈性不足,可以定義更多的等級給不同的用戶
3.22.       基於端口的特權等級
提問 根據登錄的不同端口自動賦予特定的特權等級
回答
Router1#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router1(config)#line aux 0
Router1(config-line)#privilege level 5
Router1(config-line)#exit
Router1(config)#privilege exec level 5 show ip route
Router1(config)#privilege exec level 1 show ip      
Router1(config)#privilege exec level 1 show   
Router1(config)#end
Router1#
註釋 無
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章