LoginSignup
0
0

[Microsoft] Windows Server 2022 でOpenSSHサーバをー動かす

Last updated at Posted at 2024-06-21

はじめに

以前、Windows 11 で動かしました。今回は Windows Server 2022 です。

環境

  • サーバー
    • Windows Server 2022 Standard 21H2
  • クライアント
    • Ubuntu 22.04

Windows Server 2022 に OpenSSHサーバーをインストールする

管理者権限でPowerShell を起動します。

名前を確認します。

Get-WindowsCapability -Online | where -Property Name -ILike "openssh*"

インストールします。

Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

:balloon: バージョン番号は以前と変わりませんね。

サービスを有効にして起動する

自動起動するようにします。

Set-Service -Name sshd -StartupType Automatic

起動します。

Start-Service -Name sshd

接続する

IdentitiesOnly=yes オプションをつけることで、とりあえず繋がりました。

ssh -o IdentitiesOnly=yes ホスト名

鍵認証を使えるようにする

Administratorsグループ所属のユーザーなので、$env:ProgramData\ssh\administrators_authorized_keys ファイルへ自身の公開鍵を書き込みました。

ファイルのACLも変更し、SYSTEMとAdministratorsグループ のみ にフルコントロール権限を与えます。

icacls.exe $env:ProgramData\ssh\administrators_authorized_keys /inheritance:r /grant Administrators:F /grant SYSTEM:F

既定のシェルをPowerShellにする

cmd.exeをやめてPowerShellにします。

$pspath=Get-Command powershell | Select -ExpandProperty source
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value $pspath -PropertyType String -Force

トラブルメモ

[トラブル]環境変数が反映されない

[現象]

Windows GUIから環境変数を設定しても、ssh シェル内に反映されません。

[原因]

(不明)

[解決策]

Windows を再起動します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0