SSH: multiple keys for the same host
SSH: multiple keys for the same host
refs: https://gist.github.com/oanhnn/80a89405ab9023894df7, https://www.freecodecamp.org/news/the-ultimate-guide-to-ssh-setting-up-ssh-keys/, https://betterprogramming.pub/how-to-set-up-multiple-ssh-keys-ae6688f76570, https://stackoverflow.com/questions/2419566/best-way-to-use-multiple-ssh-private-keys-on-one-client
eg: one ssh key for work, another for personal
- generate both keys
ssh-keygen -t rsa(default path~/.ssh)ssh-keygen -t rsa(different path, eg~/.ssh2)
- add alias host names in
~/.ssh/configHost work HostName bitbucket.org IdentityFile ~/.ssh/id_rsa User git Host personal HostName bitbucket.org IdentityFile ~/.ssh2/id_rsa User git - add private keys to ssh-agent (default one is added automatically)
ssh-add ~/.ssh2/id_rsa
- use the alias while cloning
- instead of:
git clone git@bitbucket.org:username/my-work-project.git - use:
git clone git@work:username/my-work-project.git - and:
git clone git@personal:username/my-personal-project.git
- instead of: