Posts Tagged ‘Ruby’
Heroku publickey Problem Solved
I work on a Ruby on Rails app that is stored on git and deployed by Heroku. I’ve been added as a collaborator to the project, so I need to be able to pull from the repository to make changes. I’ve been working with subversion, so I’m used to using version control systems.
Right now, I’m coding on Ubuntu which I hope to write another post on someday. But right now I want to address a problem I came across when I tried do a git clone and pull from the repository.
Usually, I would run this command:
git clone -o heroku git@heroku.com:myapp.git
Note that instead of “myapp” I entered the actual name of my Heroku app. When I run this command, the files for this app would be copied over to my computer so I can develop and debug locally. However, I came up to this little bugger of a problem:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
I tried my best to find out what the exactly was wrong and any solutions, but the best I could come up with was that the SSH key was getting rejected. The closest I came to finding an answer was on this thread. Basically you had to generate an SSH key then add it to Heroku. All these steps I followed from the Heroku docs for managing keys. However, I was still getting the Permission denied error.
I had to do more research. Then I came across this troubleshooter for SSH from github. Of particular interest was their note on “Issues when using sudo:”
You shouldn’t run sudo git unless you have a very good reason. If you don’t know if you have a good reason to use sudo, it’s likely that you do not have one.
If you are using sudo with git commands (e.g. using sudo git clone because you are deploying to a root-owned folder), ensure that you also generated the key using sudo. Otherwise, you will have generated a key for your current user, but when you are doing sudo git, you are actually the root user – thus, the keys will not match.
Simply put, if you are using sudo git, then also use sudo ssh-keygen.
I then realized that I wasn’t running as root on my system. *FACEPALM*
Using this info, I just performed these steps:
1. Run command line:
sudo ssh-keygen -t rsa
2. Use the default location, and don’t enter any password. (Basically, press the Enter key three times.)
3. When that’s done, run command line:
sudo heroku keys:add /root/.ssh/id_rsa.pub
4. After the key is added, run command line:
sudo git clone -o heroku git@heroku.com:myapp.git
After that last command, it should then pull in all your Heroku application files for you to work with!
Hope this helps!


