Git how to clone with SSH key, username

Always coming late to answer anything, it may be possible that you have more than one ssh keys and if not specified git will try to use id_rsa but if you need a different one you could use

git clone [email protected]:userName/projectName.git --config core.sshCommand="ssh -i ~/location/to/private_ssh_key"

This way it will apply this config and use a key different than id_rsa before actually fetching any data from the git repository.

subsequent fetch or push will use the specified key to authenticate for the cloned repository.

Hope this is helpful to anyone.

Leave a Comment