SSH Key Management for Git
If you use multiple SSH keys with Git or you Git in conjunction with SSH Gateway, you can simplify your connection process by telling your computer in advance which SSH key is used for which service. This can be accomplished using a SSH config
file on your local machine. In this article we will explain how to configure your SSH config file for Git.
Create SSH Config File
- On your local machine, first navigate to your
.ssh
directory.- MacOS – Open Terminal and type:
cd ~/.ssh/
- Windows – Use Git Bash and navigate to:
/c/Users/[youruser]/.ssh/
- MacOS – Open Terminal and type:
- To create the file run:
touch config
- To edit the file run:
vi config
- Inside the file, tap
i
to insert text - Paste the following contents:
Host git.wpestaging.qa
User git
Hostname git.wpestaging.qa
PreferredAuthentications publickey
IdentityFile ~/.ssh/wpegitkey
IdentitiesOnly yes
- To save and exit the vim editor:
esc
button then:wq
If you are using SSH Gateway and Git, additional SSH Config contents should be added for SSH Gateway.
If you are using a different key than what is generated in our Git setup guide, be sure to update ~/.ssh/wpegitkey
to your own private key file path.
Add Remotes
Now that you have a config file set up for your SSH keys, you can manage your remote repositories easier. Just use your Host alias name when adding your remote repositories.
Be sure to update environmentname to the WP Engine unique name of your environment (i.e. environmentname.wpestaging.qa)
git remote add production [email protected]:production/environmentname.git
NEXT STEP: Learn how to add your SSH key to an environment for use with Git