質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
公開鍵認証

公開鍵認証とは、公開鍵と秘密鍵の2つの鍵の組を利用する、SSHで利用される認証方式です。

SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

Windows Server

Windows Serverとは、Microsoft社のサーバ用オペレーティングシステムの総称です。 企業内ネットワークなどで利用されるサーバ機へ導入することを想定して開発されているため高い安定性があり、 管理機能を提供するソフトウェアが多く含まれています。

Q&A

解決済

2回答

5973閲覧

LinuxからWindowsへの公開鍵によるssh接続

work.ta.ya

総合スコア4

公開鍵認証

公開鍵認証とは、公開鍵と秘密鍵の2つの鍵の組を利用する、SSHで利用される認証方式です。

SSH

SSH(Secure Shell)は、セキュアチャネルを通してデータを交換するためのネットワークプロトコルです。リモートサーバーへのコマンド実行やファイル転送を行う時に一般的に使用されます。

Linux

Linuxは、Unixをベースにして開発されたオペレーティングシステムです。日本では「リナックス」と呼ばれています。 主にWebサーバやDNSサーバ、イントラネットなどのサーバ用OSとして利用されています。 上位500のスーパーコンピュータの90%以上はLinuxを使用しています。 携帯端末用のプラットフォームAndroidは、Linuxカーネル上に構築されています。

Windows Server

Windows Serverとは、Microsoft社のサーバ用オペレーティングシステムの総称です。 企業内ネットワークなどで利用されるサーバ機へ導入することを想定して開発されているため高い安定性があり、 管理機能を提供するソフトウェアが多く含まれています。

0グッド

0クリップ

投稿2019/08/26 12:53

前提・実現したいこと

LinuxからWindowsへの公開鍵によるssh接続をしたいです。
パスワード認証は可能ですが、公開鍵認証がNGで、公開鍵で接続したいです。
・参考にしたサイト:https://qiita.com/M_Nagata/items/722a9970dcc2a0b71612

・パスワード認証は可能

[testuser@sftp-linux .ssh]$ ssh -i id_rsa_win2 sftp001@13.xxx.xxx.xxx sftp001@13.xxx.xxx.xxx's password: Microsoft Windows [Version 10.0.17763.615] (c) 2018 Microsoft Corporation. All rights reserved. sftp001@EC2AMAZ-5KCOL7I C:\Users\sftp001> sftp001@EC2AMAZ-5KCOL7I C:\Users\sftp001> sftp001@EC2AMAZ-5KCOL7I C:\Users\sftp001>exit Connection to 13.xxx.xxx.xxx closed. [testuser@sftp-linux .ssh]$

・公開鍵認証がNG

[testuser@sftp-linux .ssh]$ ssh -i id_rsa_win2 sftp001@13.113.xxx.xxx -vvv OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 58: Applying options for * debug2: resolving "13.113.xxx.xxx" port 22 debug2: ssh_connect_direct: needpriv 0 debug1: Connecting to 13.113.xxx.xxx [13.113.xxx.xxx] port 22. debug1: Connection established. debug1: identity file id_rsa_win2 type 1 debug1: key_load_public: No such file or directory debug1: identity file id_rsa_win2-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_7.4 debug1: Remote protocol version 2.0, remote software version OpenSSH_for_Windows_8.0 debug1: match: OpenSSH_for_Windows_8.0 pat OpenSSH* compat 0x04000000 debug2: fd 3 setting O_NONBLOCK debug1: Authenticating to 13.113.xxx.xxx:22 as 'sftp001' debug3: hostkeys_foreach: reading file "/home/testuser/.ssh/known_hosts" debug3: record_hostkey: found key type ECDSA in file /home/testuser/.ssh/known_hosts:5 debug3: load_hostkeys: loaded 1 keys from 13.113.xxx.xxx debug3: order_hostkeyalgs: prefer hostkeyalgs: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 debug3: send packet: type 20 debug1: SSH2_MSG_KEXINIT sent debug3: receive packet: type 20 debug1: SSH2_MSG_KEXINIT received debug2: local client KEXINIT proposal debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,ext-info-c debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: compression ctos: none,zlib@openssh.com,zlib debug2: compression stoc: none,zlib@openssh.com,zlib debug2: languages ctos: debug2: languages stoc: debug2: first_kex_follows 0 debug2: reserved 0 debug2: peer server KEXINIT proposal debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1 debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519 debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: compression ctos: none debug2: compression stoc: none debug2: languages ctos: debug2: languages stoc: debug2: first_kex_follows 0 debug2: reserved 0 debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none debug1: kex: curve25519-sha256 need=64 dh_need=64 debug1: kex: curve25519-sha256 need=64 dh_need=64 debug3: send packet: type 30 debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug3: receive packet: type 31 debug1: Server host key: ecdsa-sha2-nistp256 SHA256:DL5Hs3TcydWqMmMzCXbLoyu3OaOPObIyQcj8gVOK1XU debug3: hostkeys_foreach: reading file "/home/testuser/.ssh/known_hosts" debug3: record_hostkey: found key type ECDSA in file /home/testuser/.ssh/known_hosts:5 debug3: load_hostkeys: loaded 1 keys from 13.113.xxx.xxx debug1: Host '13.113.xxx.xxx' is known and matches the ECDSA host key. debug1: Found key in /home/testuser/.ssh/known_hosts:5 debug3: send packet: type 21 debug2: set_newkeys: mode 1 debug1: rekey after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug3: receive packet: type 21 debug1: SSH2_MSG_NEWKEYS received debug2: set_newkeys: mode 0 debug1: rekey after 134217728 blocks debug2: key: id_rsa_win2 (0x56554e3d26f0), explicit debug3: send packet: type 5 debug3: receive packet: type 7 debug1: SSH2_MSG_EXT_INFO received debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521> debug3: receive packet: type 6 debug2: service_accept: ssh-userauth debug1: SSH2_MSG_SERVICE_ACCEPT received debug3: send packet: type 50 debug3: receive packet: type 51 debug1: Authentications that can continue: publickey,password,keyboard-interactive debug3: start over, passed a different list publickey,password,keyboard-interactive debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Offering RSA public key: id_rsa_win2 debug3: send_pubkey_test debug3: send packet: type 50 debug2: we sent a publickey packet, wait for reply debug3: receive packet: type 51 debug1: Authentications that can continue: publickey,password,keyboard-interactive debug2: we did not send a packet, disable method debug3: authmethod_lookup keyboard-interactive debug3: remaining preferred: password debug3: authmethod_is_enabled keyboard-interactive debug1: Next authentication method: keyboard-interactive debug2: userauth_kbdint debug3: send packet: type 50 debug2: we sent a keyboard-interactive packet, wait for reply debug3: receive packet: type 51 debug1: Authentications that can continue: publickey,password,keyboard-interactive debug3: userauth_kbdint: disable: no info_req_seen debug2: we did not send a packet, disable method debug3: authmethod_lookup password debug3: remaining preferred: debug3: authmethod_is_enabled password debug1: Next authentication method: password sftp001@13.113.xxx.xxx's password: [testuser@sftp-linux .ssh]$

