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

  1. Open Terminal
  2. Generate your key pair using your email address
    $ ssh-keygen -t ed25519 -C "your.email@example.com"
    Generating public/private ed25519 key pair
  3. When prompted to "Enter a file in which to save the key," press Enter to accept the default file location
    $ Enter file in which to save the key (/Users/user/.ssh/id_ed25519)
  4. At the prompt, simply press enter for an empty passphrase
    $ Enter passphrase (empty for no passphrase): [press enter]
    $ Enter same passphrase again: [press enter again]

    Note: You can choose to enter a passphrase, but you will have to enter the password every time you run git commands

  5. After creating the passphrase you'll see the following confirmation
    Your identification has been saved in /Users/user/.ssh/id_ed25519.
    Your public key has been saved in /Users/user/.ssh/id_ed25519.pub.

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.