setting up ssh keys for github and bitbucket
Generating a new SSH key for GitHub
Basic ssh key adding
Generating a new SSH key for GitHub.
ssh-keygen -t ed25519 -C "<insert email>" -f ~/.ssh/githubssh-add -K ~/.ssh/github
Paste the following into GitHub:
pbcopy < ~/.ssh/github.pub
Add the SSH key locally.
ssh -T git@bitbucket.org-clientname
If you use a new host or something like `bitbucket.org-clientname` as `host`, you need to add it to your ssh.
ssh -T git@bitbucket.org-clientname
Config file
If there is no config file yet:
touch ~/.ssh/config
Once there is a config file, you can add configurations with the following:
printf "# Github\n Host github.com\n Hostname github.com\n AddKeysToAgent yes\n UseKeychain yes\n IdentityFile ~/.ssh/github" | tee ~/.ssh/config
Multiple accounts by the same host
Sometimes you have different accounts (work, private, client 1, client 2, ...), and you want to ensure you commit with the proper credentials.
You can do that, but it requires a bit of work. It works the same way you add a regular ssh-key, but there are some differences.
ssh-keygen -t ed25519 -C "<insert email>" -f ~/.ssh/bitbucket-privatessh-add -K ~/.ssh/bitbucket-private
Paste the following into your host (Bitbucket in this example):
pbcopy < ~/.ssh/bitbucket-private.pub
Now is where it gets different. You create an alias. We can add anything we want behind the hostname. In this example, we add "-private", but it might as well be "-client-x".
ssh -T git@bitbucket.org-private
In the config, we resolve the hostname.
printf "# Bitbucket private\n Host bitbucket.org-private\n Hostname bitbucket.org\n AddKeysToAgent yes\n UseKeychain yes\n IdentityFile ~/.ssh/bitbucket-private" | tee ~/.ssh/config