{"id":751,"date":"2018-02-07T14:39:59","date_gmt":"2018-02-07T19:39:59","guid":{"rendered":"http:\/\/sunapi386.ca\/wordpress\/?p=751"},"modified":"2018-02-07T14:56:14","modified_gmt":"2018-02-07T19:56:14","slug":"recover-locked-aws-ec2-ssh-machine","status":"publish","type":"post","link":"https:\/\/sunapi386.ca\/wordpress\/recover-locked-aws-ec2-ssh-machine\/","title":{"rendered":"How to recover locked out AWS EC2 ssh machine"},"content":{"rendered":"<p>One time I accidentally messed with the `\/etc\/passwd` and locked myself out of being able to SSH into the machine. Since this is a remote machine in AWS I had no way of doing what I&#8217;d normally do. Which is attaching a keyboard and monitor and fixing this manually.<\/p>\n<p>To fix, use the AWS EC2 Management page to:<br \/>\n&#8211; spin up a new instance of vanilla ubuntu EC2 (let&#8217;s call it David)<br \/>\n&#8211; shutdown the locked machine (let&#8217;s call it Goliath)<br \/>\n&#8211; unmount Goliath&#8217;s volume<br \/>\n&#8211; attach the volume to David<\/p>\n<p>Then follow this guide: https:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/ebs-using-volumes.html<\/p>\n<p>Summary of what I did from this guide:<br \/>\n&#8220;`<br \/>\nlsblk<br \/>\nsudo file -s \/dev\/xvdf # MBR (not data type)<br \/>\nsudo file -s \/dev\/xvdf1 # ext4<br \/>\nsudo mkdir mount_folder<br \/>\nsudo mount \/dev\/xvdf1 mount_folder # ext4 mounted<br \/>\ncd mount_folder<br \/>\n# undo crazy setting (see Note #1)<br \/>\ncd .. # to unmount<br \/>\nsudo umount \/dev\/xvdf1<br \/>\n# Note #2<br \/>\n&#8220;`<\/p>\n<p>Note #1: For me I tried to modify `\/etc\/ssh\/sshd_config` to allow one more user to login. But this made me unable to login after. So I removed the offending line.<\/p>\n<p>Note #2: now in the Volume webpage<br \/>\n&#8211; undo attach to David (Volumes tab)<br \/>\n&#8211; mount to Goliath (Volumes tab: attach as EBS path \/dev\/sda1<strong>)<\/strong><br \/>\n&#8211; boot up Goliath (Instance tab)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One time I accidentally messed with the `\/etc\/passwd` and locked myself out of being able to SSH into the machine. Since this is a remote machine in AWS I had no way of doing what I&#8217;d normally do. Which is attaching a keyboard and monitor and fixing this manually. To fix, use the AWS EC2 &hellip; <a href=\"https:\/\/sunapi386.ca\/wordpress\/recover-locked-aws-ec2-ssh-machine\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to recover locked out AWS EC2 ssh machine<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-751","post","type-post","status-publish","format-standard","hentry","category-thoughts"],"_links":{"self":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts\/751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/comments?post=751"}],"version-history":[{"count":4,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts\/751\/revisions"}],"predecessor-version":[{"id":756,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/posts\/751\/revisions\/756"}],"wp:attachment":[{"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/media?parent=751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/categories?post=751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sunapi386.ca\/wordpress\/wp-json\/wp\/v2\/tags?post=751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}