{"id":1081,"date":"2023-08-30T00:36:34","date_gmt":"2023-08-29T19:06:34","guid":{"rendered":"https:\/\/www.openwriteup.com\/?page_id=1081"},"modified":"2024-04-02T08:37:02","modified_gmt":"2024-04-02T03:07:02","slug":"configuring-ssh-for-git-and-push","status":"publish","type":"page","link":"https:\/\/www.openwriteup.com\/?page_id=1081","title":{"rendered":"Configuring SSH for Git and push"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Youtube link<\/strong><\/span>: <span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/www.youtube.com\/watch?v=nLnokLBJ-C4&amp;list=PLwO9EbabNLzsaHgP1dUCkdLg2CxZoPXGR&amp;index=4\">Navigation to pefrom lab<\/a><\/span><\/p>\n<p>This lab has three parts:<\/p>\n<p><strong>Part1: Create a github account<\/strong><\/p>\n<ol>\n<li>Go to github.com<\/li>\n<li>Incase you have existing github account please use or sign up for a new account<\/li>\n<li>If you choose to sign up for a new account, click &#8216;Sign up&#8217; at the top right\n<ol>\n<li>Create a username. You might need to use a personal email address<\/li>\n<li>You will need to check your email and verify that your email address is real<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><strong>Part2: creating repo on github<\/strong><\/p>\n<p>Create a private repository in your GitHub account called \u201cgittraining\u201d<br \/>\na. Name: repo-lab<br \/>\nb. Choose \u2018Public\u2019<br \/>\nc. Do not initialize with a README<br \/>\nd. Click the green &#8216;Create Repository&#8217; button<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-medium wp-image-1083\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git-300x177.png\" alt=\"\" width=\"300\" height=\"177\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git-300x177.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git-700x414.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git-768x454.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git.png 1012w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Copy the SSH URL under \u2018Quick Setup\u2019<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git2-1.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-1085\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git2-1-300x170.png\" alt=\"\" width=\"300\" height=\"170\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git2-1-300x170.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git2-1-700x396.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git2-1-768x434.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git2-1.png 1057w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>On your remote putty: in the my-repo directory:<\/p>\n<pre id=\"empty-setup-new-repo-echo\" class=\"copyable-terminal-content f5\"><span class=\"user-select-contain\"># Below are the example, please change the command as per your git repo\r\ngit branch -M main\r\ngit remote add origin <span data-targets=\"git-clone-help.helpTexts\">git@github.com:amitopenwriteup\/gittraining.git<\/span><\/span>\r\n<span class=\"user-select-contain mb-0\">git push -u origin main\r\n\r\n<strong>#This should fail<\/strong> \r\n<\/span><\/pre>\n<p><strong>Part 3:<\/strong> <strong>Configuring SSH Connections to GitHub<\/strong><\/p>\n<p>To fix this, we need to follow these four steps:<br \/>\na. Create an SSH key pair<br \/>\nb. Add the PUBLIC key to GitHub<br \/>\nc. GitHub will use the PUBLIC key that you uploaded to GitHub in step \u2018B\u2019 to<br \/>\ndecrypt the communication from the PRIVATE key from your workstation,<br \/>\nAUTHENTICATING you as an authorized user<\/p>\n<pre> ssh-keygen -t rsa -b 4096<\/pre>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git4.jpg\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-1087\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git4-300x83.jpg\" alt=\"\" width=\"300\" height=\"83\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git4-300x83.jpg 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git4-700x193.jpg 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git4-768x212.jpg 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git4.jpg 890w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>#Press enter, no passphrase<\/p>\n<p>Your identification has been saved in \/root\/.ssh\/id_rsa [Private key]<br \/>\nYour public key has been saved in \/root\/.ssh\/id_rsa.pub [Public key]<\/p>\n<pre> cat \/root\/.ssh\/id_rsa.pub\r\n#copy the value<\/pre>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git5.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1088\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git5-300x56.jpg\" alt=\"\" width=\"300\" height=\"56\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git5-300x56.jpg 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git5-700x131.jpg 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git5-768x143.jpg 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git5.jpg 1201w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now go to github.com<\/p>\n<p>Go to: Settings -&gt; SSH &amp; GPG keys -&gt; SSH Keys<br \/>\nClick &#8216;New SSH key&#8217;<br \/>\nTitle \u201cPublic repo-key\u201d<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1089\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git6-300x177.png\" alt=\"\" width=\"300\" height=\"177\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git6-300x177.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git6-700x414.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git6-768x454.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git6.png 1012w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Add keys<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1090\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git7-300x177.png\" alt=\"\" width=\"300\" height=\"177\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git7-300x177.png 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git7-700x414.png 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git7-768x454.png 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/git7.png 1012w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now try to push it<\/p>\n<pre>git push origin main<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Youtube link: Navigation to pefrom lab This lab has three parts: Part1: Create a github account Go to github.com Incase you have existing github account please use or sign up for a new account If you choose to sign up for a new account, click &#8216;Sign up&#8217; at the top right Create a username. You might need to use a personal email address You will need to check your email and verify that your email address is real Part2: creating repo on github Create a private repository in your GitHub account called \u201cgittraining\u201d a. Name: repo-lab b. Choose \u2018Public\u2019 c. Do not initialize with a README d. Click the green &#8216;Create Repository&#8217; button Copy the SSH URL under \u2018Quick Setup\u2019 On your remote putty: in the my-repo directory: # Below are the example, please change the command as per your git repo git branch -M main git remote add origin git@github.com:amitopenwriteup\/gittraining.git git push -u origin main #This should fail Part 3: Configuring SSH Connections to GitHub To fix this, we need to follow these four steps: a. Create an SSH key pair b. Add the PUBLIC key to GitHub c. GitHub will use the PUBLIC key that you uploaded to GitHub in step \u2018B\u2019 to decrypt the communication from the PRIVATE key from your workstation, AUTHENTICATING you as an authorized user ssh-keygen -t rsa -b 4096 #Press enter, no passphrase Your identification has been saved in \/root\/.ssh\/id_rsa [Private key] Your public key has been saved in \/root\/.ssh\/id_rsa.pub [Public key] cat \/root\/.ssh\/id_rsa.pub #copy the value Now go to github.com Go to: Settings -&gt; SSH &amp; GPG keys -&gt; SSH Keys Click &#8216;New SSH key&#8217; Title \u201cPublic repo-key\u201d Add keys Now try to push it git push origin main &nbsp;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1081","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/1081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1081"}],"version-history":[{"count":7,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/1081\/revisions"}],"predecessor-version":[{"id":1400,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/1081\/revisions\/1400"}],"wp:attachment":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}