{"id":288,"date":"2014-02-21T16:33:40","date_gmt":"2014-02-21T16:33:40","guid":{"rendered":"http:\/\/blogs.nd.edu\/devops\/?p=288"},"modified":"2014-02-21T19:25:53","modified_gmt":"2014-02-21T19:25:53","slug":"using-ssh-with-github-for-fun-and-profit","status":"publish","type":"post","link":"https:\/\/sites.nd.edu\/devops\/2014\/02\/21\/using-ssh-with-github-for-fun-and-profit\/","title":{"rendered":"Using SSH with GitHub for Fun and Profit"},"content":{"rendered":"<p>Please see my previous post about <a href=\"http:\/\/blogs.nd.edu\/devops\/2014\/02\/21\/github-organization-ndoit\/\">joining the NDOIT GitHub Organization<\/a>.<\/p>\n<p>You can easily clone a git repository using the https URL that appears in your browser when you visit it on GitHub. \u00a0However, you can also use an SSH key pair. \u00a0It takes a little setup, but you will want to do this for two reasons:<\/p>\n<ol>\n<li>It&#8217;s required to use git from the command line after enabling two-factor security<\/li>\n<li>It&#8217;s necessary for ssh agent forwarding, which lets you&#8230;\n<ol>\n<li>use the remote deployment scripts I am developing in capistrano<\/li>\n<li>use ssh with github on vagrant (or any other machine you ssh to) without redoing these steps<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>So here&#8217;s what you want to do:<\/p>\n<p><strong>STEP 1:\u00a0<a href=\"https:\/\/help.github.com\/articles\/generating-ssh-keys\">Follow the instructions on this blog<\/a><\/strong>\u00a0to generate an SSH key \u00a0pair and register its public key with your GitHub account. \u00a0Note the platform selection tabs at the top of that page, and please be aware that\u00a0<strong>these instructions work for Mac and Linux<\/strong>, but GitHub encourages Windows users to use the Windows native GUI app.<\/p>\n<p>However, I am not recommending anyone proceed with Rails development on Github using Windows. \u00a0Many of you have seen the demos I&#8217;ve given on developing in Vagrant, and we&#8217;ve got Student Team developers building their new app on Linux VMs. \u00a0<strong>We want to develop as Unix natives! \u00a0I am happy to personally assist anyone who needs help making this transition.<\/strong><\/p>\n<p><strong>STEP 2:\u00a0<a href=\"https:\/\/github.com\/blog\/1614-two-factor-authentication\">Set up two-factor authentication on your GitHub account.<\/a>\u00a0<\/strong>\u00a0The easiest way to do this is to set up your smartphone with the Google Authenticator app, which will act as a keyfob for getting into GitHub.<\/p>\n<p><strong>STEP 3: Use SSH on the command line. \u00a0<\/strong>There are two ways to do this:<\/p>\n<ol>\n<li>Use the SSH URL when you first do your git clone\n<ol>\n<li>Find the SSH URL as shown below, circled in green.<\/li>\n<li>do\u00a0<em>git clone SSH_URL<\/em>\u00a0and get on with your life. \u00a0You&#8217;ll never need the Google Authenticator.<\/li>\n<li><a href=\"http:\/\/blogs.nd.edu\/devops\/files\/2014\/02\/Screen-Shot-2014-02-21-at-11.13.55-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-286\" alt=\"Screen Shot 2014-02-21 at 11.13.55 AM\" src=\"http:\/\/blogs.nd.edu\/devops\/files\/2014\/02\/Screen-Shot-2014-02-21-at-11.13.55-AM.png\" width=\"2138\" height=\"1712\" srcset=\"https:\/\/sites.nd.edu\/devops\/files\/2014\/02\/Screen-Shot-2014-02-21-at-11.13.55-AM.png 2138w, https:\/\/sites.nd.edu\/devops\/files\/2014\/02\/Screen-Shot-2014-02-21-at-11.13.55-AM-300x240.png 300w, https:\/\/sites.nd.edu\/devops\/files\/2014\/02\/Screen-Shot-2014-02-21-at-11.13.55-AM-1024x819.png 1024w, https:\/\/sites.nd.edu\/devops\/files\/2014\/02\/Screen-Shot-2014-02-21-at-11.13.55-AM-374x300.png 374w\" sizes=\"auto, (max-width: 2138px) 100vw, 2138px\" \/><\/a><\/li>\n<\/ol>\n<\/li>\n<li>Modify your existing git checkout directory to use SSH\n<ol>\n<li>Check your remotes by typing\u00a0<em>git remote -v<\/em><\/li>\n<li>You&#8217;ll see something like this:\n<ol>\n<li>origin https:\/\/github.com\/ndoit\/muninn (fetch)<br \/>\norigin https:\/\/github.com\/ndoit\/muninn (push)<\/li>\n<\/ol>\n<\/li>\n<li>That means you have a remote site called &#8220;origin&#8221; which represents github. \u00a0This is the remote URL you use for push\/pull. \u00a0<strong>We need to change it to use SSH!<\/strong><\/li>\n<li>That&#8217;s easy. \u00a0Have the SSH URL handy as shown above.<\/li>\n<li><em>git remote -h<\/em>\u00a0 \u00a0tells you the help details, but here&#8217;s what we&#8217;ll do:\n<ol>\n<li>git remote set-url origin SSH_URL<\/li>\n<li>Where SSH_URL is your ssh URL, of course.<\/li>\n<\/ol>\n<\/li>\n<li>push\/ pull as normal!<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h2>SSH Forwarding and Vagrant<\/h2>\n<p>Another vital result of enabling SSH is that you can now perform SSH Agent Forwarding. \u00a0What do that mean?? \u00a0Imagine the following scenario:<\/p>\n<ol>\n<li>You create an SSH keypair for use with GitHub as shown above, on your laptop<\/li>\n<li>You launch a vagrant VM for Rails development<\/li>\n<li>You try to git clone via SSH<\/li>\n<li><strong>FORBIDDEN!<\/strong><\/li>\n<\/ol>\n<p>The problem is that the SSH key you registered with GitHub is on your laptop, but the VM is a whole other machine. \u00a0Fortunately, we can use\u00a0<strong>SSH agent forwarding<\/strong>\u00a0to use your laptop&#8217;s keys on a remote machine.<\/p>\n<p>In Vagrant, this is a one-liner in the Vagrantfile: \u00a0<em>config.ssh.forward_agent = true<\/em><\/p>\n<p>Or use -A when using ssh from the command line: \u00a0<em>ssh user@someplace -A<\/em><\/p>\n<p>Now your keys travel with you, and\u00a0<em>ssh git@github.com<\/em>\u00a0will result in a personal greeting, rather than &#8220;Permission denied.&#8221;<\/p>\n<h2>Conclusion<\/h2>\n<p>If you&#8217;re using GitHub, you need to do all of this. \u00a0I can help you. \u00a0When you&#8217;re done, you&#8217;ll be more secure and generally be more attractive to your friends and colleagues. \u00a0Plus, you&#8217;ll be able to do remote deployments, which is a very good topic for my next blog post. See you next time!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Please see my previous post about joining the NDOIT GitHub Organization. You can easily clone a git repository using the https URL that appears in your browser when you visit it on GitHub. \u00a0However, you can also use an SSH &hellip; <a href=\"https:\/\/sites.nd.edu\/devops\/2014\/02\/21\/using-ssh-with-github-for-fun-and-profit\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1550,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-288","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/sites.nd.edu\/devops\/wp-json\/wp\/v2\/posts\/288","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.nd.edu\/devops\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.nd.edu\/devops\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/devops\/wp-json\/wp\/v2\/users\/1550"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/devops\/wp-json\/wp\/v2\/comments?post=288"}],"version-history":[{"count":5,"href":"https:\/\/sites.nd.edu\/devops\/wp-json\/wp\/v2\/posts\/288\/revisions"}],"predecessor-version":[{"id":295,"href":"https:\/\/sites.nd.edu\/devops\/wp-json\/wp\/v2\/posts\/288\/revisions\/295"}],"wp:attachment":[{"href":"https:\/\/sites.nd.edu\/devops\/wp-json\/wp\/v2\/media?parent=288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.nd.edu\/devops\/wp-json\/wp\/v2\/categories?post=288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.nd.edu\/devops\/wp-json\/wp\/v2\/tags?post=288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}