Windows標準のOpenSSHを利用してSSHDを立てる方法。
SSHサーバーをインストールする
20分くらいかかるので、気長に待つ。
# 有効なバージョンの確認
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
# インストール
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
SSHDサービスを構成する
# SSHDサービスの開始
Start-Service sshd
# 自動起動に設定
Set-Service -Name sshd -StartupType 'Automatic'
# 構成状況の確認
Get-Service -Name sshd
(Get-Service -Name "sshd").StartType
SSHDを鍵認証できるように設定する
%programdata%\ssh\sshd_config
に設定ファイルがあるので、これを触る。
Ubuntuと同じOpenSSHであるため、設定方法は基本的に過去に書いたSSHDの設定方法と同じだが、管理者であればAuthorizedKeysFile
のコメントを外す必要はない。
管理者である場合、authorized_keys
はadministrators_authorized_keys
というファイル名にして%programdata%\ssh
に置く。
書き換えたらRestart-Service sshd
で再起動する。
上手く繋がらない場合は、Stop-Service sshd
でサービスを止めたうえでsshd.exe -ddd -e
で直に起動するとデバッグログが見れるので参考にする。
ファイアーウォールへの穴開け
- コントロールパネル→Windows Defender ファイアウォール→詳細設定を開く
- 受信の規則にOpenSSHが登録されているが、ポート番号が変更不能なため削除する
次のコマンドを流し、規則を作りなおす
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort <ポート番号>
Windowsに入っている古くて使いづらいPowerShellをアップグレードするところから始める。
- Powershell 7.xを入れる
- PowerShellを管理者権限で起動
Set-ExecutionPolicy RemoteSigned
を流す- hoge.ps1などの名前で適当にファイルを作り、
C:\Program Files\PowerShell\7\pwsh.exe
に関連付けする
基本はこのコマンドを流せば行けるはず
sudo apt update
sudo apt upgrade
sudo apt full-upgrade
sudo do-release-upgrade
トラブルシュート
「There is no development version of an LTS available.」というエラーが出る
sudo do-release-upgrade
の実行時に-d
オプションを外す
サービスをstop出来ないみたいなエラーが出る
自動起動していない場合、PowerShellなどからWSLを殺せば解決する
wsl --shutdown
サードパーティのリポジトリ周りでこける
コケてるリポジトリを消せばよい。以下は一例
ls -la /etc/apt/sources.list.d
sudo rm -Rf /etc/apt/sources.list.d/grafana.list*
「Some third party entries in your sources.list were disabled. You can re-enable them after the upgrade with the 'software-properties' tool or your package manager.」というエラーが出る
無視してよい
WSL上のUbuntuで動作するnginxでHTTPSに対応したサーバーを作る方法。実機でも同様の手順でいける
確認環境
Env | Ver |
---|---|
nginx | nginx/1.18.0 (Ubuntu) |
mkcert | v1.4.4 |
Ubuntu | 20.04.6 LTS |
Windows 11 | 22621.3880 |
手順
- Windows側にmkcertを入れる
- mkcertで証明書を作る
mkcert sandbox.test
- 以下のpemファイルが生成される
sandbox.test.pem
sandbox.test-key.pem
- 生成されたpemファイルを
/etc/nginx/conf.d/ssl/
に移動する /etc/nginx/conf.d/sandbox.test.conf
を作成し、以下のような記述をするserver { listen 443 ssl; client_max_body_size 100m; server_name sandbox.test; ssl_certificate conf.d/ssl/sandbox.test+1.pem; ssl_certificate_key conf.d/ssl/sandbox.test+1-key.pem; access_log /var/log/nginx/sandbox.access.log; error_log /var/log/nginx/sandbox.error.log; # ファイルホスト用 # location / { # root /usr/share/nginx/html/sandbox; # index index.html; # try_files $uri /index.html =404; # } # APサーバーへのリバプロ用 location ~ ^/.*$ { rewrite ^/.*$ / break; proxy_set_header X-Request-Path $request_uri; proxy_set_header X-Host $host; proxy_pass http://127.0.0.1:9999; } # fastcgi用 location ~ \.php$ { root /usr/share/nginx/html/sandbox; fastcgi_pass unix:/run/php/php8.0-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
- nginxを再起動する
sudo service nginx restart
他の端末に証明書を撒く方法
mkcertのRoot CAをエクスポートして他の端末に突っ込めば、他の端末でもpemが流用できる
NEC Lavie PC-GN20D72DYEDYH2YAAを買ったところ、Edgeが「組織によって管理されています」状態だったのでそれを解除した方法。
以下のレジストリコマンドを流すことで解消した。別に消さなくても支障はないが、なんとなく邪魔だったので。
reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge /v WebAppInstallForceList