Windowsサーバーにてsshを利用するためにはsshサーバーを構築しなければならないです。それを構築するとZabbixまたはJob ArrangerでAgentlessの利用でできるようになります。ここではsshdサーバーv0.0.17.0を利用します。
でOpenSSH-Win64.zipをDownloadします。
僕の場合はC:\tmp下に作りました。
C:\tmp\OpenSSH-Win64>powershell install-sshd.ps1
install-sshd.ps1 : 用語 'install-sshd.ps1' は、コマンドレット、関数、スクリプト
ファイル、または操作可能なプログラムの名前として認識されません。名前が正しく記
述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認し
てから、再試行してください。
発生場所 行:1 文字:1
+ install-sshd.ps1
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (install-sshd.ps1:String) [], Co
mmandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
C:\tmp\OpenSSH-Win64>
この場合は
https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH
を参考しながらインストールします。
C:\tmp\OpenSSH-Win64>powershell -ExecutionPolicy Bypass -File install-sshd.ps1
[SC] SetServiceObjectSecurity SUCCESS
[SC] ChangeServiceConfig SUCCESS
[SC] ChangeServiceConfig2 SUCCESS
sshd and ssh-agent services successfully installed
C:\tmp\OpenSSH-Win64>.\ssh-keygen.exe -A
.\ssh-keygen.exe: generating new host keys: RSA DSA ECDSA ED25519
C:\tmp\OpenSSH-Win64>powershell -ExecutionPolicy Bypass -File FixHostFilePermiss
ions.ps1
[*] C:\tmp\OpenSSH-Win64\sshd_config
'BUILTIN\Users' should not have access to 'C:\tmp\OpenSSH-Win64\sshd_config'..
Shall I remove this access?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'BUILTIN\Users' has no more access to 'C:\tmp\OpenSSH-Win64\sshd_config'.
'NT SERVICE\sshd' now has Read access to 'C:\tmp\OpenSSH-Win64\sshd_config'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_dsa_key
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_dsa_key'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_dsa_key'.
'WORK1\Administrator' has no more access to 'C:\tmp\OpenSSH-Win64\ssh_host_dsa_k
ey'.
'NT SERVICE\sshd' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_dsa_key'
.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_dsa_key.pub
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_dsa_key.pub'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_dsa_key.pub'.
'WORK1\Administrator' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_dsa_
key.pub'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key'.
'WORK1\Administrator' has no more access to 'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa
_key'.
'NT SERVICE\sshd' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_ke
y'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key.pub
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key.pub'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key.pub'.
'WORK1\Administrator' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_ecds
a_key.pub'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key'.
'WORK1\Administrator' has no more access to 'C:\tmp\OpenSSH-Win64\ssh_host_ed255
19_key'.
'NT SERVICE\sshd' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_ed25519_
key'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key.pub
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key.pub'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key.pub'.
'WORK1\Administrator' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_ed25
519_key.pub'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_rsa_key
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_rsa_key'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_rsa_key'.
'WORK1\Administrator' has no more access to 'C:\tmp\OpenSSH-Win64\ssh_host_rsa_k
ey'.
'NT SERVICE\sshd' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_rsa_key'
.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_rsa_key.pub
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_rsa_key.pub'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_rsa_key.pub'.
'WORK1\Administrator' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_rsa_
key.pub'.
Repaired permissions
Done.
C:\tmp\OpenSSH-Win64>
コマンドを順番で纏め、
1.powershell -ExecutionPolicy Bypass -File install-sshd.ps1
2..\ssh-keygen.exe -A
3.powershell -ExecutionPolicy Bypass -File FixHostFilePermissions.ps1
聞かれると全部 Aで回答します。
4. powershell New-NetFirewallRule -Protocol TCP -LocalPort 22 -Direction Inbound -Action Allow -DisplayName sshd
Firewall開放
1.Win32-OpenSSH Download
https://github.com/PowerShell/Win32-OpenSSH/releasesでOpenSSH-Win64.zipをDownloadします。
2.Windows Serverで設置
2.1 OpenSSH-Win64フォルダ作成
DownloadしたOpenSSH-Win64.zipファイルを適当な場所で解凍します。僕の場合はC:\tmp下に作りました。
2.2 インストールします。
作成したファイルのinstall-sshd.ps1をPowershellでインストールします。C:\tmp\OpenSSH-Win64>powershell install-sshd.ps1
install-sshd.ps1 : 用語 'install-sshd.ps1' は、コマンドレット、関数、スクリプト
ファイル、または操作可能なプログラムの名前として認識されません。名前が正しく記
述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認し
てから、再試行してください。
発生場所 行:1 文字:1
+ install-sshd.ps1
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (install-sshd.ps1:String) [], Co
mmandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
C:\tmp\OpenSSH-Win64>
この場合は
https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH
を参考しながらインストールします。
C:\tmp\OpenSSH-Win64>powershell -ExecutionPolicy Bypass -File install-sshd.ps1
[SC] SetServiceObjectSecurity SUCCESS
[SC] ChangeServiceConfig SUCCESS
[SC] ChangeServiceConfig2 SUCCESS
sshd and ssh-agent services successfully installed
C:\tmp\OpenSSH-Win64>.\ssh-keygen.exe -A
.\ssh-keygen.exe: generating new host keys: RSA DSA ECDSA ED25519
C:\tmp\OpenSSH-Win64>powershell -ExecutionPolicy Bypass -File FixHostFilePermiss
ions.ps1
[*] C:\tmp\OpenSSH-Win64\sshd_config
'BUILTIN\Users' should not have access to 'C:\tmp\OpenSSH-Win64\sshd_config'..
Shall I remove this access?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'BUILTIN\Users' has no more access to 'C:\tmp\OpenSSH-Win64\sshd_config'.
'NT SERVICE\sshd' now has Read access to 'C:\tmp\OpenSSH-Win64\sshd_config'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_dsa_key
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_dsa_key'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_dsa_key'.
'WORK1\Administrator' has no more access to 'C:\tmp\OpenSSH-Win64\ssh_host_dsa_k
ey'.
'NT SERVICE\sshd' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_dsa_key'
.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_dsa_key.pub
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_dsa_key.pub'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_dsa_key.pub'.
'WORK1\Administrator' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_dsa_
key.pub'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key'.
'WORK1\Administrator' has no more access to 'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa
_key'.
'NT SERVICE\sshd' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_ke
y'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key.pub
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key.pub'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_ecdsa_key.pub'.
'WORK1\Administrator' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_ecds
a_key.pub'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key'.
'WORK1\Administrator' has no more access to 'C:\tmp\OpenSSH-Win64\ssh_host_ed255
19_key'.
'NT SERVICE\sshd' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_ed25519_
key'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key.pub
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key.pub'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_ed25519_key.pub'.
'WORK1\Administrator' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_ed25
519_key.pub'.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_rsa_key
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_rsa_key'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_rsa_key'.
'WORK1\Administrator' has no more access to 'C:\tmp\OpenSSH-Win64\ssh_host_rsa_k
ey'.
'NT SERVICE\sshd' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_rsa_key'
.
Repaired permissions
[*] C:\tmp\OpenSSH-Win64\ssh_host_rsa_key.pub
Current owner: 'WORK1\Administrator'. 'NT AUTHORITY\SYSTEM' should own
'C:\tmp\OpenSSH-Win64\ssh_host_rsa_key.pub'.
Shall I set the file owner?
[Y] はい(Y) [A] すべて続行(A) [N] いいえ(N) [L] すべて無視(L) [S] 中断(S)
[?] ヘルプ(既定値は "Y"): A
'NT AUTHORITY\SYSTEM' now owns 'C:\tmp\OpenSSH-Win64\ssh_host_rsa_key.pub'.
'WORK1\Administrator' now has Read access to 'C:\tmp\OpenSSH-Win64\ssh_host_rsa_
key.pub'.
Repaired permissions
Done.
C:\tmp\OpenSSH-Win64>
コマンドを順番で纏め、
1.powershell -ExecutionPolicy Bypass -File install-sshd.ps1
2..\ssh-keygen.exe -A
3.powershell -ExecutionPolicy Bypass -File FixHostFilePermissions.ps1
聞かれると全部 Aで回答します。
4. powershell New-NetFirewallRule -Protocol TCP -LocalPort 22 -Direction Inbound -Action Allow -DisplayName sshd
Firewall開放
2.3 sshd_configを編集
最後の部分に
PidFile C:/tmp/OpenSSH-Win64/sshd.pidを追記します。
意味はpidファイルを作成する場所です。
sshd.pidファイルの書く権限がないと
sshd起動後logファイルに
error: Couldn't create pid file "./sshd.pid": Permission denied
error: Couldn't create pid file "./sshd.pid": Permission denied
エラーが起きます。
必ずsshd プロセスが書ける場所に指定お願いいたします。
2.4 Windowsのサービスから起動
インストールが完了すると
Windowsマークがあるツールバーで右クリックをしてタスクマネージャーを起動してサービスをクリックします。
そこにはsshdとssh-agentが見られます。
それを右クリックをして起動かけます。
3.Linux Serverから接続
[root@localhost ~]# ssh Administrator@parkssh
The authenticity of host 'parkssh (192.168.xxx.xxx)' can't be established.
ECDSA key fingerprint is xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'parkssh' (ECDSA) to the list of known hosts.
Administrator@parkssh's password:
Microsoft Windows [Version 6.3.9600] (c) 2013 Microsoft Corporation. All rights reserved.
Administrator@WORK1 C:\Users\Administrator>dir ドライブ C のボリューム ラベルがありません。 ボリューム シリアル番号は 6AC7-8328 です
C:\Users\Administrator のディレクトリ
2017/07/02 10:57 <DIR> . 2017/07/02 10:57 <DIR> .. 2017/07/02 10:58 <DIR> .ssh 2017/03/18 18:50 <DIR> .VirtualBox 2017/03/02 20:54 <DIR> Contacts 2017/03/02 20:54 <DIR> Desktop 2017/07/02 18:04 <DIR> Documents 2017/06/28 22:19 <DIR> Downloads 2017/03/02 20:54 <DIR> Favorites 2017/03/02 20:54 <DIR> Links 2017/03/02 20:54 <DIR> Music 2017/03/02 20:54 <DIR> Pictures 2017/03/02 20:54 <DIR> Saved Games 2017/03/02 20:54 <DIR> Searches 2017/03/02 20:54 <DIR> Videos 2017/03/18 12:34 <DIR> VirtualBox VMs 0 個のファイル 0 バイト 16 個のディレクトリ 49,632,653,312 バイトの空き領域
Administrator@WORK1 C:\Users\Administrator>
接続できました。
これで、ZabbixとJob ArrangerのAgentlessができます。
4.エラー対応
1.
Linuxから接続ができない場合
[root@localhost ~]# ssh Administrator@parkssh
Read from socket failed: Connection reset by peer
[root@localhost ~]#
または
windows のC:\tmp\OpenSSH-Win64\logs\sshd.logログに
fatal: sshd_hostkey_sign: ssh_agent_sign failed: agent refused operation
または
windows のC:\tmp\OpenSSH-Win64\logs\sshd.logログに
fatal: sshd_hostkey_sign: ssh_agent_sign failed: agent refused operation
になる場合は
powershell -ExecutionPolicy Bypass -File FixHostFilePermissions.ps1
作業が必要です。”コマンドを順番で纏め、”をご参考ください。
2.
[root@localhost ~]# ssh Administrator@parkssh
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:1
ECDSA host key for 192.168.xxx.xxx has changed and you have requested strict Host key verification failed.
になる場合は
.ssh/known_hostsファイルを削除ください。
以上です。ご参照ください。
0 件のコメント:
コメントを投稿