1

Trying to connect using CentOS7

I deployed a couple of EC2 instances using terraform and now and trying to log in.

aws2 ec2-instance-connect send-ssh-public-key --instance-id i-0788274a4861154d44 --availability-zone us-east-2 --instance-os-user ec2-user --ssh-public-key file:/aws_ssh/my_rsa_key.pub

Parameter validation failed:
Invalid length for parameter SSHPublicKey, value: 42, valid range: 256-inf

I tried this command as well

ssh-keygen -t rsa -f my_rsa_key -b 1024

Still gives the same error.

I am new to this so as much help as you can give.

James Connigan
  • 137
  • 2
  • 13

3 Answers3

1

Connect using this command.. You tried to connect the instance using the first command...

aws ec2-instance-connect send-ssh-public-key --region us-east-1 --instance-id i-0989ec3292613a4f9 --availability-zone us-east-1 --instance-os-user ec2-user --ssh-public-key file://mynew_key.pub

After authentication, the public key is made available to the instance through the instance metadata for 60 seconds. During this time, connect to the instance using the associated private key

ssh -i mynew_key ec2-user@ec2-34-204-200-76.compute-1.amazonaws.com

If for some reason you don’t connect within that 60-second window, you see the following error:

ssh -i mynew_key ec2-user@ec2-34-204-200-76.compute-1.amazonaws.com Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

Manikandan Ram
  • 399
  • 2
  • 15
  • Still getting the same error: Parameter validation failed: Invalid length for parameter SSHPublicKey, value: 42, valid range: 256-inf – James Connigan Nov 26 '19 at 03:30
  • https://tech.smartling.com/getting-started-with-terraform-and-aws-ec2-first-steps-workshop-1-e38607f0fd4c Hope this will help – Manikandan Ram Nov 26 '19 at 04:04
0

send-ssh-public-key just support

  1. Amazon Linux 2 (any version)
  2. Ubuntu 16.04 or later

see this document: https://docs.amazonaws.cn/en_us/AWSEC2/latest/UserGuide/ec2-instance-connect-methods.html

Dinh
  • 1
-1

I am not sure why..? But the problem got fixed after making the following changes in the syntax..

file:/ by file:///

aws2 ec2-instance-connect send-ssh-public-key --instance-id i-0788274a4861154d44 --availability-zone us-east-2 --instance-os-user ec2-user --ssh-public-key file:/aws_ssh/my_rsa_key.pub

aws2 ec2-instance-connect send-ssh-public-key --instance-id i-0788274a4861154d44 --availability-zone us-east-2 --instance-os-user ec2-user --ssh-public-key file:///aws_ssh/my_rsa_key.pub

{
    "RequestId": "dd452b0f-89c3-4a01-82ea-c6a55934ec3f",
    "Success": true
}
Manikandan Ram
  • 399
  • 2
  • 15
James Connigan
  • 137
  • 2
  • 13