- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2021-06-14T15:05:22+00:00","default:admin","admin")
#author("2021-06-16T02:10:20+00:00","default:admin","admin")
-[[WindowsでOpenSSHでSFTPサーバを立てる場合の設定:https://qiita.com/sibatyu/items/36c701fc43f4a9c438ca]]
*Windows Server 2019・Windows10 [#y0c6ad5d]
-Windows Server 2019・Windows10からはOpenSSHを公式サポート
--SSHクライアントは有効化済み
--SSHサーバは自分で有効化する必要あり
---サービスの初期設定は手動、停止状態なので、必要に応じて起動、自動化する
-[[Windows Server 2019 および Windows 10 用 OpenSSH のインストール:https://docs.microsoft.com/ja-jp/windows-server/administration/openssh/openssh_install_firstuse]]
-[[Windows Server 2019で標準サポートされた「OpenSSH」がすごく便利そうだった話:https://tech-mmmm.blogspot.com/2019/06/windows-server-2019openssh.html]]
-[[OpenSSH : SSHサーバーの設定:https://www.server-world.info/query?os=Windows_Server_2019&p=ssh&f=1]]
-[[FTPサーバー : SSL/TLS の設定:https://www.server-world.info/query?os=Windows_Server_2019&p=ftp&f=4]]
*Windows Server 2016 [#u1e2e8f1]
-[[WindowsにOpenSSHをインストールする:https://obenkyolab.com/?p=1681]]
-[[WindowsServer 2016 : OpenSSH : インストール:https://www.server-world.info/query?os=Windows_Server_2016&p=openssh&f=1]]
-[[WindowsにSSH (OpenSSH)をインストールする方法:https://dawaan.com/using-ssh-in-windows/]]
**インストール [#q4dc7d24]
-[[Install Win32 OpenSSH:https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH]]
-[[Windows Server 2019 EC2インスタンスでSSHサーバーを有効にする:https://dev.classmethod.jp/articles/configure-windows-server-2019-sshd/]]
***インストール [#f676655e]
-[[https://github.com/PowerShell/Win32-OpenSSH/releases]] から最新版の OpenSSH-Win64.zip をダウンロード
-zipファイルを展開し、適当なフォルダに配置
-PowerShell を管理者権限で起動し、以下を実行
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
***ファイアウォールの設定 [#qe1220b8]
-WindowsFirewallでPort22をOpen
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
***起動 [#wd0c9f63]
net start sshd
-初回起動時に、以下に鍵ファイルが生成される
C:\ProgramData\ssh
***インストール実行例 [#ga6c6f15]
PS C:\opt\openssh> powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
[*] C:\opt\openssh\moduli
Inheritance is removed from 'C:\opt\openssh\moduli'.
'NT AUTHORITY\Authenticated Users' now has Read access to 'C:\opt\openssh\moduli'.
'BUILTIN\Users' now has Read access to 'C:\opt\openssh\moduli'.
Repaired permissions
[SC] SetServiceObjectSecurity SUCCESS
[SC] ChangeServiceConfig2 SUCCESS
[SC] ChangeServiceConfig2 SUCCESS
sshd and ssh-agent services successfully installed
PS C:\opt\openssh> New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
Name : sshd
DisplayName : OpenSSH Server (sshd)
Description :
DisplayGroup :
Group :
Enabled : True
Profile : Any
Platform : {}
Direction : Inbound
Action : Allow
EdgeTraversalPolicy : Block
LooseSourceMapping : False
LocalOnlyMapping : False
Owner :
PrimaryStatus : OK
Status : 規則は、ストアから正常に解析されました。 (65536)
EnforcementStatus : NotApplicable
PolicyStoreSource : PersistentStore
PolicyStoreSourceType : Local
PS C:\opt\openssh> net start sshd
OpenSSH SSH Server サービスを開始します..
OpenSSH SSH Server サービスは正常に開始されました。
**設定 [#g90a7c0e]
***サービス設定 [#ydc1a4f4]
-サービスの画面を起動
-サービス一覧の中に「OpenSSH SSH Server」があるので、これを右クリックし、プロパティを選択
-プロパティ画面の中のスタートアップの種類を「手動」から「自動」へ変更
***sshd_config の編集 [#aa3c13b0]
-sshd_config_default をコピーして sshd_config ファイルを作成
-必要に応じて、以下項目を編集
--Port
-[[Windows10公式のopensshサーバーを起動して、macからsshで接続するまで:https://qiita.com/hatobeam75/items/825ee10a5261835e814b]]
-インストールフォルダ(sshd.exeがあるフォルダ)に sshd_config_default があるが、設定ファイルの場所はここではない
-C:\ProgramData\ssh\sshd_config が設定ファイルのパス
-但し、エクスプローラから直接編集しようとすると「アクセス拒否」になる
-以下のようにコマンドを実行して編集する
PS> cd \ProgramData\ssh
PS> Invoke-Item sshd_config
--メモ帳などで編集
-編集
--コメントアウトする。これが有効だとAdministratorsグループ所属の場合は、.sshの下のauthorized_keysを読んでくれない
# 一番下の2行はコメントアウト
# Match Group administrators
# AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
--ログの出力先・レベル変更
# Logging
SyslogFacility LOCAL0 # LOCAL0に変更(C:\ProgramData\ssh\logs に出力されるようになる)
LogLevel DEBUG # ここは一般的なsshd_configの通り
--defaultで有効になっているが、念のためコメントアウトを解除
PubkeyAuthentication yes
***administrators_authorized_keys の作成 [#g4270207]
-[[Windows 10 で OpenSSH server 起動し公開鍵認証ログインするメモ:https://qiita.com/syoyo/items/780c3a2206c99a7568ac]]
$acl = Get-Acl C:\ProgramData\ssh\administrators_authorized_keys
$acl.SetAccessRuleProtection($true, $false)
$administratorsRule = New-Object system.security.accesscontrol.filesystemaccessrule("Administrators","FullControl","Allow")
$systemRule = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","Allow")
$acl.SetAccessRule($administratorsRule)
$acl.SetAccessRule($systemRule)
$acl | Set-Acl
***アクセス権限の変更 [#rde4723d]
-再度、管理者権限 の PowerShell 上で OpenSSH インストールフォルダに移動
-[.\FixHostFilePermission.ps1] を実行
--インストール中の問いには全て [Y] で OK
**トラブルシューティング [#q8137407]
-[[Windows ServerにOpenSSHを設定してつまずいたのでその解決方法:https://qiita.com/AinoMegumi/items/98053c3cdd43f82d8613]]
-[[インターネットに接続されていない環境下でWindows ServerにOpenSSHを入れる:https://qiita.com/sekai/items/e053932512d6d43e06e4]]
***デバッグモードで起動してみる [#j672b5a1]
PS C:\opt\openssh> sshd -d
debug1: sshd version OpenSSH_for_Windows_8.6, LibreSSL 3.3.3
debug1: private host key #0: ssh-rsa SHA256:*******************************************
debug1: private host key #1: ecdsa-sha2-nistp256 SHA256:*******************************************
debug1: private host key #2: ssh-ed25519 SHA256:*******************************************
debug1: rexec_argv[0]='C:\\opt\\openssh\\sshd.exe'
debug1: rexec_argv[1]='-d'
debug1: Bind to port 22 on ::.
Bind to port 22 on :: failed: Permission denied.
debug1: Bind to port 22 on 0.0.0.0.
Bind to port 22 on 0.0.0.0 failed: Permission denied.
Cannot bind any address.
***システム エラー 1067 が発生しました。 [#t686f0b6]
-[[Error 1067- on start OpenSSH by net start opensshd in windows cmd:https://stackoverflow.com/questions/39319140/error-1067-on-start-openssh-by-net-start-opensshd-in-windows-cmd]]
-解決策1:FixHostFilePermissions.ps1 の実行
powershell.exe -ExecutionPolicy Bypass -File .\FixHostFilePermissions.ps1
***Bind to port 22 on :: failed: Permission denied. [#u43d151d]
-他に22番ポートを使っているプロセスがないか、netstat コマンドを使って確認
***no matching cipher found. [#f42fc8a6]
-[[no matching cipher found. と出てSSH接続ができない。:https://qiita.com/sanapon1020/items/832fa5abb988e57ce62b]]
***It is also possible that a host key has just been changed [#i8ae1eb5]
-[[「SSHホスト鍵が変わってるよ!」と怒られたときの対処:https://qiita.com/hnw/items/0eeee62ce403b8d6a23c]]
***no matching key exchange method found [#hbca7b10]
-[[Ubuntu 20.04 で 古いサーバーにssh接続がエラーで接続できない場合:https://qiita.com/tukiyo3/items/7cd6a45f567441653c7c]]
**アンインストール [#b4e28bb6]
-管理者権限 の PowerShell 上で OpenSSH インストールフォルダに移動し、下記を実行
powershell.exe -ExecutionPolicy Bypass -File uninstall-sshd.ps1