title: How to access EC2 Instance even if PEM file is lost
body: <p>I lost the PEM key to the EC2 Instance.
  I followed all the following steps:</p>
  
  <p><strong>HOW TO ACCESS EC2 INSTANCE EVEN IF PEM FILE IS LOST</strong></p>
  
  <p>Accessing the EC2 instance even if you loose the pem file is rather easy. </p>
  
  <ol>
  <li><p>First, create a new instance by creating new access file, call it 'helper' instance with same region and VPC as of the lost pem file instance.</p></li>
  <li><p>Now stop the lost pem file instance. Remember not to terminate instance but to stop it.</p></li>
  <li><p>Go to EBS volumes, select the root volume of the lost pem file instance and detach.</p></li>
  <li><p>Now again select the detached volume and this time you have to attach this volume to helper instance which we created before. Since helper instance already has a root volume by default as /dev/sda1, the newly attached volume will be secondary(eg: /dev/sdf).</p></li>
  <li><p>Login to your helper instance with its pem file.</p></li>
  <li><p>Execute below commands:</p>
  
  <pre><code># mount /dev/xvdf1 /mnt
  # cp /root/.ssh/authorized_keys /mnt/root/.ssh/
  # umount /mnt
  </code></pre></li>
  <li><p>Detach the secondary volume from helper instance. </p></li>
  <li><p>Again attach the volume back to our recovery instance. Start the instance. Terminate the helper instance.</p></li>
  </ol>
  
  <p>Use helper instance pem file to log into recovery instance.</p>