web-dev-qa-db-ja.com

PSCPはホストキーを受け入れません

スクリプトからWindows上でpscpを実行しています。追加した場合

echo y | pscp.exe...

できます。ただし、を使用してホストキーを受け入れるように取得できません

pscp.exe -hostkey aa:bb:cc...

私も試しました

pscp.exe -hostkey "ssh-rsa 2048 aa:bb:cc..."

これも機能しません。次のエラーが発生するたびに:

Fatal: Host key did not appear in manually configured list

これがどのように機能するか誤解しましたか?これは完全に自動化する必要があります。キーはユーザーレジストリコンテキストに保存されるため、手動で追加することはできません。このスクリプトは、サービスアカウントを使用して、場合によっては複数のマシンでスケジュールされたタスクとして実行する必要があります。

-hostkeyの正しい使用法は何ですか?

誤解を避けるために、はい、それは正しいアルゴリズムとキーの長さです。はい、私は実際のフィンガープリントを使用しており、例で使用されている「aa:bb:cc ...」ではありません。

1
Matt G

これは正しい使用法です:

C:\>plink -pw password -hostkey 01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16 username@hostname

そしてこれは機能します:

C:\>plink -pw password -hostkey "RSA 2048 01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16" username@hostname

しかし、@ dave_thompson_085が述べたように...これは次のようにも機能するため、プログラムはスペースで区切られた追加の単語を無視しているようです。

C:\>plink -pw password -hostkey "ASDF 01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16 ASDF" username@hostname

キーはハンドシェイクで期待されるものと一致する必要があることがわかりました(-Hostkeyオプションを指定しないことで見つかりました)。

C:\>plink hostname
The server's Host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16
If you trust this Host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this Host, press Return to abandon the
connection.
Store key in cache? (y/n)

このコマンドは、サーバーで生成されたキーを表示します。

$ ls -1 /etc/ssh/ssh_Host_*.pub
/etc/ssh/ssh_Host_dsa_key.pub
/etc/ssh/ssh_Host_key.pub
/etc/ssh/ssh_Host_rsa_key.pub

これらのコマンドは、キーフィンガープリントを表示します(上記の前のコマンドで表示されたファイル名を使用)。

$ ssh-keygen -l -f /etc/ssh/ssh_Host_rsa_key
2048 01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16 /etc/ssh/ssh_Host_rsa_key.pub (RSA)
$ ssh-keygen -l -f /etc/ssh/ssh_Host_dsa_key
1024 01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16 /etc/ssh/ssh_Host_dsa_key.pub (DSA)
1
kttii