1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows版 OpenSSH 関連のチートシート

Posted at

Windows版 OpenSSH で使えるチートシートです。

1. OpenSSH の Version 確認コマンド

使っている OpenSSH ってバージョンいくつだっけ?とたまに思いますよね。ssh -V で確認できますが、PowerShell で Get-Command ssh を実行するほうが詳細に確認できたりします。

コマンド例
Get-Command ssh | Format-List *
# or
ssh -V
実行結果例
Get-Command ssh | Format-List *

HelpUri            :
FileVersionInfo    : File:             C:\WINDOWS\System32\OpenSSH\ssh.exe
                     InternalName:
                     OriginalFilename:
                     FileVersion:      9.5.2.1
                     FileDescription:
                     Product:          OpenSSH for Windows
                     ProductVersion:   OpenSSH_9.5p1 for Windows
                     Debug:            False
                     Patched:          False
                     PreRelease:       False
                     PrivateBuild:     False
                     SpecialBuild:     False
                     Language:         英語 (米国)

Path               : C:\WINDOWS\System32\OpenSSH\ssh.exe
Extension          : .exe
Definition         : C:\WINDOWS\System32\OpenSSH\ssh.exe
Source             : C:\WINDOWS\System32\OpenSSH\ssh.exe
Version            : 9.5.2.1
Visibility         : Public
OutputType         : {System.String}
Name               : ssh.exe
CommandType        : Application
ModuleName         :
Module             :
RemotingCapability : PowerShell
Parameters         :
ParameterSets      :

ssh -V
OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2

2. OpenSSH のインストールパス

デフォルトでインストールされている OpenSSH は、C:\Windows\System32\OpenSSH に配置されています。

ssh_folder_500.png

Github に公開されているバージョンをインストールすると特に変更していなければ、C:\Program Files\OpenSSH にインストールされます。

3. OpenSSH サーバーの Config & Log ファイル

Config ファイル → C:\ProgramData\ssh\sshd_config
ssh_config_400.png

Log ファイル → C:\ProgramData\ssh\logs\sshd.log
ssh_log_300.png

4. sshd サービスの再起動

sshd サービスの再起動は、OpenSSH サーバーで問題が起きた時や Config ファイルの内容を変更した時に設定を反映させるために実行します。

PowerShell
Restart-Service -Force -Name "sshd"

Restart-Service (Microsoft.PowerShell.Management)
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/restart-service

5. ログ出力

OpenSSH クライアント側

ssh コマンドや sftp コマンドに -vvv オプションを付与することで、クライアント側での DEBUG3 レベルの詳細なログが標準エラー出力に表示されます。

コマンド例
ssh -vvv "domain\username@servername"
sftp -vvv "domain\username@servername"

servername は、OpenSSH サーバー側が Windows であれば、net.exe を実行することで確認できます。

コマンド例
net config workstation 

OpenSSH サーバー側

デフォルトでは、ログは出力されないので、C:\ProgramData\ssh\logs\sshd.log にログを出力させるには、C:\ProgramData\ssh\sshd_config ファイルを開き、編集する必要があります。DEBUG3 レベルのログを出力させるには、以下のように編集します。

変更前(抜粋)
# Logging
#SyslogFacility AUTH
#LogLevel INFO
変更後(抜粋)
# Logging
SyslogFacility LOCAL0
LogLevel DEBUG3

編集後、sshd サービスを再起動すると、以後、C:\ProgramData\ssh\logs 配下に sshd.log ファイルが出力されるようになります。

さいごに

OpenSSH は、Windows に標準でインストールされていますが、最新のバージョンを使用したい場合は、Github で公開されているので、そちらを導入してみてください。導入方法は、前に投稿してます。

参考URL

Get started with OpenSSH for Windows | Microsoft Learn
https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse?tabs=gui

OpenSSH Server configuration for Windows
https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_server_configuration

PowerShell/Win32-OpenSSH Wiki · GitHub
https://github.com/PowerShell/Win32-OpenSSH

PowerShell/openssh-portable: Portable OpenSSH
https://github.com/PowerShell/openssh-portable

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?