1VM::EC2::REST::keys(3)User Contributed Perl DocumentationVM::EC2::REST::keys(3)
2
3
4
7 use VM::EC2 ':standard';
8
10 Implemented:
11 DescribeKeyPairs
12 CreateKeyPair
13 ImportKeyPair
14 DeleteKeyPair
15
16 Unimplemented:
17 (none)
18
19 These methods let you manipulate ssh key pairs.
20
21 @keys = $ec2->describe_key_pairs(@names);
22 @keys = $ec2->describe_key_pairs(\%filters);
23 @keys = $ec2->describe_key_pairs(-key_name => \@names, -filter =>
24 \%filters);
25 Searches for ssh key pairs matching the provided filters and return a
26 series of VM::EC2::KeyPair objects.
27
28 Optional arguments:
29
30 -key_name A single key name or an arrayref containing a list
31 of names
32
33 -filter Filter on tags and other attributes.
34
35 The full list of key filters can be found at:
36 http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeKeyPairs.html
37
38 $key = $ec2->create_key_pair($name)
39 Create a new key pair with the specified name (required). If the key
40 pair already exists, returns undef. The contents of the new keypair,
41 including the PEM-encoded private key, is contained in the returned
42 VM::EC2::KeyPair object:
43
44 my $key = $ec2->create_key_pair('My Keypair');
45 if ($key) {
46 print $key->fingerprint,"\n";
47 print $key->privateKey,"\n";
48 }
49
50 $key = $ec2->import_key_pair($name,$public_key)
51 $key = $ec2->import_key_pair(-key_name => $name,
52 -public_key_material => $public_key)
53 Imports a preexisting public key into AWS under the specified name. If
54 successful, returns a VM::EC2::KeyPair. The public key must be an RSA
55 key of length 1024, 2048 or 4096. The method can be called with two
56 unnamed arguments consisting of the key name and the public key
57 material, or in a named argument form with the following argument
58 names:
59
60 -key_name -- desired name for the imported key pair (required)
61 -name -- shorter version of -key_name
62
63 -public_key_material -- public key data (required)
64 -public_key -- shorter version of the above
65
66 This example uses Net::SSH::Perl::Key to generate a new keypair, and
67 then uploads the public key to Amazon.
68
69 use Net::SSH::Perl::Key;
70
71 my $newkey = Net::SSH::Perl::Key->keygen('RSA',1024);
72 $newkey->write_private('.ssh/MyKeypair.rsa'); # save private parts
73
74 my $key = $ec2->import_key_pair('My Keypair' => $newkey->dump_public)
75 or die $ec2->error;
76 print "My Keypair added with fingerprint ",$key->fingerprint,"\n";
77
78 Several different formats are accepted for the key, including SSH
79 "authorized_keys" format (generated by ssh-keygen and
80 Net::SSH::Perl::Key), the SSH public keys format, and DER format. You
81 do not need to base64-encode the key or perform any other pre-
82 processing.
83
84 Note that the algorithm used by Amazon to calculate its key
85 fingerprints differs from the one used by the ssh library, so don't try
86 to compare the key fingerprints returned by Amazon to the ones produced
87 by ssh-keygen or Net::SSH::Perl::Key.
88
89 $result = $ec2->delete_key_pair($name)
90 Deletes the key pair with the specified name (required). Returns true
91 if successful.
92
94 VM::EC2
95
97 Lincoln Stein <lincoln.stein@gmail.com>.
98
99 Copyright (c) 2011 Ontario Institute for Cancer Research
100
101 This package and its accompanying libraries is free software; you can
102 redistribute it and/or modify it under the terms of the GPL (either
103 version 1, or at your option, any later version) or the Artistic
104 License 2.0. Refer to LICENSE for the full license text. In addition,
105 please see DISCLAIMER.txt for disclaimers of warranty.
106
107
108
109perl v5.34.0 2022-01-21 VM::EC2::REST::keys(3)