Add Keypair to existing EC2 instance

前端 未结 10 823
夕颜
夕颜 2020-11-28 17:32

I was given AWS Console access to an account with 2 instances running that I cannot shut down (in production). I would however like to gain SSH access to these instances, is

相关标签:
10条回答
  • 2020-11-28 17:54

    Once an instance has been started, there is no way to change the keypair associated with the instance at a meta data level, but you can change what ssh key you use to connect to the instance.

    stackoverflow.com/questions/7881469/change-key-pair-for-ec2-instance

    0 讨论(0)
  • 2020-11-28 17:56

    In my case I used this documentation to associate a key pair with my instance of Elastic Beanstalk

    Important

    You must create an Amazon EC2 key pair and configure your Elastic Beanstalk–provisioned Amazon EC2 instances to use the Amazon EC2 key pair before you can access your Elastic Beanstalk–provisioned Amazon EC2 instances. You can set up your Amazon EC2 key pairs using the AWS Management Console. For instructions on creating a key pair for Amazon EC2, see the Amazon Elastic Compute Cloud Getting Started Guide.

    Configuring Amazon EC2 Server Instances with Elastic Beanstalk

    0 讨论(0)
  • 2020-11-28 17:57

    On your local machine, run command:

    ssh-keygen -t rsa -C "SomeAlias"
    

    After that command runs, a file ending in *.pub will be generated. Copy the contents of that file.

    On the Amazon machine, edit ~/.ssh/authorized_keys and paste the contents of the *.pub file (and remove any existing contents first).

    You can then SSH using the other file that was generated from the ssh-keygen command (the private key).

    0 讨论(0)
  • 2020-11-28 17:59

    You can just add a new key to the instance by the following command:

    ssh-copy-id -i ~/.ssh/id_rsa.pub domain_alias
    

    You can configure domain_alias in ~/.ssh config

    host domain_alias
      User ubuntu
      Hostname domain.com
      IdentityFile ~/.ssh/ec2.pem
    
    0 讨论(0)
提交回复
热议问题