{"id":239,"date":"2020-07-03T18:08:16","date_gmt":"2020-07-03T17:08:16","guid":{"rendered":"https:\/\/blog.thomarite.uk\/?p=239"},"modified":"2023-01-28T21:08:09","modified_gmt":"2023-01-28T21:08:09","slug":"github-ssh-key","status":"publish","type":"post","link":"https:\/\/blog.thomarite.uk\/index.php\/2020\/07\/03\/github-ssh-key\/","title":{"rendered":"Github + ssh-key"},"content":{"rendered":"\n<p>There are many links for this in the Internet so I am not going to discover the fire but I struggled a bit so&#8230;.<\/p>\n\n\n\n<p>The official links from github were ok and other people did a very good job too documenting the process.<\/p>\n\n\n\n<p><a href=\"https:\/\/docs.github.com\/en\/github\/authenticating-to-github\/testing-your-ssh-connection\">https:\/\/docs.github.com\/en\/github\/authenticating-to-github\/testing-your-ssh-connection<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/docs.github.com\/en\/github\/authenticating-to-github\/error-permission-denied-publickey\">https:\/\/docs.github.com\/en\/github\/authenticating-to-github\/error-permission-denied-publickey<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/jdblischak.github.io\/2014-09-18-chicago\/novice\/git\/05-sshkeys.html\">https:\/\/jdblischak.github.io\/2014-09-18-chicago\/novice\/git\/05-sshkeys.html<\/a><\/p>\n\n\n\n<p>I had already a key that I wanted to use. So adding it to the repo was ok.<\/p>\n\n\n\n<p>Testing it was my challenge. I was missing two things. My key wasn&#8217;t following the standard file name so it wasn&#8217;t used by my ssh-agent and then, i wasn&#8217;t using the &#8220;git&#8221; user when testing&#8230;. I was using my github username.<\/p>\n\n\n\n<p>So add the key and check it is there.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ ssh-add ~\/.ssh\/id_ed25519-gh\n$ ssh-add -l -E md5\n256 MD5:xx:xx:xx:xx:xx:67:xx:6a:73:xx:8a:xx:7f:78:xx:xx user@gh (ED25519)<\/pre>\n\n\n\n<p>Check you can ssh to github.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ ssh -T git@github.com\nHi xxxx! You've successfully authenticated, but GitHub does not provide shell access.\n$<\/pre>\n\n\n\n<p>Ok, all good now. But this is not a new repo, how I move from the &#8220;old&#8221; user\/pass to the &#8220;new&#8221; ssh-key process?<\/p>\n\n\n\n<p>You can clone the repo again using ssh:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.thomarite.uk\/wp-content\/uploads\/2020\/07\/Screenshot-from-2020-07-03-18-03-40.png\" alt=\"\" class=\"wp-image-240\" width=\"376\" height=\"228\" srcset=\"https:\/\/blog.thomarite.uk\/wp-content\/uploads\/2020\/07\/Screenshot-from-2020-07-03-18-03-40.png 558w, https:\/\/blog.thomarite.uk\/wp-content\/uploads\/2020\/07\/Screenshot-from-2020-07-03-18-03-40-300x182.png 300w\" sizes=\"auto, (max-width: 376px) 85vw, 376px\" \/><\/figure>\n\n\n\n<p>Or you can change the git config locally in the &#8220;url&#8221; bit.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/ceos-testing\/.git master$ cat config\n[core]\nrepositoryformatversion = 0\nfilemode = true\nbare = false\nlogallrefupdates = true\n[remote \"origin\"]\n#url = https:\/\/github.com\/thomarite\/ceos-testing.git\nurl = git@github.com:thomarite\/ceos-testing.git\nfetch = +refs\/heads\/<em>:refs\/remotes\/origin\/<\/em>\n[branch \"master\"]\nremote = origin\nmerge = refs\/heads\/master\n$<\/pre>\n\n\n\n<p>After that you can &#8220;git push&#8221; using your ssh-key.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>2023-01<\/strong><\/p>\n\n\n\n<p>Looks like I dont learn the lesson&#8230;.<\/p>\n\n\n\n<p>1- Create Key<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ ssh-keygen -t ed25519 -C \"your@email.com\"\nGenerating public\/private ed25519 key pair.\nEnter file in which to save the key (\/home\/USERNAME\/.ssh\/id_ed25519): \/home\/USERNAME\/.ssh\/id_ed25519.github\n<\/pre>\n\n\n\n<p>2- Upload key to Github<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>3- Start agent and add key<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ ssh-agent -s\nSSH_AUTH_SOCK=\/tmp\/ssh-XXXXXXjMtZn7\/agent.250293; export SSH_AUTH_SOCK;\nSSH_AGENT_PID=250294; export SSH_AGENT_PID;\necho Agent pid 250294;\n$ ssh-add ~\/.ssh\/id_ed25519.github\nIdentity added: \/home\/USERNAME\/.ssh\/id_ed25519.github (your@email.com)\n$ \n<\/pre>\n\n\n\n<p>4- Authenticate to git<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ ssh -T git@github.com\nHi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.\n$ <\/pre>\n\n\n\n<p>5- Push to git. Be sure your repo is not using https! Change it as showed <a href=\"https:\/\/stackoverflow.com\/questions\/14762034\/push-to-github-without-a-password-using-ssh-key\">here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ git remote get-url origin\nhttps:\/\/github.com\/SOMEBODY\/scripts.git\n$ git remote set-url origin git@github.com:SOMEBODY\/scripts.git\n$ \n$ git remote get-url origin\ngit@github.com:SOMEBODY\/scripts.git\n$ \n$ git push\nEnumerating objects: 5, done.\nCounting objects: 100% (5\/5), done.\nDelta compression using up to 4 threads\nCompressing objects: 100% (4\/4), done.\nWriting objects: 100% (4\/4), 2.07 KiB | 2.07 MiB\/s, done.\nTotal 4 (delta 1), reused 0 (delta 0), pack-reused 0\nremote: Resolving deltas: 100% (1\/1), completed with 1 local object.\nTo github.com:SOMEBODY\/scripts.git\n   6a4cb1a..07a4a83  main -> main\n$ \n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There are many links for this in the Internet so I am not going to discover the fire but I struggled a bit so&#8230;. The official links from github were ok and other people did a very good job too documenting the process. https:\/\/docs.github.com\/en\/github\/authenticating-to-github\/testing-your-ssh-connection https:\/\/docs.github.com\/en\/github\/authenticating-to-github\/error-permission-denied-publickey https:\/\/jdblischak.github.io\/2014-09-18-chicago\/novice\/git\/05-sshkeys.html I had already a key that I wanted to &hellip; <a href=\"https:\/\/blog.thomarite.uk\/index.php\/2020\/07\/03\/github-ssh-key\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Github + ssh-key&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-239","post","type-post","status-publish","format-standard","hentry","category-unix"],"_links":{"self":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/comments?post=239"}],"version-history":[{"count":4,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/239\/revisions"}],"predecessor-version":[{"id":1153,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/239\/revisions\/1153"}],"wp:attachment":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/media?parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/categories?post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/tags?post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}