Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################################################
- Getting access to misconfigured AmazonAws Instance...
- For my case it was the misconfigured Ubuntu /etc/ssh/sshd_config
- ######################################################################
- Video I used for help:
- Troubleshooting an RDP Connection with the EC2 Rescue Tool for Windows
- https://www.youtube.com/watch?v=WFsWQrm1qi0&ab_channel=EricintheCloud
- EC2Rescue for EC2 Windows is a troubleshooting tool that you can run on your Amazon EC2 Windows Server instances. You can use the tool to troubleshoot OS-level issues and collect advanced logs and configuration files for further analysis.
- PowerShell Command to Download the EC2 Rescue tool:
- https://s3.amazonaws.com/ec2rescue/windows/EC2Rescue_latest.zip?x-download-source=docs
- (Except I didn't use Windows Nor the Tool)
- ----------------------------------------------------------------------
- Website I used for help:
- How to access files of my First Ubuntu from my Second Ubuntu by adumbprogrammer:
- https://askubuntu.com/questions/1367142/how-to-access-files-of-my-first-ubuntu-from-my-second-ubuntu
- ######################################################################
- ######################################################################
- #0) First try accessing AmazonAWS Cloud Shell... If to no avail...
- #0.5) This requires 2 instances. Using parition access...
- So what we will do for sake of clarity call EC0 the misconfigured Server
- and we will call EC1 the newly setup server we will create later...
- #1) Go to failed AmazonAWS Server in AWS Control Panel EC2 Instance...
- #2) Click on Instance checkbox of Name:
- In details tab below:
- Copy to clipboard: instance-ID: i-###x###x##x#x##x# and paste somewhere for later
- and also: "Subnet-ID": subnet-0xx###x#xx###xx## and paste somewhere for later
- #3) Go to Instance State and "Stop Instance".
- #) Wait for it in "Instance State" to say "Stopped", then click on storage tab below.
- Click on hyperlinked blue Volume-ID of volume in "Block Devices" drop-down tab
- Volume-ID Device-Name Vol.size Attachment-status
- (vol-0xx##x##xx####x## /dev/sda1 8 Attached
- A new page will popup, with more details...
- Click on hyperlinked vol-0xx##x##xx####x## again.
- Click "Actions" drop-down-tab and select "Detach Volume"
- Wait till it says "Volume State" is "available" rather than "in use"
- For the sakes of being careful copy and paste the vol-0xx... ID for safe keeping
- as to not mix them up with the new-server vol-0xx ID.
- #4) Create a new (Ubuntu) "Launch an " Instance in EC2.
- Name it whatever you want, we'll call it EC1.
- Quick-Start tab > Ubuntu (Server 22.04 LTS (HVM), SSD, (FREE)(64-bit))
- (I already had an ssh putty.ppk key pair, so i used it, otherwise create one...
- and after creating the new server, download the ssh-key-pair, we'll need it for putty access later.
- In Network settings, click on Subnet, where it says "No Preference" tab,
- and click it, and paste the "Subnet-ID": subnet-0xx###x#xx###xx## from earlier from EC0.
- Once you have selected the Subnet-ID for the same subnet as your EC0 for EC1...
- Continue to scroll to bottom of page and select the button "Launch instance".
- #5) You should now have 2 instances. Make sure both Instance States are "Stopped".
- Once Stopped, copy instance-ID of EC1 for later...
- checkbox <check> the EC1 Name of instance.
- Click on "Storage" tab below by details.
- As before, click "Volume-ID" of any "vol-0xx##x##xx####x##"
- #6) Once in Volumes window, click the "x" to close selected volume to display all volumes.
- Now there should be 2 volume-ids:
- "vol-0xx##x##xx####x#0" //EC0
- "vol-0xx##x##xx####x#1" //EC1
- Since we detached EC0's "vol-0xx##x##xx####x#0" Volume-ID, we should be able to use it on EC1.
- To do this, click on EC0's "vol-0xx##x##xx####x##".
- Then click on "Actions" tab and "Attach Volume".
- In the new popup window, for Instance, paste EC1's Instance-ID.
- Leave Device name AS-IS. No need to change.
- Volume should now be connected to the EC2 instance...
- to verify this go to Server2 Instance Details, Storage, and it should be so.
- Now click on "Connect" Tab in EC2>Instances>instance-id>Connect to instance and choose SSH client.
- Open putty and connect with: ubuntu@ec2-#-###-###-###.us-east-2.compute.amazonaws.com with SSH-KEY putty.apk create/used earlier, when creating EC1 Instance.
- #7 Once Connected to EC1 instance, with volume of EC0 on EC1 attached from the same subnet, we can run these commands in ssh (putty) terminal...
- ---------------------------------------------
- In putty ssh of EC1:
- lsblk (THIS WILL SHOW ALL AVAILABLE DRIVES)
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
- loop0 7:0 0 24.9M 1 loop /snap/amazon-ssm-agent/7628
- loop1 7:1 0 55.7M 1 loop /snap/core18/2812
- loop2 7:2 0 63.5M 1 loop /snap/core20/2015
- loop3 7:3 0 111.9M 1 loop /snap/lxd/24322
- loop4 7:4 0 40.9M 1 loop /snap/snapd/20290
- xvda 202:0 0 8G 0 disk
- ├─xvda1 202:1 0 7.9G 0 part /
- ├─xvda14 202:14 0 4M 0 part
- └─xvda15 202:15 0 106M 0 part /boot/efi
- xvdf 202:80 0 8G 0 disk
- ├─xvdf1 202:81 0 7.9G 0 part
- ├─xvdf14 202:94 0 4M 0 part
- └─xvdf15 202:95 0 106M 0 part
- sudo mount /dev/xvdf1 /mnt (MOUNT THE DRIVE WE WANT TO FIX)
- sudo nano /mnt/etc/ssh/sshd_config (MODIFY FROM /MNT/ DIR THE FILES WE NEED TO FIX)
- <modify contents to fix ssh permission problem>
- <save>
- ---------------------------------------------
- shutdown the server instance till it says "Stopped"
- Detach Volume from EC1, using the same as before on EC0, but for EC1... (!!!) Make sure you detach the same volume as before! For EC0!.
- Reattach (THE CORRECT) volume to EC0 (!!!!)Make sure that you add the right VOLUME!
- ALSO!!! Make sure you choose Instance-ID of server1, and CHANGE "DEVICE NAME" TO: /dev/sda1 and NOT: xvdf !!!!
- Relaunch EC0 (previously misconfigured instance).
- Once Running, it should be accessible once again (via ssh in my case).
- Note** My ipaddress changed for my server after fixing ssh and had to
- recopy and paste from amazonAWS "Public IPv4 DNS":
- ubuntu@ec2-#-###-###-###.us-east-2.compute.amazonaws.com
- and in putty-tab, SSH/Auth/Credentials/Private Key File For Authentication: <putty.ppk>
- Back in Session "Save" session with "Saved Sessions" id of your choosing.
- Viola! Back to front, ready to go!
- ######################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement