Professional Documents
Culture Documents
We can see below we have two Linux servers, one server which we lost the key file and one server with a new key file
Our goal is to replace the “latest” key file with “newkeypair”.Now let’s see how we can change the key file of the server
that key file no longer exists.
Once server is stopped, identify its root volume and detach from the server
Select the Server and click on the root device, and click on the volume ID.
From the Actions, click on Detach Volume (Make sure we are detaching the correct volume)
Now let’s attach this volume to another server which has a new key file.
From the actions, choose Attach and choose new server which is running.
Once we selected new serer, on the Device section keep the defaults (/dev/sdf), This device is supposed to be attached
to the server as a secondary mount point.
Click on Attach
Now we have attached the root volume of stopped server to the new server that has new key file setup.
Let login to the new server as ec2-user and see what key file it is using (by default the key file being used are located
in /home/user/.ssh)
In this example the user is ec2-user, so the path is /home/ec2-user/.ssh (.ssh is a hidden directory)
lsblk
we can see its xvdf1 (it’s the volume we detached from old server and attached to this server)
mkdir oldvolume
once volume is created, issue below command to mount the old volume
Once its mounted let’s check what key file it has in oldvolume/home/ec2-user/.ssh/
cp /home/ec2-user/.ssh/authorized_keys /home/ec2-user/oldvolume/home/ec2-user/.ssh/
It will ask whether to replace the file, type y and hit enter
Now, let’s check if we have the new key file on the old volume
cd /home/ec2-user/oldvolume/home/ec2-user/.ssh/
ls
cat authorized_keys
umount /dev/xvdf1
Let’s detach this old volume and attach it back to old server.
Once the volume state is available, attach it back to old server which is in stopped state
Leave the Device section type “/dev/xvda”, it should be mounted as root device.
Click on Attach
Once the volume state is in-user, let’s start the old server
Once 2/2 status checks passed, login to the server with new key file “newkeyfile”