トップ «前の日記(2007-03-26 (Mon)) 最新 次の日記(2007-03-30 (Fri))» 編集

ふたつの川うるおう日記


2007-03-27 (Tue)

_ [Linux][Server][Admin] OpenSSH 4.6以降のMatchディレクティブ

ちょっと気になったので試した。

sshd_config内でMatchディレクティブを使うことでsshd_config内で定義可能な設定オプションのいくつかを、ユーザ、グループ、ホスト名、アドレスごとに再定義することが出来ます。ブロックの開始記号と終端記号がないので設定ファイルの最後に書くのが無難です。

  • Matchの構文
    • Match User ユーザ名
    • Match Group グループ名
    • Match Host FQDN
      • FQDNは対象サーバ内での名前解決結果に依存、/etc/hostsファイルで静的定義したものも有効
    • Match Address xxx.xxx.xxx.xxx
      • 「*」利用可、それもかなり大胆に。
      • 例1: 192.168.0.*
      • 例2: 192.*.0.* (途中穴抜けててもOK)
      • 例3: *.1* (末尾のIPの頭が1であればOK)
  • 再定義可能な設定オプション
    • AllowTcpForwarding
    • Banner
    • ForceCommand
    • GatewayPorts
    • GSSApiAuthentication
    • KbdInteractiveAuthentication
    • KerberosAuthentication
    • PasswordAuthentication
    • PermitOpen
    • RhostsRSAAuthentication
    • RSAAuthentication
    • X11DisplayOffset
    • X11Forwarding
    • X11UseLocalHost

フォワーディング系が多い。PasswordAuthenticationが設定できるのは美味しい。

  • 例1: 192.168.0.0/16からの接続時のみパス認証を許可する設定例
... 省略 ...
PermitRootLogin no
PasswordAuthentication no
ChallengeResponseAuthentication no
... 省略 ...
Match Address 192.168.*
    PasswordAuthentication yes

要望として良くありそうで出来ないこととしては、Matchディレクティブでは、PermitRootLoginを再定義出来ません。なので、PermitRootLoginを許可するにはグローバル設定でPermitRootLoginをon(デフォルト未設定時on)にしておく必要があります。

  • 例2: 192.168.0.0/16からの接続時のみパス認証を許可する設定例 + rootログイン許可
... 省略 ...
#PermitRootLogin yes
PasswordAuthentication no
ChallengeResponseAuthentication no
... 省略 ...
Match Address 192.168.*
    PasswordAuthentication yes

この場合、192.168.0.0/16以外からの接続は公開鍵認証必須になるので、root用の公開鍵をあえて設定しない運用をするとか。まぁでもそれだったら、一般ユーザでログインしてsu -かsudoしろって話でもある。

| Bookmark:
[]

| Return to page top | Vicuna CMS - WordPress Theme - Vicuna Ninja Style for tDiary |