Accidentally changed the permissons of .ssh and now cannot access ec2 instance

34 Views Asked by At

I accidentally changed the permissions of .ssh directory and everything inside of it to 777 in my ec2 instance as ec2-user (root) and logged out of the instance. Now I cannot ssh into my instance since the permissions are too open. Is there anything I can do without creating a new instance? I have access to other users in the same instance.

2

There are 2 best solutions below

0
Jeremy Thompson On

If you've got another user with SSH access to the instance you can log in using that user account.

Note if the permissions issue only affects the ec2-user account, you can log in with the other user and should be able to fix the permissions.

Also note you can use the EC2 Serial Console to troubleshoot issues with your instance, even if you can't SSH into it.

0
Ananth Tirumanur On
  • Did you try to use AWS Systems Manager (SSM) to access the instance and fix the permissions

  • Try detaching the root EBS volume from this instance and attaching it to another instance as a secondary volume. You could then correct the permissions directly from the other instance.

  • if you have another user with sudo privileges, login with that user - let's say ec2-user and do the below steps these should help

     sudo su
    
     chmod 700 /home/ec2-user/.ssh #     Fix permissions
    
     chmod 600 /home/ec2-user/.ssh/*
     chmod 644 /home/ec2-user/.ssh/*.pub