Automate Git Authentication with SSH
You have an account on GitHub and Bitbucket,
and you want to access both accounts using SSH keys without interaction.
Create the keys
Create keys for each domain.
Finder doesn’t show directories that start with a dot, but you can toggle the visibility of hidden files in Finder, click ⌘⇧. (that’s shift + command + dot).
Add them to your account
Copy the public keys and paste them on GitHub and on Bitbucket.
Configure SSH
Add the path to the private key to the keychain
Open the configuration file (mate is my editor).
Paste the following content in ~/.ssh/config:
Test the keys
Type the following to check that your GitHub setup authenticates correctly:
At this point you can clone projects from the terminal using the git protocol:
When cloning a repository, use the ssh: addresses. If you use the https: addresses you will be asked for user/password. For instance, let’s say you clone with ssh but the project has submodules declared with http. You can still automate this using an access token and a .netrc file. I’ll write about this next.