{"id":836,"date":"2021-02-01T15:05:16","date_gmt":"2021-02-01T14:05:16","guid":{"rendered":"https:\/\/nguenkam.com\/blog\/?p=836"},"modified":"2023-08-03T09:56:57","modified_gmt":"2023-08-03T07:56:57","slug":"setup-ssh-keys-for-use-with-github-gitlab-bitbucket-etc","status":"publish","type":"post","link":"https:\/\/nguenkam.com\/blog\/index.php\/2021\/02\/01\/setup-ssh-keys-for-use-with-github-gitlab-bitbucket-etc\/","title":{"rendered":"Setup SSH keys for use with GitHub\/GitLab\/BitBucket etc"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>Create a new repository, or reuse an existing one.<\/p>\n\n\n\n<h5><span class=\"has-inline-color has-vivid-cyan-blue-color\">Generating a new SSH key<\/span><\/h5>\n\n\n\n<ul><li>Open&nbsp;Git Bash<\/li><li>paste the text below, substituting in your email address<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ssh-keygen -t ed25519 -C \"your_email@example.com\"<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Note:<\/strong>&nbsp;If you are using a legacy system that doesn't support the \nEd25519 algorithm, use:<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ssh-keygen -t rsa -b 4096 -C \"your_email@example.com\"<\/code><\/pre>\n\n\n\n<p>This creates a new ssh key, using the provided email as a label.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&gt; Generating public\/private ed25519 key pair.<\/code><\/pre>\n\n\n\n<p>the default file location is :  <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/c\/Users\/you\/.ssh\/id_ed25519<\/code><\/pre>\n\n\n\n<h5><span class=\"has-inline-color has-vivid-cyan-blue-color\">Adding your SSH key to your Git-account<\/span><\/h5>\n\n\n\n<p>Copy the contents of the file&nbsp;<code>~\/.ssh\/id_ed25519.pub<\/code>&nbsp; ( in Windows: \/c:\/users\/you\/.ssh\/id_ed25519.pub)  to your SSH keys in your Git account settings ( example: <a href=\"https:\/\/github.com\/settings\/keys\">https:\/\/github.com\/settings\/keys<\/a>).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">In the upper-right corner of any page, click your profile photo, then click&nbsp;<strong>Settings<\/strong>.\n<\/pre>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" src=\"https:\/\/docs.github.com\/assets\/images\/help\/settings\/userbar-account-settings.png\" alt=\"Settings icon in the user bar\" width=\"147\" height=\"329\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">In the user settings sidebar, click&nbsp;<strong>SSH and GPG keys<\/strong>.\n\n<img src=\"https:\/\/docs.github.com\/assets\/images\/help\/settings\/settings-sidebar-ssh-keys.png\" alt=\"Authentication keys\" style=\"width: 200px;\"><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Click&nbsp;<strong>New SSH key<\/strong>&nbsp;or&nbsp;<strong>Add SSH key<\/strong>.\n\n<img src=\"https:\/\/docs.github.com\/assets\/images\/help\/settings\/ssh-add-ssh-key.png\" alt=\"SSH Key button\"><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">In the \"Title\" field, add a descriptive label for the new key.\n For example, if you're using a personal Mac, you might call this\n key \"Personal MacBook Air\".\n\nPaste your key into the \"Key\" field.\n\n<img src=\"https:\/\/docs.github.com\/assets\/images\/help\/settings\/ssh-key-paste.png\" alt=\"The key field\" style=\"width: 400px;\"><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Click&nbsp;<strong>Add SSH key<\/strong>.\n<img src=\"https:\/\/docs.github.com\/assets\/images\/help\/settings\/ssh-add-key.png\" alt=\"The Add key button\"><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">If prompted, confirm your Git password.\n<img src=\"https:\/\/docs.github.com\/assets\/images\/help\/settings\/sudo_mode_popup.png\" alt=\"Sudo mode dialog\" style=\"width: 200px;\"><\/pre>\n\n\n\n<h5><span class=\"has-inline-color has-vivid-cyan-blue-color\">Testing if work !!<\/span><\/h5>\n\n\n\n<p>Test SSH key:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ ssh -T git@github.com\nHi developius! You've successfully authenticated, but GitHub does not provide shell access.<\/code><\/pre>\n\n\n\n<p>Change directory into the local clone of your repository (if you&#8217;re not already there) and run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git remote set-url origin git@github.com:username\/your-repository.git<\/code><\/pre>\n\n\n\n<p>Now try editing a file (try the README) and then do:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git commit -m \"Update README.md\"\n$ git push<\/code><\/pre>\n\n\n\n<p>If successful , you should not be asked for a username or password. Your SSH key is correctly configured.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h4><span class=\"has-inline-color has-vivid-red-color\">multiple ssh keys in  .ssh folder?<\/span><\/h4>\n\n\n\n<p>Yes you can have different ssh keys. for different repository or even different git tools ( exple: gitlab &amp; github).<\/p>\n\n\n\n<p>What you can do is set up a&nbsp;<a href=\"https:\/\/www.ssh.com\/ssh\/config\/\"><code>~\/.ssh\/config<\/code><\/a>&nbsp;file in which you can associate the right private key with the right host, as&nbsp;<a href=\"https:\/\/nerderati.com\/2011\/03\/17\/simplify-your-life-with-an-ssh-config-file\/\">explained here<\/a>.<\/p>\n\n\n\n<h5><span class=\"has-inline-color has-vivid-cyan-blue-color\"> I &#8211; Using multiple repositories on one server <\/span><\/h5>\n\n\n\n<p>In the server&#8217;s SSH configuration file (usually&nbsp;<code>~\/.ssh\/config<\/code>), add an alias entry for each repository. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Host github.com-repo-0\n        Hostname github.com\n        IdentityFile=\/home\/user\/.ssh\/repo-0_deploy_key\n\nHost github.com-repo-1\n        Hostname github.com\n        IdentityFile=\/home\/user\/.ssh\/repo-1_deploy_key<\/code><\/pre>\n\n\n\n<ul><li><code>Host github.com-repo-0<\/code>&nbsp;&#8211; The repository&#8217;s alias.<\/li><li><code>Hostname github.com<\/code>&nbsp;&#8211; Configures the hostname to use with the alias.<\/li><li><code>IdentityFile=\/home\/user\/.ssh\/repo-0_deploy_key<\/code>&nbsp;&#8211; Assigns a private key to the alias.<\/li><\/ul>\n\n\n\n<p>You can then use the hostname&#8217;s alias to interact with the repository using SSH, which will use the unique deploy key assigned to that alias. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git clone git@github.com-repo-1:OWNER\/repo-1.git<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Create a new repository, or reuse an existing one. Generating a new SSH key Open&nbsp;Git Bash paste the text below, substituting in your email address Note:&nbsp;If you are using a legacy system that doesn&#8217;t support the Ed25519 algorithm, use: This creates a new ssh key, using the provided email as a label. &gt; Generating public\/private [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[60,33,31],"tags":[61,209,185,210],"_links":{"self":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/836"}],"collection":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=836"}],"version-history":[{"count":5,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/836\/revisions"}],"predecessor-version":[{"id":2805,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/836\/revisions\/2805"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/807"}],"wp:attachment":[{"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nguenkam.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}