If you use multiple SSH keys with git for multiple environments or accounts on WP Engine, you can simplify your connection process by helping your computer use the right SSH key for connection every time. This can be accomplished using a config file on your local machine. In this article we will explain how to configure a config file for use with git.
Creating your config file
To add a config file, first navigate on your local machine to your .ssh directory. First, if you are on a Mac, open up your Terminal and type this:
(On a Windows machine, you can use Git Bash and navigate to /c/Users/[you]/.ssh/ instead)
Now, make a config file:
Open/edit the config file using your favorite text editor (vim or nano being the most common):
Inside the file, paste the following content, replacing the identity file with the correct git key for one of your accounts:
(Remember, on a Windows machine the path to your .ssh folder will most likely look like this: /c/Users/[you]/.ssh with your SSH keys within)
Paste again, changing the host to be something memorable to each key (something that helps you remember which users/accounts this key belongs to), and changing the IdentityFile path to the proper key for each one.
Save your file and exit your editor when you have an entry for each git key.
Now that you have a config file set up for your SSH keys, you can use your Host entries when adding your remote repositories for easier management.
If I wanted to connect to my original Host entry (mapped to the “id_rsa” key in the example above), I can use the following syntax when adding my remotes:
git remote add production myaccountgitkey:production/environment-name.git
And now when I push to the “production” remote, it will read the correct SSH key for that profile when connecting.