Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Error: Permission denied (publickey)

I'm not able to push my code in github.

I'm getting Error message :- $ git push origin master

Permission denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights.

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Have you uploaded your .ssh key to your Github account? If not, follow the steps in this Github help page

If the guide seems too confusing, you can download the Github client for Mac or Win. That way you can work with Github repo in a GUI interface, the app automatically setup everything properly for you behind the scene, and you can push code to Github repo with the press of a button.

Yes, I have uploaded my .SSH key.

But when I recheck my step , I found that I have miss this step during setup the .ssh key.

•ssh-agent:

ssh-add ~/.ssh/id_rsa

sudo apt-get install xclip

xclip -sel clip < ~/.ssh/id_rsa.pub

Do I need to generate again .ssh key.?

William Li
William Li
Courses Plus Student 26,868 Points

I'm not entirely sure here, it's been many years since I last generate a ssh key myself. But because the step you're missing is only about adding the ssh key to ssh-agent, my guess is that you don't need to generate a new key, just try re-do the step you missed.

Thnx for your help. Now i am able to push my file in github account.

by using:-

                  $git remote set-url origin https://My Directory/Project name.git

                  $git push origin master
William Li
William Li
Courses Plus Student 26,868 Points

so the problem was that the remote url wasn't set correctly in the first place?

Yes, I hope so.

I got a solution after an hour in tutorials. As u said, follow the step in the Github help page. and i was able to connect in every step.For some reason my origin got messed up without my realizing it, so i check my setting by using:

                                           $git remote -v

and set my Primary Remote Repository url that was:

              $git remote set-url origin https://github.com/Directory/my project name.git

After that i Push in Repository

                                        $git push origin master

And i check my updates by:

                                             $git pull