This means, on your local machine, you haven't made any SSH keys. Not to worry. Here's how to fix:
- Open git bash (Use the Windows search. To find it, type "git bash") or the Mac Terminal. Pro Tip: You can use any
*nix
based command prompt (but not the default Windows Command Prompt!) - Type
cd ~/.ssh
. This will take you to the root directory for Git (LikelyC:\Users\[YOUR-USER-NAME]\.ssh\
on Windows) - Within the
.ssh
folder, there should be these two files:id_rsa
andid_rsa.pub
. These are the files that tell your computer how to communicate with GitHub, BitBucket, or any other Git based service. Typels
to see a directory listing. If those two files don't show up, proceed to the next step. NOTE: Your SSH keys must be namedid_rsa
andid_rsa.pub
in order for Git, GitHub, and BitBucket to recognize them by default. - To create the SSH keys, type
ssh-keygen -t rsa -C "your_email@example.com"
. This will create bothid_rsa
andid_rsa.pub
files. - Now, go and open
id_rsa.pub
in your favorite text editor (you can do this via Windows Explorer or the OSX Finder if you like, typingopen .
will open the folder). - Copy the contents--exactly as it appears, with no extra spaces or lines--of
id_rsa.pub
and paste it into GitHub and/or BitBucket under the Account Settings > SSH Keys. NOTE: I like to give the SSH key a descriptive name, usually with the name of the workstation I'm on along with the date. - Now that you've added your public key to Github and/or BitBucket, try to
git push
again and see if it works. It should!
More help available from GitHub on creating SSH Keys and BitBucket Help.
If you:
id_rsa
git
you need some troubleshooting to use git installation executables and a prior setup:
First of all thanks for this gist, it helped me out when I was at a total loss!!!
1. Start or get currently running agent into env vars (PID and socket/pipe file).
start-ssh-agent.cmd
It should be in PATH, otherwise find it at
C:\Program Files\Git\cmd
This command undocumented in the FAQ will spawn a child CMD with the dynamic env vars set. Use it, if you close it will leave the agent on but
git
calls won't work as wanted.2. Make sure you're using the ssh executables from the git installation
In PowerShell:
Get-Command ssh
(this is likewhich ssh
in Linux)You're probably not using that, so point there before anything else.
In CMD:
set PATH=C:\Program Files\Git\usr\bin;%PATH%
In PowerShell:
$Env:PATH = "C:\Program Files\Git\usr\bin;$Env:PATH"
3. Only after that load keys using git installation's ssh-add:
ssh-add <PATH_TO_KEY>
And enter the passphrase.
Then you can use
git
directly from CWD/PowerShell without (so much) troubles. Not onlygit push
but alsogit clone
, etc.I needed this for some automation and didn't want to spawn a Git Bash per git call, neither wanted to run inside Git Bash.
https://gist.github.com/2bam/33347ff54be8088943450f20323fde53