Amazon.co.uk Widgets

Log in

X

Using an SSH key, you can connect and authenticate to remote git servers without supplying your username and personal access token at each visit. Inevitably, you'll end up using more than one provider, for example for public projects and for internal private one, or for a particular client who requires a particular Git repository provider be used. SSh keys are more than just a convenient reduction in admin. They are essential in a devops environment where scripts and hooks will be working with code and multiple accounts and servers.

It is surprisingly easy to set up SSH access to Git repositories, but there are important things to think through which means you need to think about what you are doing. Most providers ofhave good instructions, and you could do no better than to start by reading one, such as this page Connecting to GitHub with SSH. The principles will be the same whatever the Git repository hosting provider.

TL:DR — SSH access to multiple Git repositories is easy to set up, convenient and secure but be careful not to accidentally overwrite other existing keys.

Create an SSH Config file — Step by Step instructions

  1. Open a terminal (this example was in Ubuntu Linux).
  2. Navigate to the .ssh hidden folder in your home directory
    $ cd .ssh
  3. Create or Edit the config file
    $ vi config
  4. Set out your different Git providers in the config file. I use both 'Assembla' and 'GitHub' for Git repository hosting. Replace the HostName and User with the right ones for your provider. I use a meaningful key file filename as these can get confusing quickly.
    Host git.assembla.com
     HostName git.assembla.com
     User Git
     IdentityFile ~/.ssh/id_rsa_username_domain_for_assembla
    
    Host github.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_username_domain_for_github
    
    So for this example if my username was harry and my domain name was example.com my key for github would be called id_rsa_harry_example_for_github

Create the SSH keys — Step by Step instructions

  1. Use ssh-keygen to create a new key associated with your email adddress used with the Git repository you are using. This example is for GitHub. Make sure you use the filename you used in your config file earlier. Dont use the defaults, as you could easily overwrite an existing key file. Remember, you are working in a hidden folder, the convention is that you know what you are doing here!
     $ ssh-keygen -t ed25519 -C "This email address is being protected from spambots. You need JavaScript enabled to view it."
    Generating public/private ed25519 key pair.
    Enter file in which to save the key (/home/me/.ssh/id_ed25519): id_rsa_harry_example_for_github
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in id_rsa_harry_example_for_github
    Your public key has been saved in id_rsa_harry_example_for_github.pub
  2. Add they key to your user account.
    $ ssh-add ~/.ssh/id_rsa_harry_example_for_github
  3. To use your new SSH key, you'll also need to add it to your Git repository account. In Github, click your profile photo, then click 'Settings', then click SSH and GPG keys and then click New SSH key.
  4. Copy the ssh key to the clipboard
    $ cat id_rsa_harry_example_for_github
    for example copy it from the terminal to the clipboard after listing the file with cat
  5. Paste it into GitHub 'key' field and give it a sensible name in the 'title' field.
  6. Save and thats it done.

Now you can use git commands against this repository without usernames and passwords. They key will be used instead.

Licences, trademarks, source code licences and attributions

Licences, trademarks, source code licences and attributions

928uk® is a trademark of Multizone Limited, registered in the UK. Multizone and this site is not affiliated with or endorsed by The Joomla! Project™. Any products and services provided through this site are not supported or warrantied by The Joomla! Project or Open Source Matters, Inc. Use of the Joomla!® name, symbol, logo and related trademarks is permitted under a limited licence granted by Open Source Matters, Inc. AdMob™, AdSense™, AdWords™, Android™, Chrome OS™, Chromebook™, Chrome™, DART™, Flutter™, Firebase™, Firestore™, Fuchsia™, Gmail™, Google Maps™, Google Pixel™, Google Play™, Pixelbook Go™, and Pixel™ and other trademarks listed at the Google Brand Resource center are trademarks of Google LLC and this site is not endorsed by or affiliated with Google in any way. Apple and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other countries. App Store is a service mark of Apple Inc. The OSI logo trademark is the trademark of Open Source Initiative. UNIX® and the X® logo are registered trademarks of The Open Group. Any other product or company names may be trademarks™ or registered® trademarks of their respective holders. Use of these trademarks in articles here does not apply affiliation or endorsement by any of them.

Where the source code is published here on ezone.co.uk or on our GitHub by Angus Fox, Multizone Limited it is licenced according to the open source practice for the project concerned.

BSD 3-Clause "New" or "Revised" Licence
Original source code for mobile apps are licenced using the same licence as the one used by "The Flutter Authors". This Licence, the BSD 3-Clause "New" or "Revised" Licence (bsd-3-clause) is a permissive licence with a clause that prohibits others from using the name of the project or its contributors to promote derived products without written consent.
GNU General Public Licence v2.0 or later
Original source code for Joomla! published here on ezone.co.uk by Angus Fox, Multizone Limited is licenced using the same licence as the one used by Joomla!. This Licence, the GNU General Public Licence Version 2 or later (gpl-2.0) is the most widely used free software licence and has a strong copyleft requirement. When distributing derived works, the source code of the work must be made available under the same licence.

You can use any code you find here, just respect the licences and dont use the name of this site or our company to promote derived products without written consent. I mean, why would you? You're not us!

Amazon Associate
As an Amazon Associate we earn from qualifying purchases.
Logo
Our Logo Image is by Freepik. We chose it because its an M and also the letter A twice - and that represents us.