メインコンテンツへスキップ
見出し画像

Cisco IOSでSSHログインとRADIUS認証を構築してみた【検証手順付き】

    はじめに

    Ciscoルータの管理では、セキュリティ向上のため、TelnetではなくSSHを利用するのが一般的です。

    今回は、CML(Cisco Modeling Labs)環境でCisco IOSルータに対して

    • SSHによるローカル認証

    • FreeRADIUSを利用したAAA認証

    までを検証しました。

    この記事では、実際に設定した内容と、設定時のポイントをまとめます。

    検証環境

    画像
    検証構成図

    今回の検証環境は以下の通りです。

    • Cisco IOSv Router(SSH設定対象)

    • Ubuntu Server(FreeRADIUSサーバ)

    • RouterとFreeRADIUSサーバを同一ネットワークに接続

    • SSH接続確認用ルータ(Cisco IOSv)

    まずはローカルユーザーでSSH接続できる状態を構築し、その後RADIUS認証へ切り替えています。

    ① SSH(Local Login) の設定

    ・ホスト名の設定

    Router#configure terminal
    Router(config)#hostname R1

    ・ドメイン名の設定

    R1(config)#ip domain-name cisco.jp

    ・RSA鍵の生成(※RSAキーを発行させるためには、ホスト名/ドメイン名の設定が必須です)

    R1(config)#crypto key generate rsa
    The name for the keys will be: R1.cisco.jp
    Choose the size of the key modulus in the range of 360 to 4096 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 1024 bit RSA keys, keys will be non-exportable...
    [OK] (elapsed time was 1 seconds)

    ・ローカルユーザアカウントの作成

    R1(config)#username labuser secret labuser

    ・特権EXECモードに入る際のパスワードの設定

    R1(config)#enable secret cisco

    ・ローカル認証の設定およびSSHによる接続の許可

    R1(config)#line vty 0 4
    R1(config-line)#login local
    R1(config-line)#transport input ssh

    ・SSHのバージョンの指定

    ※SSHのバージョンを明示的に指定しない場合、デフォルトではSSHバージョン1が使用されます。SSHバージョン1には既知の脆弱性が存在するため、セキュリティ向上の観点から、SSHバージョン2を明示的に指定することが推奨されています。

    R1(config)#ip ssh version 2

    動作確認

    SSH接続確認用ルータから以下のコマンドを実行し、SSH接続できることを確認します。

    ssh -l labuser <R1のGi0/0のIPアドレスを指定>

    login-user#ssh -l labuser 192.168.255.172
    
    **************************************************************************
    * IOSv is strictly limited to use for evaluation, demonstration and IOS  *
    * education. IOSv is provided as-is and is not supported by Cisco's      *
    * Technical Advisory Center. Any use or disclosure, in whole or in part, *
    * of the IOSv Software or Documentation to any third party for any       *
    * purposes is expressly prohibited except as otherwise authorized by     *
    * Cisco in writing.                                                      *
    **************************************************************************
    Password: 
    ( 省略 )
    R1>enable
    Password: 
    R1#
    
    R1#exit
    
    [Connection to 192.168.255.172 closed by foreign host]
    login-user#

    ② RADIUS認証の設定

    次にFreeRADIUSを構築します。

    ・FreeRADIUSの構築

    Ubuntuでは以下のようにFreeRADIUSをインストールできます。
    $ sudo apt update
    $ sudo apt install -y freeradius freeradius-utils
    $ sudo systemctl enable --now freeradius
    $ sudo systemctl status freeradius
    ・clients.confでは、RADIUSサーバへのアクセスを許可するクライアント(Ciscoルータ)を登録します。
    $ sudo vi /etc/freeradius/3.0/clients.conf
    client router {
    ipaddr = 192.168.255.0/24
    secret = cisco123
    }
    ・usersファイルでは、RADIUS認証に使用するユーザーアカウントを登録します。
    $ sudo vi /etc/freeradius/3.0/users
    testuser Cleartext-Password := "password"
    Service-Type = NAS-Prompt-User

    その後、Router(R1)側では

    ・AAAの有効化

    R1(config)#aaa new-model

    ・Radius Serverの登録

    R1(config)#radius server RADIUS-1
    R1(config-radius-server)#address ipv4 192.168.255.187 auth-port 1812 acct-port 1813
    R1(config-radius-server)#key cisco123  ※Radiusサーバ側と合わせておく
    R1(config-radius-server)#exit

    ・AAA Groupの作成

    R1(config)#aaa group server radius RADGROUP
    R1(config-sg-radius)#server name RADIUS-1
    R1(config-sg-radius)#exit

    ・Login Authenticationの設定

    R1(config)#aaa authentication login VTY_LOGIN group RADGROUP local
    R1(config)#aaa authentication login default local
    R1(config)#line vty 0 4
    R1(config-line)#login authentication VTY_LOGIN
    R1(config-line)#end

    を実施します。

    動作確認

    RADIUSユーザーでSSHログインできれば設定完了です。
    ssh -l testuser <R1のGi0/0のIPアドレスを指定>

    login-user#ssh -l testuser 192.168.255.172
    
    **************************************************************************
    * IOSv is strictly limited to use for evaluation, demonstration and IOS  *
    * education. IOSv is provided as-is and is not supported by Cisco's      *
    * Technical Advisory Center. Any use or disclosure, in whole or in part, *
    * of the IOSv Software or Documentation to any third party for any       *
    * purposes is expressly prohibited except as otherwise authorized by     *
    * Cisco in writing.                                                      *
    **************************************************************************
    Password: 
    ( 省略 )
    R1>enable
    Password: 
    R1#
    
    R1#exit
    
    [Connection to 192.168.255.172 closed by foreign host]
    login-user#
    

    まとめ

    今回はCisco Routerを利用して、

    • SSH(Local Login)

    • FreeRADIUSによるAAA認証

    まで構築してみました。

    ローカル認証だけでなく、外部認証サーバと連携することで、より実務に近い構成を体験できました。

     
     
    日本在住の外国人ネットワークエンジニア。 コンピュータサイエンス専攻で大学を卒業後、プログラマーとして2年間の経験を積む。 2016年より現在に至るまで、ネットワークエンジニアとして従事している。 #IT #Networking #KnowledgeSharing

    あなたへのおすすめ