Unable to login to ec2 instance after running “sudo chmod 2770 /”












1















I am new to linux and AWS.



I ran sudo chmod 2770 / command on my ec2 instance and after that




I was getting Permission denied on everything I was doing(even using
ls or cd)




So I exited my connection(using cygwin) and tried to re-connect but now I get




Permission denied (publickey,gssapi-keyex,gssapi-with-mic)




I tried setting chmod 400 my.pem , chmod 600 my.pem, chmod 777 my.pem but nothing worked.

I am trying to connect using ssh -i my.pem ec2-user@xx.xx.xx.x which was working fine earlier.

What is the solution?










share|improve this question







New contributor




iAmLearning is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • I have installed so many things on my instance. I don't want to loose it. Is there any way to get it back ?

    – iAmLearning
    43 mins ago






  • 1





    You should be using EBS snapshots to ensure you can recover your instance to a point in time that it's working. The advice from MLu below is what I'd have said too. Don't experiment on servers that have important data. I did something similar on my EC2 instance when I was learning, I had to restore to a snapshot because it was far too difficult to fix.

    – Tim
    10 mins ago
















1















I am new to linux and AWS.



I ran sudo chmod 2770 / command on my ec2 instance and after that




I was getting Permission denied on everything I was doing(even using
ls or cd)




So I exited my connection(using cygwin) and tried to re-connect but now I get




Permission denied (publickey,gssapi-keyex,gssapi-with-mic)




I tried setting chmod 400 my.pem , chmod 600 my.pem, chmod 777 my.pem but nothing worked.

I am trying to connect using ssh -i my.pem ec2-user@xx.xx.xx.x which was working fine earlier.

What is the solution?










share|improve this question







New contributor




iAmLearning is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • I have installed so many things on my instance. I don't want to loose it. Is there any way to get it back ?

    – iAmLearning
    43 mins ago






  • 1





    You should be using EBS snapshots to ensure you can recover your instance to a point in time that it's working. The advice from MLu below is what I'd have said too. Don't experiment on servers that have important data. I did something similar on my EC2 instance when I was learning, I had to restore to a snapshot because it was far too difficult to fix.

    – Tim
    10 mins ago














1












1








1








I am new to linux and AWS.



I ran sudo chmod 2770 / command on my ec2 instance and after that




I was getting Permission denied on everything I was doing(even using
ls or cd)




So I exited my connection(using cygwin) and tried to re-connect but now I get




Permission denied (publickey,gssapi-keyex,gssapi-with-mic)




I tried setting chmod 400 my.pem , chmod 600 my.pem, chmod 777 my.pem but nothing worked.

I am trying to connect using ssh -i my.pem ec2-user@xx.xx.xx.x which was working fine earlier.

What is the solution?










share|improve this question







New contributor




iAmLearning is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I am new to linux and AWS.



I ran sudo chmod 2770 / command on my ec2 instance and after that




I was getting Permission denied on everything I was doing(even using
ls or cd)




So I exited my connection(using cygwin) and tried to re-connect but now I get




Permission denied (publickey,gssapi-keyex,gssapi-with-mic)




I tried setting chmod 400 my.pem , chmod 600 my.pem, chmod 777 my.pem but nothing worked.

I am trying to connect using ssh -i my.pem ec2-user@xx.xx.xx.x which was working fine earlier.

What is the solution?







linux amazon-web-services amazon-ec2






share|improve this question







New contributor




iAmLearning is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




iAmLearning is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




iAmLearning is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 53 mins ago









iAmLearningiAmLearning

1062




1062




New contributor




iAmLearning is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





iAmLearning is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






iAmLearning is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • I have installed so many things on my instance. I don't want to loose it. Is there any way to get it back ?

    – iAmLearning
    43 mins ago






  • 1





    You should be using EBS snapshots to ensure you can recover your instance to a point in time that it's working. The advice from MLu below is what I'd have said too. Don't experiment on servers that have important data. I did something similar on my EC2 instance when I was learning, I had to restore to a snapshot because it was far too difficult to fix.

    – Tim
    10 mins ago



















  • I have installed so many things on my instance. I don't want to loose it. Is there any way to get it back ?

    – iAmLearning
    43 mins ago






  • 1





    You should be using EBS snapshots to ensure you can recover your instance to a point in time that it's working. The advice from MLu below is what I'd have said too. Don't experiment on servers that have important data. I did something similar on my EC2 instance when I was learning, I had to restore to a snapshot because it was far too difficult to fix.

    – Tim
    10 mins ago

















