web-dev-qa-db-ja.com

AWSEC2サーバーの新規ユーザーにPuTTY秘密鍵を使用する

AWSEC2インスタンスを開始しました。 Amazonによって生成されたSSH秘密鍵を使用して、ユーザーec2-userでインスタンスに接続できます。

http://docs.aws.Amazon.com/AWSEC2/latest/UserGuide/managing-users.html の指示に従って、新しいユーザー「bob」の認証情報を追加しました。

新しいユーザーボブを作成し、PuTTY KeyGeneratorを使用して新しい公開鍵と秘密鍵のセットを生成しました。公開鍵を/home/bob/.ssh/authorized_keysのEC2インスタンスに移動しました

/home/bob/.sshと/home/bob/.ssh/authorized_keysの所有者とグループをbob:bobに変更しました

/home/bob/.sshのアクセス許可を700に変更しました

/home/bob/.ssh/authorized_keysのアクセス許可を600に変更しました

EC2インスタンスにbobとしてSSHで接続しようとすると、bobの秘密鍵を使用してエラーが発生します。

PuTTY Fatal Error
Disconnected: No supported authentication methods available (server sent: pulickey,gssapi-keyex,gssapi-with-mic)

PuTTYコンソールには次のように表示されます。

Using username "bob".
Server refused our key

また、コマンドラインからbobの秘密鍵を使用してEC2インスタンスにSSHで接続しようとしましたが、一般的ではありませんでした。キーのパスフレーズを受け入れませんでした。パスフレーズのないキーペアも試してみましたが、それでもパスワードの入力を求められ、サーバーにアクセスできませんでした。

これが私の非常に冗長な出力です

