Server refused our key, set authorized_keys perrmissions to 777

我只是一个虾纸丫 提交于 2019-12-25 09:46:20

问题


I was copying some files from my home directory on my ec2 instance, and in a fit of laziness, I ran the command sudo chmod 777 /home/ec2-user/*. I guess this made my .ssh folder and possibly the authorized_keys have 777 privileges as well. Well it turns out that if authorized_keys is set to 777, you cannot SSH into the box with those keys (since another user could have updated it).

My question is, how can I fix this and log into my box again? This is an ec2 instance, so I have to ssh in.


回答1:


To Change permissions you'll need to access the files that are inside the Instance.

Since you can't ssh in the Instance you'll need to do the following things:

  1. Schedule a downtime for your application, because you'll need to stop the instance.
  2. Back-up everything inside the Instance Store(ephemeral volumes).
  3. Stop the instance.
  4. Detach the Volume from the EC2 instance in question.
  5. Attach the Volume to another working EC2 instance.
  6. Make the chmod changes to your .ssh directory and it's files.
  7. Detach the volume.
  8. Attach to the EC2 instance in question.
  9. Start the EC2 Instance.
  10. Try Connecting to the EC2 instance.

Please note that if you don't have Elastic IP configured for the Instance, the IP address will change.

For more information about attaching volume to EC2 instance refer to this AWS Documentation.




回答2:


To keep the downtime minimum, take the image of instance (in no-reboot mode) and create a new machine with this image and the key that you had previously specified. AWS, while creating the new box, puts the keys with proper permissions.

Note that private and public IPs will change, use elastic IP if you don't want IP change then use elastic IP.



来源:https://stackoverflow.com/questions/38236985/server-refused-our-key-set-authorized-keys-perrmissions-to-777

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!