I have installed so many things on my instance. I don't want to loose it. Is there any way to get it back ?

– iAmLearning
43 mins ago





I have installed so many things on my instance. I don't want to loose it. Is there any way to get it back ?

– iAmLearning
43 mins ago




1




1





You should be using EBS snapshots to ensure you can recover your instance to a point in time that it's working. The advice from MLu below is what I'd have said too. Don't experiment on servers that have important data. I did something similar on my EC2 instance when I was learning, I had to restore to a snapshot because it was far too difficult to fix.

– Tim
10 mins ago





You should be using EBS snapshots to ensure you can recover your instance to a point in time that it's working. The advice from MLu below is what I'd have said too. Don't experiment on servers that have important data. I did something similar on my EC2 instance when I was learning, I had to restore to a snapshot because it was far too difficult to fix.

– Tim
10 mins ago










1 Answer
1






active

oldest

votes


















2














Solution is to start a new instance and never do what you did again. It would be too complicated to try to properly recover all the permissions that you reset to 2770.



If you have any valuable files on the broken instance you can stop it, mount its root volume to the new instance and copy the files from there.





Update: as @GeraldSchneider points out you may be lucky if you didn't recursively change all the permissions everywhere. You'll have to start a new instance and use it to fix the root permissions back to 0755. Follow for example the instructions here: Changed AWS EC2 firewall rule and locked out of ssh (instead of Fix the firewall do sudo chmod 755 /mnt or wherever you mount the other disk).



Hope that helps :)






share|improve this answer


























  • My first thought was to rebuild the instance as well, but then I realized that the OP only changed the permission on / itself, not the directories and files below. It should be pretty easy to fix this, but I'm not familiar with EC2 and don't know how to mount the volume on a different instance.

    – Gerald Schneider
    30 mins ago











  • Is rebuilding possible ? I am just learning ec2 so I don't care about permissions/security. I just need it working again if possible.

    – iAmLearning
    13 mins ago











  • @GeraldSchneider good point, updated the answer.

    – MLu
    12 mins ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "2"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






iAmLearning is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f954623%2funable-to-login-to-ec2-instance-after-running-sudo-chmod-2770%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Solution is to start a new instance and never do what you did again. It would be too complicated to try to properly recover all the permissions that you reset to 2770.



If you have any valuable files on the broken instance you can stop it, mount its root volume to the new instance and copy the files from there.





Update: as @GeraldSchneider points out you may be lucky if you didn't recursively change all the permissions everywhere. You'll have to start a new instance and use it to fix the root permissions back to 0755. Follow for example the instructions here: Changed AWS EC2 firewall rule and locked out of ssh (instead of Fix the firewall do sudo chmod 755 /mnt or wherever you mount the other disk).



Hope that helps :)






share|improve this answer


























  • My first thought was to rebuild the instance as well, but then I realized that the OP only changed the permission on / itself, not the directories and files below. It should be pretty easy to fix this, but I'm not familiar with EC2 and don't know how to mount the volume on a different instance.

    – Gerald Schneider
    30 mins ago











  • Is rebuilding possible ? I am just learning ec2 so I don't care about permissions/security. I just need it working again if possible.

    – iAmLearning
    13 mins ago











  • @GeraldSchneider good point, updated the answer.

    – MLu
    12 mins ago
















2














Solution is to start a new instance and never do what you did again. It would be too complicated to try to properly recover all the permissions that you reset to 2770.



If you have any valuable files on the broken instance you can stop it, mount its root volume to the new instance and copy the files from there.





Update: as @GeraldSchneider points out you may be lucky if you didn't recursively change all the permissions everywhere. You'll have to start a new instance and use it to fix the root permissions back to 0755. Follow for example the instructions here: Changed AWS EC2 firewall rule and locked out of ssh (instead of Fix the firewall do sudo chmod 755 /mnt or wherever you mount the other disk).



Hope that helps :)






