0

boto を使用して EC2 に接続し、インスタンスを起動しています。インスタンスを作成したら、それに ssh する必要があります。既知のホスト ファイルに追加するには、サーバーの公開 ssh キーが必要です。boto を使用してキーを取得するにはどうすればよいですか? キー検証をバイパスしたくありません。boto コマンド シェルを使用しましたが、ソースを見ると、boto は paramiko を使用し、ssh キーのチェックをバイパスしているように見えます。誰でも助けてもらえますか?

4

1 に答える 1

1
# Check to see if specified keypair already exists.
# If we get an InvalidKeyPair.NotFound error back from EC2,
# it means that it doesn't exist and we need to create it.
try:
    key = ec2.get_all_key_pairs(keynames=[key_name])[0]
except ec2.ResponseError, e:
    if e.code == 'InvalidKeyPair.NotFound':
        print 'Creating keypair: %s' % key_name
        # Create an SSH key to use when logging into instances.
        key = ec2.create_key_pair(key_name)

        # AWS will store the public key but the private key is
        # generated and returned and needs to be stored locally.
        # The save method will also chmod the file to protect
        # your private key.
        key.save(key_dir)
    else:
        raise
于 2014-01-03T16:51:49.007 に答える