amazon web services - How to secure an AWS EC2 instance when the SSH key is compromised or lost -


i'm aws noob.

i had developer set ec2 instance load balancer host node.js-based api. has moved on company still have private key log in, if wanted to. want change keys.

from have read, need relaunch instance new key pair. however, if lose node packages, , other sw has been installed on current instance? happen load balancer? need need update dns info point new ip?

(once situated, time around create multiple key pairs devs use.)

thanks, steve

edit: yes, have private key , can need to. want make sure no longer has access.

  1. take ami of current instance backup purposes. reboot instance keep existing ip. not need remove elb. may need ami if you cannot connect in after changing key.
  2. login root user, existing key.
  3. from shell, run following commands:
  4. $ ssh-keygen -t rsa -b 2048 -f user - generates new key pair
  5. $ sudo su - - if needed
  6. $ cp /home/ubuntu/.ssh/authorized_keys /home/ubuntu/.ssh/authorized_keys.bak - backup existing public key
  7. $ mv user.pub /home/ubuntu/.ssh/authorized_keys - replaces existing public key in authorized_keys file
  8. $ chmod 600 /home/ubuntu/.ssh/authorized_keys - change permissions on file
  9. copy private key (file called user) generated $ ssh-keygen command local machine , delete instance.
  10. connect instance new private key confirm. important: keep existing ssh session open , create new session new key.

if have problems on step 10 still have access existing session troubleshoot.

as cleanup make sure , remove old key pair aws console, , invalidate credentials if(!) not required existing services run. if granted developer root access aws console, should reset credentials.

note: these steps assume ubuntu installation. if using other linux type, replace \ubuntu correct aws username:

amazon linux: ec2-user   ubuntu  ubuntu debian  admin rhel 6.4 ec2-user    rhel 6.3 root 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -