{"id":4511,"date":"2019-05-10T11:13:27","date_gmt":"2019-05-10T09:13:27","guid":{"rendered":"http:\/\/blog.via-internet.de\/?p=4511"},"modified":"2019-05-10T11:13:27","modified_gmt":"2019-05-10T09:13:27","slug":"github-using-multiple-accounts","status":"publish","type":"post","link":"https:\/\/via-internet.de\/blog\/2019\/05\/10\/github-using-multiple-accounts\/","title":{"rendered":"Git | Using multiple accounts with Github"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"advgb-toc-43432112-ac6c-4a2e-bcc2-4d5508eb66f8\">Create a New SSH Key<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">We need to generate a unique SSH key for our second GitHub account.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ ssh-keygen -t rsa -C &lt;your email address><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Be careful: do not over-write your existing key for your personal account.  Instead, when prompted, save the file as&nbsp;<code>id_rsa_&lt;account name&gt;<\/code>. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I saved the file to&nbsp;<code>~\/.ssh\/id_rsa_placeholder<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/blog.via-internet.de\/wp-content\/uploads\/2019\/05\/ssh_create_id_rsa_file_for_github_authentication-700x280.png\" alt=\"\" class=\"wp-image-4588\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advgb-toc-4888c12e-0270-47e7-94a2-17e18f463563\">Attach the new Key to your Github Account<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next, login to your second GitHub account, browse to &#8220;<strong>Account Overview<\/strong>,&#8221; and attach the new key, within the &#8220;<strong>SSH Public Keys<\/strong>&#8221; section.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Copy and paste the content of the generated ssh file (with extention <strong>.pub<\/strong>): <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">~\/.ssh\/id_rsa_placeholder.pub<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: Be sure to give this key a descriptive title, so that you can remember the source of the key.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/blog.via-internet.de\/wp-content\/uploads\/2019\/05\/add_ssh_key_to_github_account-700x248.jpg\" alt=\"\" class=\"wp-image-4513\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advgb-toc-78d6408a-1401-43a4-a2b5-03e4e4bc77b7\">Configure you shell environment<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"advgb-toc-17b761ae-f253-44b0-a356-ac93f6dcd86e\">Start the ssh-agent, so that we can remember ssh-keys.<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ eval $(ssh-agent)\nAgent pid 5099<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong>: If you want to automatically start the agent on login, please look at the profile script at the end of this article<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"advgb-toc-1c2c2332-72a9-471f-9dfe-0fa4ada23107\">Now, add the key to the ssh-agent<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ ssh-add $HOME\/.ssh\/id_rsa_placeholder\nIdentity added: \/home\/ralphg\/.ssh\/id_rsa_placeholder (\/home\/placeholder\/.ssh\/id_rsa_placeholder)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Verify, that the key is loaded<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ ssh-add -l\n2048 SHA256:ZOvzhxxxMVxxxOsMxxxm2YxxxHpV4\/eAiFWyKJVRl\/xxxxx \/home\/placeholder\/.ssh\/id_rsa_placeholder (RSA)<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"advgb-toc-f876881a-1603-43c7-9a3d-3590c7654b4e\">Now, configure your github repository<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git remote -v \norigin https:\/\/github.com\/placeholder\/Awesome-Github.git (fetch)\norigin https:\/\/github.com\/placeholder\/Awesome-Github.git (push)<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"advgb-toc-37b9db98-d263-44be-8591-4a67d0a4a5d5\">Configure repository to use this ssh-key<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1-3\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"1,2,3\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git remote remove origin\n$ git remote add origin git@github.com:placeholder\/Awesome-Github.git\n$ git remote -v\norigin  git@github.com:placeholder\/Awesome-Github.git (fetch)\norigin  git@github.com:placeholder\/Awesome-Github.git (push)<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git push\nfatal: The current branch master has no upstream branch.\nTo push the current branch and set the remote as upstream, use<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git push --set-upstream origin master<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">The authenticity of host 'github.com (140.82.118.4)' can't be established.\nRSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.\nAre you sure you want to continue connecting (yes\/no)? yes\nWarning: Permanently added 'github.com,140.82.118.4' (RSA) to the list of known hosts.<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Counting objects: 5, done.\nDelta compression using up to 8 threads.\nCompressing objects: 100\nWriting objects: 100\nTotal 5 (delta 1), reused 0 (delta 0)\nremote: Resolving deltas: 100\nTo github.com:placeholder\/Awesome-Github.git&lt;\n    1679693..3bbeede  master -> master\nBranch 'master' set up to track remote branch 'master' from 'origin'.&lt;<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"advgb-toc-3609e292-68d5-4bbe-81f6-ecd083522503\">Configure your repository to use the created ssh-key<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1\" data-enlighter-linenumbers=\"false\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ git config core.sshCommand \"ssh -i ~\/.ssh\/id_rsa_placeholder\"<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advgb-toc-c7eb859a-d95d-4324-b66a-26413fb9320b\">Appendix<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"advgb-toc-4cb5ecdb-3809-4e0b-a8ee-105b59c09b89\">Shell profile script for autostart ssh-agent<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SSH_ENV=\"$HOME\/.ssh\/environment\"\n\nfunction start_agent {\n    echo \"Initialising new SSH agent...\"\n    \/usr\/bin\/ssh-agent | sed 's\/^echo\/#echo\/' > \"${SSH_ENV}\"\n    echo succeeded\n    chmod 600 \"${SSH_ENV}\"\n    . \"${SSH_ENV}\" > \/dev\/null\n    \/usr\/bin\/ssh-add;\n}\n\n# Source SSH settings, if applicable\n\nif [ -f \"${SSH_ENV}\" ]; then\n    . \"${SSH_ENV}\" > \/dev\/null\n    #ps ${SSH_AGENT_PID} doesn't work under cywgin\n    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > \/dev\/null || {\n        start_agent;\n    }\nelse\n    start_agent;\nfi<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advgb-toc-4b50fbdf-2361-4cc0-aac6-4b10933304eb\">Script: create_ssh_keys<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\n\nGITHUB_ACCOUNT=\"$1\"\necho ssh-keygen -t rsa -C \"${GITHUB_ACCOUNT}@via-internet.de\" -f id_rsa_${GITHUB_ACCOUNT}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advgb-toc-eeb1ffde-17c5-4fe8-9802-168ed906edd1\">Script: update_ssh_keys_to_HOME <\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/bash\nFLDR_DST=$HOME\/.ssh\n\nfor _FILE in id*\ndo\n    echo \"copy $_FILE\"\n    FILE_DST=\"${FLDR_DST}\/$(basename $_FILE)\"\n\n    chmod 600       $FILE_DST\n    cp  $_FILE      $FLDR_DST\n    chmod 400       $FILE_DST\ndone<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Create a New SSH Key We need to generate a unique SSH key for our second GitHub account. Be careful: do not over-write your existing key for your personal account. Instead, when prompted, save the file as&nbsp;id_rsa_&lt;account name&gt;. I saved the file to&nbsp;~\/.ssh\/id_rsa_placeholder Attach the new Key to your Github Account Next, login to your second GitHub account, browse to &#8220;Account Overview,&#8221; and attach the new key, within the &#8220;SSH Public Keys&#8221; section. Copy and paste the content of the generated ssh file (with extention .pub): Note: Be sure to give this key a descriptive title, so that you can remember [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4541,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[28],"tags":[],"class_list":["post-4511","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-git_github"],"jetpack_featured_media_url":"https:\/\/via-internet.de\/blog\/wp-content\/uploads\/2019\/05\/github.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/4511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/comments?post=4511"}],"version-history":[{"count":0,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/posts\/4511\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/media\/4541"}],"wp:attachment":[{"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/media?parent=4511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/categories?post=4511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/via-internet.de\/blog\/wp-json\/wp\/v2\/tags?post=4511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}