{"id":15209,"date":"2014-08-19T15:32:31","date_gmt":"2014-08-19T10:02:31","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=15209"},"modified":"2016-11-29T17:44:23","modified_gmt":"2016-11-29T12:14:23","slug":"change-ssh-key-pair-of-running-ec2-instance","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/change-ssh-key-pair-of-running-ec2-instance\/","title":{"rendered":"Change ssh key-pair of Running EC2 Instance"},"content":{"rendered":"<p>Sometimes we get the requirement to change the key-pair for some security reasons. In this article, we will be changing the key pair of running EC2 instances.<\/p>\n<h3 style=\"text-align: justify;color: #ff9900\">Steps:<\/h3>\n<p>1. Create a new key pair from AWS Console.<br \/>\n2. Generate Public key from newly created key pair ( Private Key ).<br \/>\n3. Paste the generated public key ( from Step 2 ) in ~\/.ssh\/authorized_keys of Server.<br \/>\n4. Delete the existing key from ~\/.ssh\/authorized_keys of Server<br \/>\n5. Perform ssh using new key.<\/p>\n<p>I have a running EC2 Instance ( Ubuntu 14.04 ) having key-pair &#8220;testing-key&#8221;.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/08\/Screenshot-from-2014-08-19-131614.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15215\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/08\/Screenshot-from-2014-08-19-131614.png\" alt=\"Screenshot from 2014-08-19 13:16:14\" width=\"956\" height=\"56\" \/><\/a><\/p>\n<p>Let&#8217;s change the key<\/p>\n<h4 style=\"text-align: justify;color: #ff9900\">1. Create a new key pair from AWS Console<\/h4>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/08\/Screenshot-from-2014-08-19-140814.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15213\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/08\/Screenshot-from-2014-08-19-140814.png\" alt=\"Screenshot from 2014-08-19 14:08:14\" width=\"423\" height=\"154\" \/><\/a><\/p>\n<p>This is a private key that you have to download on your local machine.<\/p>\n<h4 style=\"text-align: justify;color: #ff9900\">2. Generate Public Key from Private Key (testing-ssh-key)<\/h4>\n<p>Execute<\/p>\n<p>[js]&quot;$ ssh-keygen -y&quot;[\/js]<\/p>\n<p>and provide the path for private key.<br \/>\nHere &#8220;testing-ssh-key.pem&#8221; is the new private key<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/08\/Screenshot-from-2014-08-19-145948.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15221\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/08\/Screenshot-from-2014-08-19-145948.png\" alt=\"Screenshot from 2014-08-19 14:59:48\" width=\"630\" height=\"93\" \/><\/a><\/p>\n<h4 style=\"text-align: justify;color: #ff9900\">3. Append the above generated public key to ~\/.ssh\/authorized_keys<\/h4>\n<h4 style=\"text-align: justify;color: #ff9900\">4. Remove the old key from ~\/.ssh\/authorized_keys ( &#8220;testing-key.pem&#8221; )<\/h4>\n<h4 style=\"text-align: justify;color: #ff9900\">5. Perform ssh using new key<\/h4>\n<p>[js]<br \/>\n$ ssh -i testing-ssh-key.pem ubuntu@X.X.X.X<br \/>\n[\/js]<\/p>\n<p>You can now log in using new key.<\/p>\n<p><a href=\"\/blog\/wp-ttn-blog\/uploads\/2014\/08\/Screenshot-from-2014-08-19-142903.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-15211\" src=\"\/blog\/wp-ttn-blog\/uploads\/2014\/08\/Screenshot-from-2014-08-19-142903.png\" alt=\"Screenshot from 2014-08-19 14:29:03\" width=\"530\" height=\"413\" \/><\/a><\/p>\n<p>Read more about our <a title=\"DevOps AWS\" href=\"http:\/\/www.tothenew.com\/devops-aws\">D<\/a><span><a title=\"DevOps AWS\" href=\"http:\/\/www.tothenew.com\/devops-aws\">evOps AWS<\/a> capabilities.<\/span><\/p>\n<p>Note: This article is not for changing key-pair if it is lost or deleted. Before performing below actions, it is advisable to take the backup of existing EC2 Instance.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes we get the requirement to change the key-pair for some security reasons. In this article, we will be changing the key pair of running EC2 instances. Steps: 1. Create a new key pair from AWS Console. 2. Generate Public key from newly created key pair ( Private Key ). 3. Paste the generated public [&hellip;]<\/p>\n","protected":false},"author":100,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":185},"categories":[1174,2348],"tags":[2366,1555,3233,1892,1556,1498,553],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15209"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/100"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=15209"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/15209\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=15209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=15209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=15209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}