次の方法で共有


Windows Server および Windows 用の OpenSSH Server の構成

この記事では、OpenSSH Server (sshd) の Windows 固有の構成について説明します。

OpenSSH maintains detailed documentation for configuration options online at OpenSSH.com, which isn't duplicated in this documentation set.

OpenSSH 構成ファイル

OpenSSH には、サーバー設定とクライアント設定の両方の構成ファイルがあります。 OpenSSH はオープンソースであり、Windows Server 2019 および Windows 10 (ビルド 1809) 以降、Windows Server および Windows クライアント オペレーティング システムに追加されました。 その結果、OpenSSH 構成ファイルのオープンソース ドキュメントはここで繰り返されません。 クライアント構成ファイル。 ssh_configの手動ページ と OpenSSH サーバー構成ファイルについては 、sshd_configの手動ページを参照してください。

Open SSH Server (sshd) reads configuration data from %programdata%\ssh\sshd_config by default, or a different configuration file might be specified by launching sshd.exe with the -f parameter. ファイルがない場合、sshd はサービスの開始時に既定の構成でファイルを生成します。

Windows では、OpenSSH クライアント (ssh) は構成ファイルから次の順序で構成データを読み取ります。

  1. ssh.exe パラメーターを使用して-Fを起動し、構成ファイルへのパスとそのファイルのエントリ名を指定します。
  2. A user's configuration file at %userprofile%\.ssh\config.
  3. The system-wide configuration file at %programdata%\ssh\ssh_config.

Windows での OpenSSH 用の既定のシェルの構成

既定のコマンド シェルは、SSH を使用してサーバーに接続するときにユーザーに表示されるエクスペリエンスを提供します。 初期の既定の Windows は Windows コマンド シェル (cmd.exe) です。 Windows には PowerShell も含まれており、サード パーティ製のコマンド シェルは Windows でも使用でき、サーバーの既定のシェルとして構成される場合があります。

既定のコマンド シェルを設定するには、まず OpenSSH インストール フォルダーがシステム パスにあることを確認します。 For Windows, the default installation folder is %systemdrive%\Windows\System32\openssh. 次のコマンドは、現在のパス設定を示し、既定の OpenSSH インストール フォルダーを追加します。

Command shell 使用するコマンド
Command path
PowerShell $env:path

既定の SSH シェルの構成は、Windows レジストリで、文字列値 HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSHDefaultShell にシェル実行可能ファイルへの完全なパスを追加することによって行われます。

たとえば、次の管理者特権の PowerShell コマンドは、既定のシェルを OpenSSH Server に powershell.exe するように設定します (このパスの設定は OpenSSH クライアントには適用されません)。

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

sshd_configの Windows 構成

In Windows, sshd reads configuration data from %programdata%\ssh\sshd_config by default, or a different configuration file might be specified by launching sshd.exe with the -f parameter. ファイルがない場合、sshd はサービスの開始時に既定の構成でファイルを生成します。

次の要素は、sshd_configのエントリを通じて可能な Windows 固有の構成を提供します。 オンライン の Win32 OpenSSH ドキュメントで詳しく説明しているため、ここに記載されていない可能性のあるその他の構成設定があります。

Tip

OpenSSH サーバー (sshd) は、サービスの開始時に構成ファイルを読み取ります。 構成ファイルを変更した場合は、サービスを再起動する必要があります。

AllowGroups、AllowUsers、DenyGroups、DenyUsers

Controlling which users and groups can connect to the server is done using the AllowGroups, AllowUsers, DenyGroups, and DenyUsers directives. The allow/deny directives are processed in the following order: DenyUsers, AllowUsers, DenyGroups, and finally AllowGroups. すべてのアカウント名は小文字で指定する必要があります。 ssh_configの PATTERNS とワイルドカードの詳細については、 sshd_config OpenBSD のマニュアル ページを参照してください。

ドメイン ユーザーまたはグループを使用してユーザー/グループ ベースのルールを構成する場合は、次の形式を使用します: user?domain*。 Windows では、ドメイン プリンシパルを指定するための複数の形式を使用できますが、標準の Linux パターンと競合する可能性があります。 そのため、FQDN をカバーするために * が追加されます。 また、この方法では、?ではなく@を使用して、username@host形式との競合を回避します。

作業グループのユーザー/グループとインターネットに接続されたアカウントは、常にローカル アカウント名に解決されます (標準の Unix 名に似たドメイン部分はありません)。 Domain users and groups are strictly resolved to NameSamCompatible format: domain_short_name\user_name. すべてのユーザー/グループ ベースの構成規則は、この形式に従う必要があります。

次の例では、ホスト 192.168.2.23 から contoso\admin を拒否し、contoso ドメインからすべてのユーザーをブロックします。 また、contoso\sshusers グループと contoso\serveroperators グループのメンバーであるユーザーも使用できます。

