Created
August 24, 2018 04:57
-
-
Save mortenege/42b12a82f7d79877171af84c7d0a0714 to your computer and use it in GitHub Desktop.
How to set up using GitHub SSH with keys without agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. This assumes an SSH keypair exists, usually in ~/.ssh (windows C:\Users\<username>\.ssh) | |
2. This assumes a git repository exists, otherwise create one as usual `git init` | |
3. Create a Repository on GitHub | |
4. Add SSH key to GitHub | |
5. Add the remote origin from gthub | |
``` | |
git remote add origin [email protected]:<username>/<repo>.git | |
``` | |
use `git remote -v` to verify | |
6. Edit your SSH config-file `~/.ssh/config` (windows `C:\Users\<username>\.ssh\config`) and add a Host | |
``` | |
Host github | |
HostName github.com | |
User git | |
IdentityFile "path/to/ssh/private-key" | |
IdentitiesOnly yes | |
``` | |
7. Edit the git projects config-file `.git\config` and add in [core] | |
``` | |
sshCommand = "ssh -F <path/to/ssh/config/file>" | |
``` | |
8. Use git push like usual | |
``` | |
git push origin master | |
``` |
Ill just add that for some reason this did't work and trying git push origin main
(my branch is called main, not master) I was getting [email protected]: Permission denied (publickey)'.
. However putting only the following in the ~/.ssh.config file:
Host github.com
IdentityFile "path/to/ssh/private-key"
did work. So someone may want to try that if they are having the same issue as me. Maybe someone smart may immediately identify why the original .ssh/config was not working for me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was helpful, thank you both! I'll add that the ssh command can also be set via the
GIT_SSH_COMMAND
environment variable if editing the config is inconvenient.