実施したこと

■Windows2019
・以下から、OpenSSH(v8.0.0.0p1-Beta OpenSSH-Win64.zip)導入
https://github.com/PowerShell/Win32-OpenSSH/releases
・Firewallの無効化
・ホストの認証キーを作成
.\ssh-keygen.exe -A
・ホスト認証キーのパーミッション確認

C:\OpenSSH-Win64>powershell -ExecutionPolicy Bypass -File FixHostFilePermissions.ps1 [*] C:\ProgramData\ssh\sshd_config looks good [*] C:\ProgramData\ssh\ssh_host_dsa_key looks good [*] C:\ProgramData\ssh\ssh_host_dsa_key.pub looks good [*] C:\ProgramData\ssh\ssh_host_ecdsa_key looks good [*] C:\ProgramData\ssh\ssh_host_ecdsa_key.pub looks good [*] C:\ProgramData\ssh\ssh_host_ed25519_key looks good [*] C:\ProgramData\ssh\ssh_host_ed25519_key.pub looks good [*] C:\ProgramData\ssh\ssh_host_rsa_key looks good [*] C:\ProgramData\ssh\ssh_host_rsa_key.pub looks good [*] C:\Users\sftp001.ssh\authorized_keys looks good [*] C:\Users\Administrator.ssh\authorized_keys looks good Done. C:\OpenSSH-Win64>

・.sshフォルダへ、該当ユーザのフルコントロール権限付与
イメージ説明

・以下の質問ではドメインユーザで接続したところ接続可能だったようですが、今回はWindowsローカルユーザです。
   https://teratail.com/questions/69331
・Linux-Linux同士の公開鍵認証は接続可能でした。
・Windowsの.sshフォルダや、authorized_keysの権限周りを変更し接続を試みましたが、NGでした。

ご教授いただきたく思います。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

Windows 2008 、OpenSSH v7.6.1.0-1-Bata で以下サイトのように実施したらできました。
https://qiita.com/M_Nagata/items/722a9970dcc2a0b71612
ver差分あり、根本原因は不明ですが、時間あるときに切り分けたいと思います。

ご確認、ご回答いただきありがとうございました!

投稿2019/08/27 02:00

work.ta.ya

総合スコア4

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

https://qiita.com/uura/items/df0a43cbbd61a04cc820

配置した「authorized_keys」のプロパティ画面でアクセス許可に「NT Service\sshd」を追加し、[読み取り]を許可します。

だ、そうです。いかがでしょ

投稿2019/08/26 13:53

impepc

総合スコア86

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

work.ta.ya

2019/08/27 01:11

返信ありがとうございます。 NT Service\sshd 追加し、sshd再起動しましたがNGでした。 他記事で、ssh-agent起動したら接続可能だったとの記事がありましたが、状況変わらず接続NGでした。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問