$ ssh -vvv -i bobs_key.ppk  [email protected]
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug2: ssh_connect: needpriv 0
debug1: Connecting to ec2-12-345-678-910.us-west-2.compute.amazonaws.com [12.345.678.910] port 22.
debug1: Connection established.
debug3: Not a RSA1 key file bobs_key.ppk.
debug2: key_type_from_name: unknown key type 'PuTTY-User-Key-File-2:'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'Encryption:'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'Comment:'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'Public-Lines:'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type 'Private-Lines:'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type 'Private-MAC:'
debug3: key_read: missing keytype
debug1: identity file bobs_key.ppk type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.4
debug1: match: OpenSSH_6.4 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.6
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-ctr,aes192-ctr,a
es256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,[email protected],aes128-ctr,aes192-ctr,a
es256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-grou
p14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ecdsa-sha2-nistp256
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,ae
s192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,ae
s192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-512-etm@
openssh.com,[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,h
mac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-512-etm@
openssh.com,[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,h
mac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_init: found hmac-md5
debug1: kex: server->client aes128-cbc hmac-md5 none
debug2: mac_init: found hmac-md5
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 140/256
debug2: bits set: 512/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: check_Host_in_hostfile: filename /c/Users/bob/.ssh/known_hosts
debug3: check_Host_in_hostfile: match line 1
debug3: check_Host_in_hostfile: filename /c/Users/bob/.ssh/known_hosts
debug3: check_Host_in_hostfile: match line 1
debug1: Host 'ec2-12-345-678-910.us-west-2.compute.amazonaws.com' is known and matches the RSA Host key.
debug1: Found key in /c/Users/bob/.ssh/known_hosts:1
debug2: bits set: 501/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: bobs_key.ppk (0x0)
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic
debug3: preferred 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: Trying private key: bobs_key.ppk
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key 'bobs_key.ppk':
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug2: bad passphrase given, try again...
Enter passphrase for key 'bobs_key.ppk':
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug2: bad passphrase given, try again...
Enter passphrase for key 'bobs_key.ppk':
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug2: bad passphrase given, try again...
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

PuTTYログ:

2015-02-08 08:35:15 Looking up Host "ec2-12-345-678-910.us-west-2.compute.amazonaws.com"
2015-02-08 08:35:15 Connecting to 12.345.678.910 port 22
2015-02-08 08:35:15 Server version: SSH-2.0-OpenSSH_6.4
2015-02-08 08:35:15 Using SSH protocol version 2
2015-02-08 08:35:15 We claim version: SSH-2.0-PuTTY_Release_0.62
2015-02-08 08:35:15 Doing Diffie-Hellman group exchange
2015-02-08 08:35:15 Doing Diffie-Hellman key exchange with hash SHA-256
2015-02-08 08:35:16 Host key fingerprint is:
2015-02-08 08:35:16 ssh-rsa 2048 b6:76:a5:c6:06:dc:3c:d6:c2:65:fe:f5:55:27:b9:ef
2015-02-08 08:35:16 Initialised AES-256 SDCTR client->server encryption
2015-02-08 08:35:16 Initialised HMAC-SHA1 client->server MAC algorithm
2015-02-08 08:35:16 Initialised AES-256 SDCTR server->client encryption
2015-02-08 08:35:16 Initialised HMAC-SHA1 server->client MAC algorithm
2015-02-08 08:35:16 Reading private key file "C:\bob.ppk"
2015-02-08 08:35:16 Pageant is running. Requesting keys.
2015-02-08 08:35:16 Pageant has 1 SSH-2 keys
2015-02-08 08:35:16 Configured key file not in Pageant
2015-02-08 08:35:16 Offered public key
2015-02-08 08:35:16 Server refused our key
2015-02-08 08:35:16 Using SSPI from SECUR32.DLL
2015-02-08 08:35:16 Attempting GSSAPI authentication
2015-02-08 08:35:16 GSSAPI authentication request refused
2015-02-08 08:35:16 Disconnected: No supported authentication methods available (server sent: publickey,gssapi-keyex,gssapi-with-mic)

サーバーsshdログ:

Feb  8 08:35:16 ip-101-10-101-1 sshd[3182]: error: Received disconnect from 22.33.44.555: 14: No supported authentication methods available [preauth]

これはPuTTYによって生成された公開鍵の例です

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20150209"
AAAAB3NzaC1yc2EAAAABJQAAAQEAs2f7SVX8KOu0RvzQh0r6uwWS/TB5uXO7+QEs
CxF+0CF3vwLeOn+cNw1HQHy7EDHhGw4eYvL/ErbIyv4I8HgGe/IFe4qPUOMy3vtz
ZNjqemBsy32Lgsx/flQBYLW+XzYC4LeZv3TSZjfYyIk8ilRBOzdkP4CdYeK0rPRb
PPtlLQY5l95h1UnmuORNgA93yLqvKI/dSnkvKyTrJoCGbRXr5pept5Y9LSEHYlEa
drBpogsF9LYj/HDeaoIjBhGQu+CZRDzZSxgtv3+nePEkoeV1xC8tyJ83JiHcrX3P
bjouJHLLTWa2tl40XM913dkUSsbha2Fbd0wBchry9y2BlpUA9Q==
---- END SSH2 PUBLIC KEY ----

これは、それに付随する秘密鍵の例です

PuTTY-User-Key-File-2: ssh-rsa
Encryption: aes256-cbc
Comment: rsa-key-20150209
Public-Lines: 6
AAAAB3NzaC1yc2EAAAABJQAAAQEAs2f7SVX8KOu0RvzQh0r6uwWS/TB5uXO7+QEs
CxF+0CF3vwLeOn+cNw1HQHy7EDHhGw4eYvL/ErbIyv4I8HgGe/IFe4qPUOMy3vtz
ZNjqemBsy32Lgsx/flQBYLW+XzYC4LeZv3TSZjfYyIk8ilRBOzdkP4CdYeK0rPRb
PPtlLQY5l95h1UnmuORNgA93yLqvKI/dSnkvKyTrJoCGbRXr5pept5Y9LSEHYlEa
drBpogsF9LYj/HDeaoIjBhGQu+CZRDzZSxgtv3+nePEkoeV1xC8tyJ83JiHcrX3P
bjouJHLLTWa2tl40XM913dkUSsbha2Fbd0wBchry9y2BlpUA9Q==
Private-Lines: 14
UP7YT8e9aWk159T5xO1P0MR5AbAuhTh9hzjFw98igBaYhco9ATUhOyXVumBuHnuB
1+2aiucV22XUuJIWDjRDdX3uSmUMsDXPPS4li6GOvdGMBo66bcLAqNbwNuzS7ogX
fFQ23TzsPnDbrOqwNcNOl9Suf7MA6u6s7sACFsflxAuCSRe9iiyxcRLXafvAl/AH
BD3Ltd4i49SICrjmW3vEAndX6r0QqMQ5GjzorQhu1I2b4dYdQqVAOThYSfXTR9p4
nHTvoeO+Qi7qTmzZMRUAEkh7tC+4J8idHN5e3k6hpzV8z0E7arjbtPH8gDbG1FL2
ZevCJX2s4b4bGL9a9vzxzLLg/TikZBr0QAVHtTU5sPgViCSgkeAKTeIsQcLKT/vt
Kl8UOpaalyoeRTSo9HNUEwuz99aK7WjzvKRGHIUpioqBsA7C7Yj/hLq/ofKOZQgJ
lp6bsSA0GkY5zncPHUSIrCu5xcdO9cNnKaXwf5qjJfW9udqzHRIf19Jgzo6NlymL
SxGBa+bXmn+15BIg1R23mE/VTBZoKRbmCgVRFlz4vLGIyTwbtnNIaFIZIxvhUVgs
PWIG2E4orNKZ+n1g92RI0MGoyk+WMOajAoCbMWsIEgFBTqWDAxliEgtyu/npuIFD
RbufWC/kIoSm/GVbIUoEYCDbR6KSi3OzdHCQKYufSUk67vP2BGfS9jxRe98/YhvQ
WXgxtHFWZ2p6KqDIurdWUtnoO2IYrBBeZwXSOPHuJkQaIOC6XBLFflKM4XXAdXl1
vsuAGXBnZ2BJfbxifWNvSlf60SXOeggvxYXx3euVkTpBtb6yy6AeIN7VJDjqMpn5
+Jz/PazNXUbHLZqBvBxYF9MBgACqGmV3b8dtiL3bCvFcuDv/JYTdSFtCgysgbs0s
Private-MAC: 44a5eabcdebd7d33a1c99f72016563d26b435832
3
Boundless

公開鍵を質問(authorized_keys)に示されている形式で---- BEGIN SSH2 PUBLIC KEY ----ファイルに貼り付けた場合、それは機能しません。

"OpenSSHauthorized_keysファイルに貼り付けるための公開鍵"というラベルの付いたPuTTYgenに示されている1行の形式を使用する必要があります。

それは次のようになります:

rsa-key AAAAB3NzaC1yc2EAAAABJQAAAQEAs2f7SVX8KOu0RvzQh0r6uwWS/TB5uXO7+QEsCxF+0CF3vwLeOn+cNw1HQHy7EDHhGw4eYvL/ErbIyv4I8HgGe/IFe4qPUOMy3vtzZNjqemBsy32Lgsx/flQBYLW+XzYC4LeZv3TSZjfYyIk8ilRBOzdkP4CdYeK0rPRbPPtlLQY5l95h1UnmuORNgA93yLqvKI/dSnkvKyTrJoCGbRXr5pept5Y9LSEHYlEadrBpogsF9LYj/HDeaoIjBhGQu+CZRDzZSxgtv3+nePEkoeV1xC8tyJ83JiHcrX3PbjouJHLLTWa2tl40XM913dkUSsbha2Fbd0wBchry9y2BlpUA9Q== rsa-key-20150209
5
Martin Prikryl

PuTTYで秘密/公開鍵を生成し、それらをLinuxディストリビューションに直接コピーした場合、鍵はPuTTY形式になります。 githubまたは他のサーバーに接続するために使用する前に、まずOpenSSH形式に変更する必要があります。そうしないと、誤ったエラーが表示され、パスフレーズが必要であることが通知されます。

秘密鍵のファイル拡張子が.ppkでない場合でも、PuTTY形式にすることができます。ファイルをメモ帳またはその他のテキストエディタで開いて、正しい形式を確認できます。

公開鍵のOpenSSH形式

ssh-rsa AAAAB3NzaC1yc2EAAAA…

秘密鍵のOpenSSH形式

-----BEGIN RSA PRIVATE KEY----- MIIEogIBAAKCAQEA4Jgy…

秘密鍵の新しいOpenSSH形式

-----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAA…

PuTTYからOpenSSH形式の生成キーを使用する方法:

Linuxでsshを使用して別のサーバーにログインするか、githubにログインする場合は、idのopenssh形式を使用する必要があります。手順:

  1. スタートメニューでPuttygenと入力して、Puttygenを開きます。次に、Loadを押すかAlt-lを押して、秘密鍵をロードします。

Load public-key into PuTTY gen

  1. PuTTY秘密鍵をOpenSSH形式に変換しますConversions>Export OpenSSH key

Convert to OpenSSH format

  1. キーをid_rsaとして保存します

  2. PuTTYを使用してLinuxにログインしてから別のサーバーにsshするか、githubにsshを使用している場合は、id_rsaを〜/ .ssh/id_rsaにコピーします。

  3. それでも機能しない場合は、次の手順に従ってください: https://superuser.com/a/1285777/658319

2
alpha_989

PuTTYから生成された複数のキーを試しましたが、EC2インスタンスで機能するものはありませんでした。キーペアを機能させる方法は、EC2サーバーでキーペアを生成することでした。

ssh-keygen -t rsa -b 2048

次に、秘密鍵をコンピューターに移動し、PuTTY KeyGeneratorを使用して鍵をPuTTYの形式に変換しました。これで、キーを使用してEC2インスタンスに接続できるようになりました。

0
Boundless