{"id":427,"date":"2018-02-25T21:36:11","date_gmt":"2018-02-25T21:36:11","guid":{"rendered":"http:\/\/kevinmichaelcoy.com\/blog\/?p=427"},"modified":"2018-02-25T21:36:11","modified_gmt":"2018-02-25T21:36:11","slug":"use-ssh-key-exchange-with-bitbucket-instead-of-https","status":"publish","type":"post","link":"http:\/\/kevinmichaelcoy.com\/blog\/2018\/02\/25\/use-ssh-key-exchange-with-bitbucket-instead-of-https\/","title":{"rendered":"Use SSH Key Exchange with BitBucket instead of HTTPS"},"content":{"rendered":"<p>By default, my BitBucket Git repository uses the HTTPS URL instead of the SSH. As a result, I get prompted for my password every time I push code to my BitBucket Git repository.<\/p>\n<p>[code language=&#8221;bash&#8221;]<br \/>\n$ git push<br \/>\nPassword for &#8216;https:\/\/&lt;repo_owner&gt;@bitbucket.org&#8217;:<br \/>\n[\/code]<\/p>\n<p>You should see\u00a0your BitBucket account username in place of\u00a0<strong>&lt;repo_owner&gt;<\/strong>\u00a0. If you want to avoid having to do this every time, you must configure BitBucket to have your SSH Key. Therefore, copy your SSH key (or <a href=\"https:\/\/confluence.atlassian.com\/x\/X4FmKw\">generate one<\/a> if you haven&#8217;t already) and add it your account settings in BitBucket (ie, https:\/\/bitbucket.org\/account\/user\/<span style=\"color: #993300;\"><strong>&lt;repo_owner&gt;<\/strong><\/span>\/ssh-keys\/).<\/p>\n<p>[code language=&#8221;bash&#8221;]<br \/>\n$ cat ~\/.ssh\/id_rsa.pub | pbcopy<br \/>\n[\/code]<\/p>\n<p>Now, you must configure your Git to use SSH instead of HTTPS. You can do this globally for all Git repos on your machine\/account, by doing the following:<\/p>\n<p>[code language=&#8221;bash&#8221;]<br \/>\n$ git config &#8211;global url.ssh:\/\/&lt;repo_owner&gt;@bitbucket.org\/.insteadOf https:\/\/&lt;repo_owner&gt;@bitbucket.org\/<br \/>\n[\/code]<\/p>\n<p>You can confirm that this works by checking your global configuration file and look for the insteadOf:<\/p>\n<p>[code language=&#8221;bash&#8221;]<br \/>\n$ cat ~\/.gitconfig<br \/>\n[url &quot;ssh:\/\/&lt;repo_owner&gt;@bitbucket.org\/&quot;]<br \/>\n\tinsteadOf = https:\/\/&lt;repo_owner&gt;@bitbucket.org\/<br \/>\n[\/code]<\/p>\n<p>Now, you&#8217;ll be able to push code changes to BitBucket without being prompted for a password.<\/p>\n<p>Sources:<\/p>\n<ul>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/11200237\/how-do-i-get-git-to-default-to-ssh-and-not-https-for-new-repositories\">https:\/\/stackoverflow.com\/questions\/11200237\/how-do-i-get-git-to-default-to-ssh-and-not-https-for-new-repositories<\/a><\/li>\n<li><a href=\"https:\/\/confluence.atlassian.com\/bitbucket\/ssh-keys-935365775.html\">https:\/\/confluence.atlassian.com\/bitbucket\/ssh-keys-935365775.html<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>By default, my BitBucket Git repository uses the HTTPS URL instead of the SSH. As a result, I get prompted for my password every time I push code to my BitBucket Git repository. [code language=&#8221;bash&#8221;] $ git push Password for &#8216;https:\/\/&lt;repo_owner&gt;@bitbucket.org&#8217;: [\/code] You should see\u00a0your BitBucket account username in place&#8230;<\/p>\n<p class=\"continue-reading-button\"> <a class=\"continue-reading-link\" href=\"http:\/\/kevinmichaelcoy.com\/blog\/2018\/02\/25\/use-ssh-key-exchange-with-bitbucket-instead-of-https\/\">Continue reading<i class=\"crycon-right-dir\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,3],"tags":[282,307,320,322,323,321],"_links":{"self":[{"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/posts\/427"}],"collection":[{"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/comments?post=427"}],"version-history":[{"count":7,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/posts\/427\/revisions"}],"predecessor-version":[{"id":434,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/posts\/427\/revisions\/434"}],"wp:attachment":[{"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/media?parent=427"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/categories?post=427"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/kevinmichaelcoy.com\/blog\/wp-json\/wp\/v2\/tags?post=427"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}