share|improve this answer


























  • My first thought was to rebuild the instance as well, but then I realized that the OP only changed the permission on / itself, not the directories and files below. It should be pretty easy to fix this, but I'm not familiar with EC2 and don't know how to mount the volume on a different instance.

    – Gerald Schneider
    30 mins ago











  • Is rebuilding possible ? I am just learning ec2 so I don't care about permissions/security. I just need it working again if possible.

    – iAmLearning
    13 mins ago











  • @GeraldSchneider good point, updated the answer.

    – MLu
    12 mins ago














2












2








2







Solution is to start a new instance and never do what you did again. It would be too complicated to try to properly recover all the permissions that you reset to 2770.



If you have any valuable files on the broken instance you can stop it, mount its root volume to the new instance and copy the files from there.





Update: as @GeraldSchneider points out you may be lucky if you didn't recursively change all the permissions everywhere. You'll have to start a new instance and use it to fix the root permissions back to 0755. Follow for example the instructions here: Changed AWS EC2 firewall rule and locked out of ssh (instead of Fix the firewall do sudo chmod 755 /mnt or wherever you mount the other disk).



Hope that helps :)






share|improve this answer















Solution is to start a new instance and never do what you did again. It would be too complicated to try to properly recover all the permissions that you reset to 2770.



If you have any valuable files on the broken instance you can stop it, mount its root volume to the new instance and copy the files from there.





Update: as @GeraldSchneider points out you may be lucky if you didn't recursively change all the permissions everywhere. You'll have to start a new instance and use it to fix the root permissions back to 0755. Follow for example the instructions here: Changed AWS EC2 firewall rule and locked out of ssh (instead of Fix the firewall do sudo chmod 755 /mnt or wherever you mount the other disk).



Hope that helps :)







share|improve this answer














share|improve this answer



share|improve this answer








edited 13 mins ago

























answered 36 mins ago









MLuMLu

8,21712141




8,21712141













  • My first thought was to rebuild the instance as well, but then I realized that the OP only changed the permission on / itself, not the directories and files below. It should be pretty easy to fix this, but I'm not familiar with EC2 and don't know how to mount the volume on a different instance.

    – Gerald Schneider
    30 mins ago











  • Is rebuilding possible ? I am just learning ec2 so I don't care about permissions/security. I just need it working again if possible.

    – iAmLearning
    13 mins ago











  • @GeraldSchneider good point, updated the answer.

    – MLu
    12 mins ago



















  • My first thought was to rebuild the instance as well, but then I realized that the OP only changed the permission on / itself, not the directories and files below. It should be pretty easy to fix this, but I'm not familiar with EC2 and don't know how to mount the volume on a different instance.

    – Gerald Schneider
    30 mins ago











  • Is rebuilding possible ? I am just learning ec2 so I don't care about permissions/security. I just need it working again if possible.

    – iAmLearning
    13 mins ago











  • @GeraldSchneider good point, updated the answer.

    – MLu
    12 mins ago

















My first thought was to rebuild the instance as well, but then I realized that the OP only changed the permission on / itself, not the directories and files below. It should be pretty easy to fix this, but I'm not familiar with EC2 and don't know how to mount the volume on a different instance.

– Gerald Schneider
30 mins ago





My first thought was to rebuild the instance as well, but then I realized that the OP only changed the permission on / itself, not the directories and files below. It should be pretty easy to fix this, but I'm not familiar with EC2 and don't know how to mount the volume on a different instance.

– Gerald Schneider
30 mins ago













Is rebuilding possible ? I am just learning ec2 so I don't care about permissions/security. I just need it working again if possible.

– iAmLearning
13 mins ago





Is rebuilding possible ? I am just learning ec2 so I don't care about permissions/security. I just need it working again if possible.

– iAmLearning
13 mins ago













@GeraldSchneider good point, updated the answer.

– MLu
12 mins ago





@GeraldSchneider good point, updated the answer.

– MLu
12 mins ago










iAmLearning is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















iAmLearning is a new contributor. Be nice, and check out our Code of Conduct.













iAmLearning is a new contributor. Be nice, and check out our Code of Conduct.












iAmLearning is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Server Fault!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f954623%2funable-to-login-to-ec2-instance-after-running-sudo-chmod-2770%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL Server 17 - Attemping to backup to remote NAS but Access is denied

Always On Availability groups resolving state after failover - Remote harden of transaction...

Restoring from pg_dump with foreign key constraints