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.

mkdir -p ~/.ssh
cd ~/.ssh

# create keys with Ed25519
ssh-keygen -t ed25519 -f ~/.ssh/github -C ""
ssh-keygen -t ed25519 -f ~/.ssh/bitbucket -C ""

# add them to the keychain
eval "$(ssh-agent -s)"
ssh-add --apple-use-keychain ~/.ssh/github
ssh-add --apple-use-keychain ~/.ssh/bitbucket

# list all 
ssh-add -l

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.

pbcopy < ~/.ssh/
pbcopy < ~/.ssh/

Configure SSH

Add the path to the private key to the keychain

ssh-add -K ~/.ssh/bitbucket
ssh-add -K ~/.ssh/github

Open the configuration file (mate is my editor).

mate ~/.ssh/config

Paste the following content in ~/.ssh/config:

    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/bitbucket

    User git
    PreferredAuthentications publickey
    IdentitiesOnly yes
    IdentityFile ~/.ssh/github

Test the keys

Type the following to check that your GitHub setup authenticates correctly:

ssh -T
ssh -T

At this point you can clone projects from the terminal using the git protocol:

git clone --recursive

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.