Using Multiple SSH Keys with WP Engine's Git Push Functionality
WP Engine has a great feature: the ability to push from your development environment (typically your local environment - VVV or MAMP or whatever) to a site’s staging or production environments using git. You just use git push. Typically I use this for moving local changes to the staging server. It sure beats moving files via PHPStorm’s depolyment sync or manual FTP transfer.
If you are unfamiliar with this process you can learn more through this WP Engine Support Garage article.
WP Engine provides great instructions on setting up an SSH key so you can use the git push feature, but its instructions focus on using a single SSH key. This may not be advisable from a security perspective (shared keys between different sites/clients), and also look unproffesional in the WP Engine web portal (a shared name between sites/clients). Therefore I thought it would be helpful to share how to configure multiple SSH keys.
Creating an SSH config file
The magic that will allow you to use multiple SSH keys is in the SSH config file. In the config file you can provide an entry for each SSH connection which should use a unique key. The following example will show you how to set up a SSH config file such that running the command
will ssh into git.wpengine.com using a private key stored in ~/.ssh/your_site_name/id_rsa.
Open terminal and enter:
- Enter the following into the file:
- press “CONTROL X” to exit
Generating an SSH Key
Now we have to create the SSH key we pointed to in the config file (IdentityFile). If you already know how to generate an SSH key feel free to skip ahead (just make sure the config file you created points to your private key). Otherwise, pop open terminal and run the following commands:
- save thev key to “~/.ssh/your_site_name/id_rsa”
Configuring WP Engine
So far we’ve set up public / private SSH keys and a config file that helps route to them. Now we have to configure WP Engine. You’ll want to be logged in under the account you’d like the SSH key associated with.
- Visit https://my.wpengine.com/installs/your_site_name/git_push (note “your_site_name” in the URL needs to be replaced with your site name)
- Provide a developer name
- Paste copied public key (~/.ssh/your_site_name/id_rsa.pub)
- Test (after 10 minutes) by running the following, making note of the repo names returned for use in next step:
- note that the “your_site_name” before the colon corresponds to the ~/.ssh/config “Host”
- note that the “staging/your_site_name” after the colon corresponds to the response from ssh your_site_name info
Once that’s set up you should be good to push using git as you normally would (for WP Engine).