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.
Here's how you can proceed:
Check for SSH keys in PowerShell:
Run the following command to check the contents of the .ssh directory:
Get-ChildItem -Path $env:USERPROFILE\.ssh
Copy the SSH public key:
To copy the public key to the clipboard, run the following command in PowerShell:
powershell
Get-Content $env:USERPROFILE\.ssh\id_rsa.pub | clip
This will copy the contents of your public key (id_rsa.pub) to your clipboard.
Add the SSH key to your GitHub account:
Go to GitHub and sign in.
Navigate to Settings by clicking your profile picture at the top-right, then click SSH and GPG keys from the left sidebar.
Click New SSH key.
In the "Title" field, you can enter something like "My PC SSH Key".
Paste the SSH key (copied in step 1) into the "Key" field.
Click Add SSH key.
Test the SSH connection:
After adding the key to GitHub, test the connection by running this command in PowerShell:
bash
ssh -T git@github.com
You should see a message like this:
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
4. Clone the repository using SSH:
Now you can clone the repository using the SSH URL:
bash
git clone git@github.com:your-username/your-repository.git
This should resolve the "Permission denied (publickey)" issue.