If you're like me, you might want to have different SSH keys to access different machines or platforms that require it to communicate with git (Github, Gitlab, or other).
When SSH'ing to a machine, you can specify the certificate by adding the flag -i
to the command:
ssh -i ~/.ssh/my_particular_public_ssh_key_or_certificate myuser@myserveraddress.or.ip
Things get a bit more challenging when you have to pass this certificate to your push, pull or clone on protected repositories of git. To solve it, I've adopted the following strategy:
ssh-agent bash -c 'ssh-add ~/.ssh/my_particular_public_ssh_key_or_certificate; git clone user@gitrepository.local:my-group/my-project.git app'
In the example, I'm cloning the project after adding my "particular public ssh key" or "certificate" to my ssh-agent; this action is not permanent, meaning that your agent, when unspecified, will still use your ~/.ssh/id_rsa.pub
as the default public key. If you want to do something different than cloning, you can just replace the clone instruction to perform a push or a pull instead. Adding files and committing has no requirement of your ssh key: only on direct communications through the network to your git repository provider.