1. Packages
  2. AWS
  3. API Docs
  4. iam
  5. SshKey
AWS v6.75.0 published on Wednesday, Apr 2, 2025 by Pulumi

aws.iam.SshKey

Explore with Pulumi AI

Uploads an SSH public key and associates it with the specified IAM user.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const user = new aws.iam.User("user", {
    name: "test-user",
    path: "/",
});
const userSshKey = new aws.iam.SshKey("user", {
    username: user.name,
    encoding: "SSH",
    publicKey: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 mytest@mydomain.com",
});
Copy
import pulumi
import pulumi_aws as aws

user = aws.iam.User("user",
    name="test-user",
    path="/")
user_ssh_key = aws.iam.SshKey("user",
    username=user.name,
    encoding="SSH",
    public_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 mytest@mydomain.com")
Copy
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		user, err := iam.NewUser(ctx, "user", &iam.UserArgs{
			Name: pulumi.String("test-user"),
			Path: pulumi.String("/"),
		})
		if err != nil {
			return err
		}
		_, err = iam.NewSshKey(ctx, "user", &iam.SshKeyArgs{
			Username:  user.Name,
			Encoding:  pulumi.String("SSH"),
			PublicKey: pulumi.String("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 mytest@mydomain.com"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var user = new Aws.Iam.User("user", new()
    {
        Name = "test-user",
        Path = "/",
    });

    var userSshKey = new Aws.Iam.SshKey("user", new()
    {
        Username = user.Name,
        Encoding = "SSH",
        PublicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 mytest@mydomain.com",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.iam.User;
import com.pulumi.aws.iam.UserArgs;
import com.pulumi.aws.iam.SshKey;
import com.pulumi.aws.iam.SshKeyArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var user = new User("user", UserArgs.builder()
            .name("test-user")
            .path("/")
            .build());

        var userSshKey = new SshKey("userSshKey", SshKeyArgs.builder()
            .username(user.name())
            .encoding("SSH")
            .publicKey("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 mytest@mydomain.com")
            .build());

    }
}
Copy
resources:
  user:
    type: aws:iam:User
    properties:
      name: test-user
      path: /
  userSshKey:
    type: aws:iam:SshKey
    name: user
    properties:
      username: ${user.name}
      encoding: SSH
      publicKey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 mytest@mydomain.com
Copy

Create SshKey Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new SshKey(name: string, args: SshKeyArgs, opts?: CustomResourceOptions);
@overload
def SshKey(resource_name: str,
           args: SshKeyArgs,
           opts: Optional[ResourceOptions] = None)

@overload
def SshKey(resource_name: str,
           opts: Optional[ResourceOptions] = None,
           encoding: Optional[str] = None,
           public_key: Optional[str] = None,
           username: Optional[str] = None,
           status: Optional[str] = None)
func NewSshKey(ctx *Context, name string, args SshKeyArgs, opts ...ResourceOption) (*SshKey, error)
public SshKey(string name, SshKeyArgs args, CustomResourceOptions? opts = null)
public SshKey(String name, SshKeyArgs args)
public SshKey(String name, SshKeyArgs args, CustomResourceOptions options)
type: aws:iam:SshKey
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. SshKeyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. SshKeyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. SshKeyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. SshKeyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. SshKeyArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var sshKeyResource = new Aws.Iam.SshKey("sshKeyResource", new()
{
    Encoding = "string",
    PublicKey = "string",
    Username = "string",
    Status = "string",
});
Copy
example, err := iam.NewSshKey(ctx, "sshKeyResource", &iam.SshKeyArgs{
	Encoding:  pulumi.String("string"),
	PublicKey: pulumi.String("string"),
	Username:  pulumi.String("string"),
	Status:    pulumi.String("string"),
})
Copy
var sshKeyResource = new SshKey("sshKeyResource", SshKeyArgs.builder()
    .encoding("string")
    .publicKey("string")
    .username("string")
    .status("string")
    .build());
Copy
ssh_key_resource = aws.iam.SshKey("sshKeyResource",
    encoding="string",
    public_key="string",
    username="string",
    status="string")
Copy
const sshKeyResource = new aws.iam.SshKey("sshKeyResource", {
    encoding: "string",
    publicKey: "string",
    username: "string",
    status: "string",
});
Copy
type: aws:iam:SshKey
properties:
    encoding: string
    publicKey: string
    status: string
    username: string
Copy

SshKey Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The SshKey resource accepts the following input properties:

Encoding
This property is required.
Changes to this property will trigger replacement.
string
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
PublicKey
This property is required.
Changes to this property will trigger replacement.
string
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
Username
This property is required.
Changes to this property will trigger replacement.
string
The name of the IAM user to associate the SSH public key with.
Status string
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
Encoding
This property is required.
Changes to this property will trigger replacement.
string
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
PublicKey
This property is required.
Changes to this property will trigger replacement.
string
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
Username
This property is required.
Changes to this property will trigger replacement.
string
The name of the IAM user to associate the SSH public key with.
Status string
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
encoding
This property is required.
Changes to this property will trigger replacement.
String
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
publicKey
This property is required.
Changes to this property will trigger replacement.
String
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
username
This property is required.
Changes to this property will trigger replacement.
String
The name of the IAM user to associate the SSH public key with.
status String
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
encoding
This property is required.
Changes to this property will trigger replacement.
string
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
publicKey
This property is required.
Changes to this property will trigger replacement.
string
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
username
This property is required.
Changes to this property will trigger replacement.
string
The name of the IAM user to associate the SSH public key with.
status string
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
encoding
This property is required.
Changes to this property will trigger replacement.
str
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
public_key
This property is required.
Changes to this property will trigger replacement.
str
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
username
This property is required.
Changes to this property will trigger replacement.
str
The name of the IAM user to associate the SSH public key with.
status str
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
encoding
This property is required.
Changes to this property will trigger replacement.
String
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
publicKey
This property is required.
Changes to this property will trigger replacement.
String
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
username
This property is required.
Changes to this property will trigger replacement.
String
The name of the IAM user to associate the SSH public key with.
status String
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.

Outputs

All input properties are implicitly available as output properties. Additionally, the SshKey resource produces the following output properties:

Fingerprint string
The MD5 message digest of the SSH public key.
Id string
The provider-assigned unique ID for this managed resource.
SshPublicKeyId string
The unique identifier for the SSH public key.
Fingerprint string
The MD5 message digest of the SSH public key.
Id string
The provider-assigned unique ID for this managed resource.
SshPublicKeyId string
The unique identifier for the SSH public key.
fingerprint String
The MD5 message digest of the SSH public key.
id String
The provider-assigned unique ID for this managed resource.
sshPublicKeyId String
The unique identifier for the SSH public key.
fingerprint string
The MD5 message digest of the SSH public key.
id string
The provider-assigned unique ID for this managed resource.
sshPublicKeyId string
The unique identifier for the SSH public key.
fingerprint str
The MD5 message digest of the SSH public key.
id str
The provider-assigned unique ID for this managed resource.
ssh_public_key_id str
The unique identifier for the SSH public key.
fingerprint String
The MD5 message digest of the SSH public key.
id String
The provider-assigned unique ID for this managed resource.
sshPublicKeyId String
The unique identifier for the SSH public key.

Look up Existing SshKey Resource

Get an existing SshKey resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: SshKeyState, opts?: CustomResourceOptions): SshKey
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        encoding: Optional[str] = None,
        fingerprint: Optional[str] = None,
        public_key: Optional[str] = None,
        ssh_public_key_id: Optional[str] = None,
        status: Optional[str] = None,
        username: Optional[str] = None) -> SshKey
func GetSshKey(ctx *Context, name string, id IDInput, state *SshKeyState, opts ...ResourceOption) (*SshKey, error)
public static SshKey Get(string name, Input<string> id, SshKeyState? state, CustomResourceOptions? opts = null)
public static SshKey get(String name, Output<String> id, SshKeyState state, CustomResourceOptions options)
resources:  _:    type: aws:iam:SshKey    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Encoding Changes to this property will trigger replacement. string
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
Fingerprint string
The MD5 message digest of the SSH public key.
PublicKey Changes to this property will trigger replacement. string
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
SshPublicKeyId string
The unique identifier for the SSH public key.
Status string
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
Username Changes to this property will trigger replacement. string
The name of the IAM user to associate the SSH public key with.
Encoding Changes to this property will trigger replacement. string
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
Fingerprint string
The MD5 message digest of the SSH public key.
PublicKey Changes to this property will trigger replacement. string
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
SshPublicKeyId string
The unique identifier for the SSH public key.
Status string
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
Username Changes to this property will trigger replacement. string
The name of the IAM user to associate the SSH public key with.
encoding Changes to this property will trigger replacement. String
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
fingerprint String
The MD5 message digest of the SSH public key.
publicKey Changes to this property will trigger replacement. String
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
sshPublicKeyId String
The unique identifier for the SSH public key.
status String
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
username Changes to this property will trigger replacement. String
The name of the IAM user to associate the SSH public key with.
encoding Changes to this property will trigger replacement. string
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
fingerprint string
The MD5 message digest of the SSH public key.
publicKey Changes to this property will trigger replacement. string
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
sshPublicKeyId string
The unique identifier for the SSH public key.
status string
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
username Changes to this property will trigger replacement. string
The name of the IAM user to associate the SSH public key with.
encoding Changes to this property will trigger replacement. str
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
fingerprint str
The MD5 message digest of the SSH public key.
public_key Changes to this property will trigger replacement. str
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
ssh_public_key_id str
The unique identifier for the SSH public key.
status str
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
username Changes to this property will trigger replacement. str
The name of the IAM user to associate the SSH public key with.
encoding Changes to this property will trigger replacement. String
Specifies the public key encoding format to use in the response. To retrieve the public key in ssh-rsa format, use SSH. To retrieve the public key in PEM format, use PEM.
fingerprint String
The MD5 message digest of the SSH public key.
publicKey Changes to this property will trigger replacement. String
The SSH public key. The public key must be encoded in ssh-rsa format or PEM format.
sshPublicKeyId String
The unique identifier for the SSH public key.
status String
The status to assign to the SSH public key. Active means the key can be used for authentication with an AWS CodeCommit repository. Inactive means the key cannot be used. Default is active.
username Changes to this property will trigger replacement. String
The name of the IAM user to associate the SSH public key with.

Import

Using pulumi import, import SSH public keys using the username, ssh_public_key_id, and encoding. For example:

$ pulumi import aws:iam/sshKey:SshKey user user:APKAJNCNNJICVN7CFKCA:SSH
Copy

To learn more about importing existing cloud resources, see Importing resources.

Package Details

Repository
AWS Classic pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.