{"id":1964,"date":"2023-11-02T18:50:24","date_gmt":"2023-11-02T13:20:24","guid":{"rendered":"https:\/\/www.veeble.org\/kb\/?p=1964"},"modified":"2025-03-17T10:28:16","modified_gmt":"2025-03-17T04:58:16","slug":"generating-using-pem-keys-linux-server","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/generating-using-pem-keys-linux-server\/","title":{"rendered":"How to Generate PEM Key and Connect to a Linux Machine?"},"content":{"rendered":"\n<p>A Private Enhanced Mail (PEM) key is a widely used file format for storing cryptographic keys and certificates. In the context of securing SSH access to a Linux server, a PEM key can be used to authenticate and establish a secure connection. This guide outlines the steps to generate a PEM key and use it to connect to a Linux server from both Linux and Windows operating systems. This approach was already chosen as the default security standard in cloud-offered VMs such as <a href=\"https:\/\/docs.aws.amazon.com\/AWSEC2\/latest\/UserGuide\/ec2-key-pairs.html\" target=\"_blank\" rel=\"noopener\">AWS cloud instances<\/a>. By using a PEM key rather than using old-fashioned passwords, you can get rid of security concerns such as <a href=\"https:\/\/www.geeksforgeeks.org\/what-is-a-dictionary-attack\/\" target=\"_blank\" rel=\"noopener\">dictionary attacks<\/a> for passwords.<\/p>\n\n\n\n<p><strong>Alright, let&#8217;s get started!!<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open your Linux terminal. Once open, you&#8217;re ready to generate your RSA key pair with the command:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">ssh-keygen -p -m PEM -f ~\/.ssh\/<\/pre>\n\n\n\n<p>When prompted, press <code>Enter<\/code> to save the key pair in the default location, or feel free to choose a different path. <\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>Remember, security is key, so make sure to set the appropriate permissions with:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">chmod 600 ~\/.ssh\/id_rsa<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li> Now, you will have 2 new files under the directory \/.ssh\/, <code>id_rsa<\/code> and <code>id_rsa.pub<\/code> where id_rsa is the private key file generated by the <code>ssh-keygen<\/code> command when you create an RSA key pair. It&#8217;s a binary file that should be kept highly secure and never shared with anyone and id_rsa.pub is the public key file that corresponds to the private key. It&#8217;s also generated by the <code>ssh-keygen<\/code> command at the same time as the private key. <\/li>\n<\/ol>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li>Copy the contents from the <code>id_rsa<\/code> file and paste them into a file with the <code>.pem<\/code> extension on your local machine. This file will be used for logging into the server next time.<\/li>\n<\/ol>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li>Copy the contents from the <code>id_rsa.pub<\/code> file and insert them into the file <code>authorized_keys<\/code> which is located under the directory location <code>~\/.ssh\/<\/code> with the command:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">cp ~\/.ssh\/id_rsa.pub &gt;&gt; ~\/.ssh\/authorized_keys<\/pre>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li>Additionally, remove password-based authentication for SSH by changing the value of <code>PasswordAuthentication yes<\/code> to <code>PasswordAuthentication no<\/code> in <code>\/etc\/ssh\/sshd_config<\/code> file.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo vi \/etc\/ssh\/sshd_config<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted has-ast-global-color-5-background-color has-background\">PasswordAuthentication&nbsp;no<\/pre>\n\n\n\n<ol start=\"7\" class=\"wp-block-list\">\n<li>Restart the SSH service with the command:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">service ssh restart<\/pre>\n\n\n\n<p>8. Finally, you can now able to log into the server using the pem file we generated now!<br>For Windows PC users, open PuTTY, input the server&#8217;s IP, navigate to &#8216;Auth&#8217; under &#8216;SSH&#8217;, and provide the path to your <code>.pem<\/code> file.<br>And for use the below command after replacing the filename:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ssh -i \/path\/to\/private_key.pem username@server_ip<\/pre>\n\n\n\n<p>Congratulations! You&#8217;ve now mastered the art of generating and using PEM keys for secure server access. Stay secure and happy computing!<\/p>\n\n\n\n<div style=\"height:45px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-b917d625 wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Powering Your Business with Windows VPS<\/h3><p class=\"uagb-cta__desc\">Choose a robust and reliable platform for your critical applications. Experience the difference a high-performance VPS can make.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/windows-vps\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">View Our Plans<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>A Private Enhanced Mail (PEM) key is a widely used file format for storing cryptographic keys and certificates. In the context of securing SSH [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":8123,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1964","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/11\/How-to-Generate-PEM-Key-and-Connect-to-a-Linux-Machine.jpg",1366,768,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/11\/How-to-Generate-PEM-Key-and-Connect-to-a-Linux-Machine-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/11\/How-to-Generate-PEM-Key-and-Connect-to-a-Linux-Machine-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/11\/How-to-Generate-PEM-Key-and-Connect-to-a-Linux-Machine-768x432.jpg",768,432,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/11\/How-to-Generate-PEM-Key-and-Connect-to-a-Linux-Machine-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/11\/How-to-Generate-PEM-Key-and-Connect-to-a-Linux-Machine.jpg",1366,768,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2023\/11\/How-to-Generate-PEM-Key-and-Connect-to-a-Linux-Machine.jpg",1366,768,false]},"uagb_author_info":{"display_name":"Adrian Antony","author_link":"https:\/\/www.veeble.com\/kb\/author\/adrian\/"},"uagb_comment_info":0,"uagb_excerpt":"A Private Enhanced Mail (PEM) key is a widely used file format for storing cryptographic keys and certificates. In the context of securing SSH [&hellip;]","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/1964","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=1964"}],"version-history":[{"count":5,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/1964\/revisions"}],"predecessor-version":[{"id":7507,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/1964\/revisions\/7507"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/8123"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=1964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=1964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=1964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}