{"id":6000,"date":"2024-03-22T12:39:07","date_gmt":"2024-03-22T12:39:07","guid":{"rendered":"https:\/\/natsav.com\/blog\/?p=6000"},"modified":"2024-04-22T11:32:51","modified_gmt":"2024-04-22T11:32:51","slug":"connecting-github-using-ssh-key","status":"publish","type":"post","link":"https:\/\/natsav.com\/blog\/connecting-github-using-ssh-key\/","title":{"rendered":"How to Connect Git to GitHub Using SSH Key"},"content":{"rendered":"<p style=\"text-align: justify;\">In the realm of version control and collaborative development, Git serves as a cornerstone tool, and GitHub stands tall as a leading platform for hosting repositories and fostering collaboration. To maximize security and streamline your workflow, connecting Git to GitHub via SSH key is a prudent choice. This blog post will walk you through the straightforward process, empowering you to securely manage your projects on GitHub.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_68_1 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/natsav.com\/blog\/connecting-github-using-ssh-key\/#Why_SSH_Key\" title=\"Why SSH Key?\">Why SSH Key?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/natsav.com\/blog\/connecting-github-using-ssh-key\/#Step_1_Generate_SSH_Key\" title=\"Step 1: Generate SSH Key\">Step 1: Generate SSH Key<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/natsav.com\/blog\/connecting-github-using-ssh-key\/#Step_2_Add_SSH_Key_to_GitHub\" title=\"Step 2: Add SSH Key to GitHub\">Step 2: Add SSH Key to GitHub<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/natsav.com\/blog\/connecting-github-using-ssh-key\/#Step_3_Test_SSH_Connection\" title=\"Step 3: Test SSH Connection\">Step 3: Test SSH Connection<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/natsav.com\/blog\/connecting-github-using-ssh-key\/#Step_4_Update_Git_Remote_URL_Optional\" title=\"Step 4: Update Git Remote URL (Optional)\">Step 4: Update Git Remote URL (Optional)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/natsav.com\/blog\/connecting-github-using-ssh-key\/#Conclusion\" title=\"Conclusion\">Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Why_SSH_Key\"><\/span><strong>Why SSH Key?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">SSH (Secure Shell) keys provide a secure method for authenticating your identity without the need for repeatedly entering passwords. By utilizing SSH keys, you enhance security while seamlessly interacting with GitHub repositories.<\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Step_1_Generate_SSH_Key\"><\/span><strong>Step 1: Generate SSH Key<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Begin by generating an SSH key pair on your local machine. Open your terminal or command prompt and execute the following command, replacing &#8220;your_email@example.com&#8221; with your GitHub-associated email:<\/p>\n<p style=\"text-align: justify;\">ssh-keygen -t rsa -b 4096 -C &#8220;your_email@example.com&#8221;<br \/>\nThis command prompts you for the desired location to save the key pair and an optional passphrase for added security.<\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Step_2_Add_SSH_Key_to_GitHub\"><\/span><strong>Step 2: Add SSH Key to GitHub<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">Next, you&#8217;ll need to add your SSH public key to your GitHub account. Retrieve the public key by running:<\/p>\n<p style=\"text-align: justify;\">pbcopy &lt; ~\/.ssh\/id_rsa.pub<br \/>\nFor <a href=\"https:\/\/www.natsav.com\/windows-vps-server-hosting.php\"><strong>Windows<\/strong><\/a> and Linux users without pbcopy, manually open id_rsa.pub and copy its contents. Then, navigate to your GitHub account settings, select &#8220;SSH and GPG keys,&#8221; and click &#8220;New SSH key.&#8221; Paste the copied key into the designated field and assign a recognizable title.<\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Step_3_Test_SSH_Connection\"><\/span><strong>Step 3: Test SSH Connection<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">To verify successful SSH key configuration, establish a connection with GitHub:<\/p>\n<p style=\"text-align: justify;\">ssh -T git@github.com<br \/>\nUpon execution, you should receive a confirmation message, signaling that you&#8217;ve authenticated with GitHub via SSH.<\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Step_4_Update_Git_Remote_URL_Optional\"><\/span><strong>Step 4: Update Git Remote URL (Optional)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">If you&#8217;ve previously configured Git with an HTTPS remote URL, transitioning to SSH is a breeze. Simply update the remote URL with the SSH variant using:<\/p>\n<p style=\"text-align: justify;\">git remote set-url origin git@github.com:username\/repository.git<br \/>\nReplace username\/repository with your GitHub username and repository name.<\/p>\n<h2 style=\"text-align: justify;\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align: justify;\">With these simple steps, you&#8217;ve seamlessly connected Git to GitHub using SSH key authentication. Embrace the enhanced security and convenience this setup offers, empowering you to collaborate efficiently and safeguard your projects with confidence.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the realm of version control and collaborative development, Git serves as a cornerstone tool, and GitHub stands tall as a leading platform for hosting repositories and fostering collaboration. To maximize security and streamline your workflow, connecting Git to GitHub via SSH key is a prudent choice. This blog post will walk you through the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6001,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[267],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2024\/03\/GITHUB-e1711111134187.png?fit=591%2C266&ssl=1","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/6000"}],"collection":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/comments?post=6000"}],"version-history":[{"count":10,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/6000\/revisions"}],"predecessor-version":[{"id":6116,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/6000\/revisions\/6116"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media\/6001"}],"wp:attachment":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media?parent=6000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/categories?post=6000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/tags?post=6000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}