
You can also set an entirely different SSH binary with GIT_SSH. You can GIT_SSH_COMMAND='ssh -i ~/.ssh/github -o UserKnownHostsFile=/dev/null -o StrictHostKe圜hecking=no'Īny Git commands you run afterwards in the same shell session will use that SSH command instead of the default one. This is your local ssh client asking you to decrypt the private key, it is not the remote server asking for a password. If you don’t want to mess with SSH config, or just want to override it temporarily, Git also provides the GIT_SSH_COMMAND environment variable. However, if you set a passphrase when creating your SSH key, you will be asked to enter the passphrase at that time. git remote add origin Manually Overriding You can set separate hosts per-repository. Git will recognize this, and use this SSH host to connect. Then, instead of adding as the remote, replace it with the name of the Host in the SSH configuration file. If you have a remote repository like Github linked with your local repo, delete it: git remote remove origin Usually this would result in a conflicting configuration, but Git provides a way around this. Well, you’ll need to define two configurations with different names, using the same host: Host personal This will let you use a different SSH key than your primary one for all requests going to, but what if you want to use two different keys for separate Git repositories? For example, one for your work account, and one for your personal account. SSH’s config file allows setting “Hosts” which will match based on what you’re connecting to and allow modification of the file that ssh uses. ssh-keygen -t rsa -f ~/.ssh/github Editing ~/.ssh/config This will create a private key and a public key with the. Simply run ssh-keygen and specify a new key name with the -f flag. You’ll need one to do this in the first place, and doing this is pretty easy. This probably isn’t what you want if you’re here reading this, so to change it, you’ll need to edit SSH’s configuration-not Git’s. It does this silently, so you may not be aware of the commands it’s running, but it uses ssh under the hood.īecause it uses your default ssh command, it will act like you just ran it yourself, and use your default key in ~/.ssh/id_rsa. Git doesn’t just use your private key to authenticate when you use SSH instead of HTTPS-it actually establishes a real SSH connection to the remote server. By editing your SSH config though, you can connect to multiple Git repositories with different keys.

#How to set github in .ssh on mac password
Unlike a password however, it’s harder to change your SSH key, or manage multiple keys.

Using SSH keys is more secure than passwords, and that applies to Git as well.
