- Conflicting SSH keys
- Committing with the wrong credentials
- Set your personal SSH key from GitHub -> unset your work SSH. Having to login manually in SSH every single time...
- Hairloss and broken keyboard due to stress of not getting it to work 👨🏻🦲
- Remove your current remote (now it's porbably http instead of ssh or tied to the wrong ssh key).
- Add your git remote again, but via a special way. It will be linked to the ssh-key that you wish to use for you repo. Below I'll try to explain it to you step-by-step. Feel free to ask questions if you can't get it to work.
- Your terminal is running in the
~/.ssh/
folder. - You generated the ssh files using
ssh-keygen -t rsa -C "example@youremailprovider.com"
- You type in a filename for your ssh keys. I'd recommend to put your username in it so you can easily link it in the next step. (PS: You're already in ~/.ssh so no need to enter path if asked in prev step)
- You had ssh-agent running so it did go without errors.
- You pasted your beautifullfilename.pub contents to Github via GitHub (add SSH key link)
- Create host file, probably you want to create it in
~/.ssh/
folder - Name this host file "config" (without any file-extensions)
- Use template below to add hosts, use a nice [subdomain].domain-name in
Host
(not mistaken with Hostname!) - Point to your ssh key in the field
IdentityFile
- See below for example on what your file can look like
# Example host file (named config, probably you want to put it in .ssh folder)
Host mebusiness.github.com
Hostname github.com
IdentityFile ~/.ssh/githubpersonal
IdentitiesOnly yes
Host mepersonal.github.com
Hostname bitbucket.com
IdentityFile ~/.ssh/githubpersonal
IdentitiesOnly yes
- Add our new remote to Git! (And replace the emoji to the value you've used in the config file).
`git remote add origin git@:username/repository.git `
git remote remove origin
git remote add origin git@<<<subdomain.domain.com>>:<<<UserNameInGitHub>>>/existing-repo.git
- Example:
git remote add origin git@me.github.com:Yaromey/existing-repo-url.git
- Don't forget the
.git
extension
Bonus!! --> Start your ssh agent automatically and add your keys to the agent everytime you open a Bash terminal:
- Go to your .bashrc file (user root directory) or just create one.
- Put this code in it -- V
if [ -z "$SSH_AUTH_SOCK" ] ; then
eval `ssh-agent -s`
ssh-add ~/.ssh/MY_PERSONAL_SSH_FILE
ssh-add ~/.ssh/MY_WORK_SSH_FILE
ssh-add ~/.ssh/MY_OTHER_SECONDARY_ACCOUNT_SSH_FILE
fi