{"id":138,"date":"2018-06-14T16:41:27","date_gmt":"2018-06-14T16:41:27","guid":{"rendered":"http:\/\/blog.hegars.com\/?p=138"},"modified":"2018-06-14T16:54:54","modified_gmt":"2018-06-14T16:54:54","slug":"script-generate-ssh-keys","status":"publish","type":"post","link":"https:\/\/blog.hegars.com\/?p=138","title":{"rendered":"Generate SSH keys"},"content":{"rendered":"<h1><span style=\"font-weight: 400;\">GENERATE NEW KEY PAIR<\/span><\/h1>\n<p><span style=\"font-weight: 400;\">This creates two files, A Private key (id_rsa) and Public Key (id_rsa.pub), back both up and keep secure<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">$ ssh-keygen -t rsa -C &#8220;hegars@hegars.com&#8221;<\/span><\/p>\n<p>&nbsp;<\/p>\n<h1><span style=\"font-weight: 400;\">ENABLE ACCESS TO EXISTING SERVER<\/span><\/h1>\n<h2><span style=\"font-weight: 400;\">Create New User<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Create a user on the server<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\"># adduser hegars<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Add User to Group<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Add the newly created user to the required groups.<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\"># usermod -a -G www-data,sudo hegars<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Generate Temporary keys <\/span><\/h2>\n<p><span style=\"font-weight: 400;\">This generated the set of temporary keys that is needed to kick something over in the OS to get it working, just remove the self generated keys <\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\"># su &#8211; hegars<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">$ ssh-keygen<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Delete temp keys<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Just delete the generated keys.<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">cd ~\/.ssh\/<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">rm *<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Copy existing Public Key to User<\/span><\/h2>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">$ cd ~\/.ssh\/<\/span><\/p>\n<p><span style=\"font-weight: 400;\">scp something from somewhere<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">$ cp id_rsa.pub authorized_keys<\/span><\/p>\n<p><span style=\"font-weight: 400;\">or paste it <\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">$ vim authorized_keys<\/span><\/p>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">$ chmod 744 authorized_keys<\/span><\/p>\n<h1><span style=\"font-weight: 400;\">Generate Public Key from Private Key <\/span><\/h1>\n<p style=\"padding-left: 30px;\"><span style=\"font-weight: 400;\">ssh-keygen -y -f ~\/.ssh\/id_rsa &gt; ~\/.ssh\/id_rsa.pub<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>GENERATE NEW KEY PAIR This creates two files, A Private key (id_rsa) and Public Key (id_rsa.pub), back both up and keep secure $ ssh-keygen -t rsa -C &#8220;hegars@hegars.com&#8221; &nbsp; ENABLE ACCESS TO EXISTING SERVER Create New User Create a user on the server # adduser hegars Add User to Group Add the newly created user [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hegars.com\/index.php?rest_route=\/wp\/v2\/posts\/138"}],"collection":[{"href":"https:\/\/blog.hegars.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hegars.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hegars.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hegars.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138"}],"version-history":[{"count":3,"href":"https:\/\/blog.hegars.com\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions"}],"predecessor-version":[{"id":169,"href":"https:\/\/blog.hegars.com\/index.php?rest_route=\/wp\/v2\/posts\/138\/revisions\/169"}],"wp:attachment":[{"href":"https:\/\/blog.hegars.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hegars.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hegars.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}