OpenSSH は、SSH プロトコルを使用するリモート サインイン用の接続ツールです。 クライアントとサーバーの間のすべてのトラフィックを暗号化して、盗聴、接続ハイジャック、その他の攻撃を排除します。
OpenSSH 互換クライアントを使用して、Windows Server および Windows クライアント デバイスに接続できます。
Important
PowerShell/openssh-portal の GitHub リポジトリから OpenSSH ベータ版をダウンロードした場合は、この記事の手順ではなく、ここに記載されている手順に従ってください。 Win32-OpenSSH リポジトリの一部の情報は、リリース前に大幅に変更される可能性があるプレリリース製品に関連しています。 ここに記載された情報について、Microsoft は明示または黙示を問わずいかなる保証をするものでもありません。
Prerequisites
開始する前に、お使いのコンピューターが次の要件を満たしている必要があります。
前提条件の確認
お使いの環境を検証するには、管理者特権の PowerShell セッションを開き、次の操作を行います。
「winver.exe」と入力し、Enter キーを押して Windows デバイスのバージョンの詳細を表示します。
$PSVersionTable.PSVersion
を実行します。 メジャー バージョンが 5 以上で、マイナー バージョンが 1 以上であることを確認します。
Windows への PowerShell のインストールの詳細については、こちらを参照してください。
管理者のタイミングを確認するには、次のコマンドを実行します。 ビルトイン Administrator グループのメンバーである場合、出力には True
が表示されます。
(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
OpenSSH サーバーを有効にする
Windows Server 2025 以降では、OpenSSH が既定でインストールされるようになりました。 サーバー マネージャーで sshd
サービスを有効または無効にすることもできます。
サーバー マネージャーを使用して SSHD を有効にするには:
サーバー マネージャーの左側のナビゲーション ウィンドウで、[ローカル サーバー] を選択します。
[プロパティ] ウィンドウで、リモート SSH アクセスを見つけます。
OpenSSH サービスを有効にするには、[ 無効] を選択します。
Note
特定のユーザーまたはグループがリモート アクセスに OpenSSH を使用することを許可または制限する必要がある場合は、それらを OpenSSH Users ユーザー グループに追加します。
PowerShell を使用して SSHD を有効にするには:
管理者として PowerShell 開き、次のコマンドレットを実行して SSHD サービスを開始します。
# Start the sshd service
Start-Service sshd
オプションではあるものの推奨されている次のコマンドレットを実行して SSHD を自動的に開始し、有効な状態を維持することもできます。
Set-Service -Name sshd -StartupType 'Automatic'
最後に、次のコマンドを実行して、SSHD セットアップ プロセスによってファイアウォール ルールが自動的に構成されたことを確認します。
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}
OpenSSH サーバーとクライアントのインストール
Windows Server デバイスに OpenSSH コンポーネントをインストールするには:
[スタート] を選択し、検索ボックスに「オプション機能」と入力し、[オプション機能] を選択します。
一覧を確認して、OpenSSH が既にインストールされているかどうかを確認します。 表示されない場合は、ページの上部にある [ビュー機能] を選択し、次の操作を行います。
サービス デスクトップ アプリを開きます。 ( [スタート] を選択し、検索ボックスに 「services.msc 」と入力し、 サービス アプリを選択するか Enter キーを押します)。
詳細ウィンドウで、[OpenSSH SSH Server] をダブルクリックします。
[ 全般 ] タブの [ スタートアップの種類 ] ドロップダウン メニューで、[ 自動 ] を選択し、[ OK] を選択します。
サービスを開始するには、[開始] を選択 します。
Note
OpenSSH サーバーをインストールすると、 OpenSSH-Server-In-TCP
という名前のファイアウォール規則が作成され、有効になります。 この規則では、ポート 22 で受信 SSH トラフィックを許可します。 この規則が有効になっておらず、このポートが開いていない場合、接続は拒否またはリセットされます。
PowerShell を使用して OpenSSH をインストールするには:
PowerShell を管理者として実行します。
OpenSSH が使用可能になっていることを確認するには、次のコマンドレットを実行します。
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
どちらもインストールされていない場合は、このコマンドにより次の出力が返されます。
Name : OpenSSH.Client~~~~0.0.1.0
State : NotPresent
Name : OpenSSH.Server~~~~0.0.1.0
State : NotPresent
その後、次のコマンドレットを実行して、必要に応じてサーバーまたはクライアント コンポーネントをインストールします。
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
両方のコマンドから、次の出力が返されます。
Path :
Online : True
RestartNeeded : False
初めての使用のために OpenSSH Server を起動して構成するには、管理者特権の PowerShell プロンプトを開き (右クリックして [管理者として実行] を選択)、次のコマンドを実行して sshd service
を起動します。
# Start the sshd service
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}
OpenSSH サーバーとクライアントのインストール
Windows Server デバイスに OpenSSH コンポーネントをインストールするには:
[スタート] を選択し、検索ボックスに「オプション機能」と入力し、[オプション機能の追加] を選択します。
一覧を確認して、OpenSSH が既にインストールされているかどうかを確認します。 されていない場合は、ページの上部にある [機能の追加] を選択し、次のようにします。
サービス デスクトップ アプリを開きます。 ( [スタート] を選択し、検索ボックスに 「services.msc 」と入力し、 サービス アプリを選択するか Enter キーを押します)。
詳細ウィンドウで、[OpenSSH SSH Server] をダブルクリックします。
[ 全般 ] タブの [ スタートアップの種類 ] ドロップダウン メニューで、[ 自動 ] を選択し、[ OK] を選択します。
サービスを開始するには、[開始] を選択 します。
Note
OpenSSH サーバーをインストールすると、 OpenSSH-Server-In-TCP
という名前のファイアウォール規則が作成され、有効になります。 この規則では、ポート 22 で受信 SSH トラフィックを許可します。 この規則が有効になっておらず、このポートが開いていない場合、接続は拒否またはリセットされます。
PowerShell を使用して OpenSSH をインストールするには:
PowerShell を管理者として実行します。
OpenSSH が使用可能になっていることを確認するには、次のコマンドレットを実行します。
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
どちらもインストールされていない場合は、このコマンドにより次の出力が返されます。
Name : OpenSSH.Client~~~~0.0.1.0
State : NotPresent
Name : OpenSSH.Server~~~~0.0.1.0
State : NotPresent
その後、次のコマンドレットを実行して、必要に応じてサーバーまたはクライアント コンポーネントをインストールします。
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
両方のコマンドから、次の出力が返されます。
Path :
Online : True
RestartNeeded : False
初めての使用のために OpenSSH Server を起動して構成するには、管理者特権の PowerShell プロンプトを開き (右クリックして [管理者として実行] を選択)、次のコマンドを実行して sshd service
を起動します。
# Start the sshd service
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}
OpenSSH サーバーとクライアントのインストール
Windows Server デバイスに OpenSSH コンポーネントをインストールするには:
[スタート] を選択し、検索ボックスに「オプション機能」と入力し、[オプション機能] (オプション機能の管理とも呼ばれます) を選択します。
一覧を確認して、OpenSSH が既にインストールされているかどうかを確認します。 されていない場合は、ページの上部にある [機能の追加] を選択し、次のようにします。
サービス デスクトップ アプリを開きます。 ( [スタート] を選択し、検索ボックスに 「services.msc 」と入力し、 サービス アプリを選択するか Enter キーを押します)。
詳細ウィンドウで、[OpenSSH SSH Server] をダブルクリックします。
[ 全般 ] タブの [ スタートアップの種類 ] ドロップダウン メニューで、[ 自動 ] を選択し、[ OK] を選択します。
サービスを開始するには、[開始] を選択 します。
Note
OpenSSH サーバーをインストールすると、 OpenSSH-Server-In-TCP
という名前のファイアウォール規則が作成され、有効になります。 この規則では、ポート 22 で受信 SSH トラフィックを許可します。 この規則が有効になっておらず、このポートが開いていない場合、接続は拒否またはリセットされます。
PowerShell を使用して OpenSSH をインストールするには:
PowerShell を管理者として実行します。
OpenSSH が使用可能になっていることを確認するには、次のコマンドレットを実行します。
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
どちらもインストールされていない場合は、このコマンドにより次の出力が返されます。
Name : OpenSSH.Client~~~~0.0.1.0
State : NotPresent
Name : OpenSSH.Server~~~~0.0.1.0
State : NotPresent
その後、次のコマンドレットを実行して、必要に応じてサーバーまたはクライアント コンポーネントをインストールします。
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
両方のコマンドから、次の出力が返されます。
Path :
Online : True
RestartNeeded : False
初めての使用のために OpenSSH Server を起動して構成するには、管理者特権の PowerShell プロンプトを開き (右クリックして [管理者として実行] を選択)、次のコマンドを実行して sshd service
を起動します。
# Start the sshd service
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
} else {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
}
OpenSSH Server への接続
インストールすると、OpenSSH クライアントがインストールされている Windows または Windows Server デバイスから OpenSSH Server に接続できます。 PowerShell プロンプトから、次のコマンドを実行します。
ssh ___domain\username@servername
接続すると、次のような出力が表示されます。
The authenticity of host 'servername (10.00.00.001)' can't be established.
ECDSA key fingerprint is SHA256:(<a large string>).
Are you sure you want to continue connecting (yes/no)?
「はい」と入力すると、そのサーバーが Windows クライアント上の既知の SSH ホストの一覧に追加されます。
この時点で、サービスからパスワードの入力を求められます。 セキュリティ上の予防措置として、パスワードの文字は入力時に表示されません。
接続すると、次の Windows コマンド シェル プロンプトが表示されます。
___domain\username@SERVERNAME C:\Users\username>
OpenSSH サーバーを無効にする
サーバー マネージャーでは、 sshd
サービスを無効にすることができます。
サーバー マネージャーを使用して SSHD を無効にするには:
サーバー マネージャーの左側のナビゲーション ウィンドウで、[ローカル サーバー] を選択します。
[プロパティ] ウィンドウで、リモート SSH アクセスを見つけます。
OpenSSH サービスを無効にするには、[ 無効] を選択します。
Note
特定のユーザーまたはグループがリモート アクセスに OpenSSH を使用することを許可または制限する必要がある場合は、それらを OpenSSH Users ユーザー グループに追加します。
PowerShell を使用して SSHD を無効にするには:
管理者として PowerShell 開き、次のコマンドレットを実行して SSHD サービスを開始します。
# Stop the sshd service
Stop-Service sshd
オプションではあるものの推奨されている次のコマンドレットを実行して SSHD を自動的に開始し、有効な状態を維持することもできます。
Set-Service -Name sshd -StartupType 'Disabled'
最後に、次のコマンドを実行して、既定の SSHD ファイアウォール規則を無効にします。
if ((Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' is being disabled."
Disable-NetFirewallRule -Name 'OpenSSH-Server-In-TCP'
} else {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, disable failed..."
}
OpenSSH サーバーとクライアントのアンインストール
Windows の設定を使用して OpenSSH をアンインストールするには:
[スタート] を選択し、検索ボックスに「オプション機能」と入力し、[オプション機能] を選択します。
一覧をスキャンして、OpenSSH がインストールされているかどうかを確認します。
PowerShell を使用して OpenSSH コンポーネントをアンインストールするには、次の手順に従います。
PowerShell を管理者として開きます。
OpenSSH を削除するには、次のコマンドを使用します。
# Uninstall the OpenSSH Client
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Uninstall the OpenSSH Server
Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
最後に、次のコマンドを実行してファイアウォール規則を削除します。
if ((Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' is being removed."
Remove-NetFirewallRule -Name 'OpenSSH-Server-In-TCP'
} else {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, removal failed..."
}
OpenSSH サーバーとクライアントのアンインストール
Windows の設定を使用して OpenSSH をアンインストールするには:
[ スタート] を選択し、検索ボックスに「 オプション機能 」と入力し、[ オプション機能 ] を選択します ( オプション機能の管理 または オプションの機能履歴の表示とも呼ばれます)。
一覧で、 OpenSSH クライアント または OpenSSH サーバーを選択します。
[ アンインストール] を選択します。
PowerShell を使用して OpenSSH コンポーネントをアンインストールするには、次の手順に従います。
PowerShell を管理者として開きます。
OpenSSH を削除するには、次のコマンドを使用します。
# Uninstall the OpenSSH Client
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Uninstall the OpenSSH Server
Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
最後に、次のコマンドを実行してファイアウォール規則を削除します。
if ((Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' is being removed."
Remove-NetFirewallRule -Name 'OpenSSH-Server-In-TCP'
} else {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, removal failed..."
}
アンインストール時にサービスが使用されていた場合は、Windows を再起動する必要があります。
次のステップ
OpenSSH Server for Windows のインストールが完了したので、その使用方法を学ぶのに役立つ記事をいくつか紹介します。