Connecting to GitHub and Drupal with SSH keys from your local environment

Matt Artz @mattartz

In July of 2020, GitHub announced its intent to require the use of token-based authentication for all Git operation and on August 13, 2021, the password authentication will be deprecated. With SSH keys, you can connect to GitHub, including Drupal, without supplying your username and password each time you push or pull changes to or from the repo.

Follow the steps below to connect to GitHub and Drupal with SSH keys from your local environment.

Generating a new SSH key

Follow this tutorial to Generate an SSH Key.

Adding your SSH key to your GitHub account

  1. Open Terminal
  2. Copy your SSH public key to the clipboard
    $ pbcopy < ~/.ssh/id_ed25519.pub

Then, follow the documentation from GitHub in adding a new ssh key.

Adding your SSH key to your Drupal account

  1. Open Terminal
  2. Copy your SSH key to the clipboard
    $ pbcopy < ~/.ssh/id_ed25519.pub

Follow the documentation from Drupal in adding your public key to Drupal.org.

Adding your SSH key it to the ssh-agent

  1. Open Terminal
  2. Open and modify your ~/.ssh/config file using vi (or your favorite editor)
    $ vi ~/.ssh/config
  3.  Enter the following configurations to use your ssh key, created above, in the config file and save it
    Host git.drupal.org
    Hostname git.drupal.org
    User git
    IdentityFile ~/.ssh/id_ed25519
    
    Host github.com
    Hostname github.com
    User git
    IdentityFile ~/.ssh/id_ed25519

Switch Github repo to ssh

Locate your local git repo for your project and you can now switch it from HTTPS to SSH URLs. Follow the documentation from GitHub in changing a remote's URL.

Test your key if it works by doing pull or push commands in git in terminal for your local git repo.

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.