DenyUsers contoso\admin@192.168.2.23
DenyUsers contoso\*
AllowGroups contoso\sshusers contoso\serveroperators

The following example allows the user localusers to sign-in from the host 192.168.2.23 and allows members of the group sshusers.

AllowUsers localuser@192.168.2.23
AllowGroups sshusers

AuthenticationMethods

Windows OpenSSH の場合、使用可能な認証方法は passwordpublickeyのみです。

Important

Microsoft Entra アカウントを使用した認証は現在サポートされていません。

AuthorizedKeysFile

既定値は .ssh/authorized_keysです。 If the path isn't absolute, it's taken relative to user's home directory (or profile image path), for example, C:\Users\username. If the user belongs to the administrator group, %programdata%/ssh/administrators_authorized_keys is used instead.

Tip

The administrators_authorized_keys file must only have permission entries for the NT Authority\SYSTEM account and BUILTIN\Administrators security group. NT Authority\SYSTEM アカウントには、フル コントロールが付与されている必要があります。 管理者が承認されたキーを管理するには、BUILTIN\Administrators セキュリティ グループが必要です。必要なアクセス権を選択できます。 アクセス許可を付与するには、管理者特権の PowerShell プロンプトを開き、コマンド icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"を実行します。

ChrootDirectory (v7.7.0.0 で追加されたサポート)

このディレクティブは、sftp セッションでのみサポートされます。 cmd.exeへのリモート セッションでは、ChrootDirectoryは優先されません。 sftp 専用の chroot サーバーを設定するには、 ForceCommand を internal-sftp に設定します。 scp と sftp のみを許可するカスタム シェルを実装することで、chroot を使用して scp を設定することもできます。

GSSAPIAuthentication

GSSAPIAuthentication構成引数は、GSSAPI ベースのユーザー認証を許可するかどうかを指定します。 GSSAPIAuthenticationの既定値は no です。

GSSAPI 認証では、OpenSSH クライアントの使用時にホスト名を指定する -K スイッチも使用する必要があります。 または、SSH クライアント構成で対応するエントリを作成することもできます。 In Windows, the OpenSSH client reads configuration data from %userprofile%.ssh\config by default.

GSSAPI OpenSSH クライアント構成の例を確認できます。

# Specify a set of configuration arguments for a host matching the pattern SERVER01.contoso.com
# Patterns are case sensitive
Host SERVER01.contoso.com
    # Enables GSSAPI authentication
    GSSAPIAuthentication yes
    # Forward (delegate) credentials to the server.
    GSSAPIDelegateCredentials yes

Important

GSSAPI は、Windows Server 2022、Windows 11、および Windows 10 xxxx 以降でのみ使用できます。

HostKey

既定値は次のとおりです。

#HostKey __PROGRAMDATA__/ssh/ssh_host_rsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_dsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ecdsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ed25519_key

既定値が存在しない場合は、サービスの開始時に sshd によって自動的に生成されます。

Match

1 つ以上の基準を使用して条件に一致させます。 一致すると、後続の構成引数が適用されます。 マッチングでは、「AllowGroups、AllowUsers、DenyGroups、DenyUsers」セクションで説明されているパターンルールが使用されます。 ユーザー名とグループ名は小文字にする必要があります。

PermitRootLogin

Windows では適用されません。 To prevent administrators signing in, use Administrators with DenyGroups directive.

SyslogFacility

If you need file based logging, use LOCAL0. Logs are generated under %programdata%\ssh\logs. 既定値を含む他の値の場合、AUTH はログ記録を ETW に転送します。 詳細については、「 Windows のログ機能」を参照してください。

Configuration arguments

Windows Server 2022、Windows 11、および Windows 10 xxxx 以降では、次の構成引数を使用できます。

  • GSSAPIAuthentication

次の構成引数は、Windows Server および Windows クライアントに付属する OpenSSH バージョンでは使用できません。

  • AcceptEnv
  • AllowStreamLocalForwarding
  • AuthorizedKeysCommand
  • AuthorizedKeysCommandUser
  • AuthorizedPrincipalsCommand
  • AuthorizedPrincipalsCommandUser
  • ExposeAuthInfo
  • GSSAPICleanupCredentials
  • GSSAPIStrictAcceptorCheck
  • HostbasedAcceptedKeyTypes
  • HostbasedAuthentication
  • HostbasedUsesNameFromPacketOnly
  • IgnoreRhosts
  • IgnoreUserKnownHosts
  • KbdInteractiveAuthentication
  • KerberosAuthentication
  • KerberosGetAFSToken
  • KerberosOrLocalPasswd
  • KerberosTicketCleanup
  • PermitTunnel
  • PermitUserEnvironment
  • PermitUserRC
  • PidFile
  • PrintLastLog
  • PrintMotd
  • RDomain
  • StreamLocalBindMask
  • StreamLocalBindUnlink
  • StrictModes
  • X11DisplayOffset
  • X11Forwarding
  • X11UseLocalhost
  • XAuthLocation