EC2 instance connect is showing (AccessDeniedException) error

1.2k Views Asked by At

While I am connecting to an Amazon-linux-2 instance in which the AWS instance connect was installed by default I am getting the error like this

An error occurred (AccessDeniedException) when calling the SendSSHPublicKey operation: User: arn:aws:iam::7***********:user/EIC-user is not authorized to perform: ec2-instance-connect:SendSSHPublicKey on resource: arn:aws:ec2:eu-west-1:7***********:instance/i-065544409504*****

My Attached IAM Policy for user EIC-user is

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "ec2-instance-connect:SendSSHPublicKey",
            "Resource": [
                "arn:aws:ec2:eu-west-1:7312********:instance/i-06554440950******"
            ],
            "Condition": {
                "StringEquals": {
                    "ec2:osuser": "dev"
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": "ec2:DescribeInstances",
            "Resource": "*"
        }
    ]
}

In My Ec2 Instance i added a user with named dev by using this command : useradd dev

If i changed the "ec2:osuser": "dev" to "ec2:osuser": "ec2-user" then it is connecting to ec2-user but i want to connect to user dev

I wanted to connect to another user in the OS, Is it possible to login with non-default users other than default users in AWS Instance Connect ????

Everything is going perfect if i used default user.... the error is happening only when i changed the OSuser I wanted to connect to the user dev Please help me to find out.....

0

There are 0 best solutions below