Amazon Ubuntu Instance Suffers `Permission Denied(publickey).`

N.B. There are dozens of reasons to lead to this problem, for example, wrong permission of your pem file, incorrect username(e.g., ec2-user, ubuntu),wrong spelling in your command, etc..

The reason which causes my problem, if I am right, is that I run command `sudo chmod -R ./` under the wrong directory, namely, my home folder.

The solution is just setting your home folder permissions back.

  1. Stop your problematic instance.
  2. Create a new instance and stop the new problem-free instance.
  3. The newly created instance should be in the same `Availability Zone` like ‘us-west-2c’ which can be set on the ‘Network’ step under which the menu is ‘Subnet’.
  4. Detach your ‘ebs volume’ from the problematic instances and attach it on your new problem-free instance.
  5. Your need input your instance id as well as the mount point which looks like ‘/dev/sda2’.
  6. Start your new instance and mount the second drive that you just attached.
  7. [ubuntu ~]$ lsblk
    xvdf  202:80   0  100G  0 disk
    xvda1 202:1    0    8G  0 disk /
    [ubuntu ~]$ sudo mount /dev/xvdf/ /mnt
  8. Change directory to your mounted point and restore the permission of your home directory with permission 755.
    [ubuntu ~]$ cd /mnt/home/
    [ubuntu ~]$ chmod 755 yourusername
  9. Stop your new instance and detach the volume owned by the problematic instance.
  10. Reattach the just detached volume to the default problematic instance.

Leave a Reply