0

This is my first time using linode and uploading a Rails app to a VPS, so I might of skipped something obvious.

I followed two tutorials Ryan Bates video to deploying to a vps and David's answer on Stackoverflow

I am at the point where I want to deploy my rails app on Linode (Ubuntu 13.10)

When I execute the command bundle exec cap deploy:update

I get the errors that Linode cannot connect to github due to a public key

user:my-app User$ bundle exec cap deploy:update
  * 2014-02-12 17:19:46 executing `deploy:update'
 ** transaction: start
  * 2014-02-12 17:19:46 executing `deploy:update_code'
    updating the cached checkout on all servers
    executing locally: "git ls-remote git@github.com:user/my-app.git master"
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/user/apps/my-app/releases/20140212091953; true"
    servers: ["XXX.XXX.XX.XX"]
    [XXX.XXX.XX.XX] executing command
    command finished in 4607ms
Command git ls-remote git@github.com:user/my-app.git master returned status code pid 1529 exit 128

On my local machine I have no problem to commit and push my app on Github and I have RSA Keys on my local computer. It just asks me to login with my username and password each time I push my app.

On linode from the shell, I can connect to github by using ssh -vT git@github.com. I do have the RSA keys on the linode server and I added the ssh-agent using ssh-add

my deploy.rb

set :application, "my-app"
set :user, "user"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :keep_releases, 3
default_run_options[:pty] = true
set :scm, :git
set :repository, "git@github.com:user/#{application}.git"
set :ssh_options, { :forward_agent => true }
# ssh_options[:forward_agent] = true
set :branch, "master"

I am a bit at a loss.

EDIT: I have a private repository

Community
  • 1
  • 1
Zedrian
  • 909
  • 9
  • 29
  • have you tried this: http://stackoverflow.com/a/5485395/1120015 ? – Uri Agassi Feb 12 '14 at 11:16
  • Hello Uri, thanks for the response. I am pretty sure it is not a passphrase issue because in this test event, there isn't any passphrase. – Zedrian Feb 12 '14 at 18:44
  • OK. In your deploy.rb it says `set :repository, "git@github.com:user/#{application}.git"`. You renamed it to `user` for here right? In your actual deploy.rb, it is the real repository location... – Uri Agassi Feb 12 '14 at 20:10
  • yes I renamed it here on stackoverflow, the real username and app name are properly written in the cap file. I am thinking the issue is more github related than cap, but again I might be wrong. – Zedrian Feb 13 '14 at 03:58

2 Answers2

6

I just moved from Linux to Mac OSx. Thus, I have imported whole .ssh folder from linux to mac. While moving from linux to linux it worked, but to make it work on Mac, I had also to run:

ssh-add

That's the whole fix ;) See http://peteoliveira.com/deploying-with-capistrano-3-failing-permission-denied-publickey/ for more info.

jtompl
  • 1,034
  • 13
  • 16
3

So I found the solution to this github connection. I actually have another problem with the deployment where the bundle install fails. Anyways here is what I learned and I hope it will help others.

What you need to know:

  1. With Capistrano when you wish to push your public or private Github repository onto your VPS server, you need to make sure that BOTH your server and your computer has an SSH access with Github.
  2. Even if you can git push origin master it doesn't mean you have SSH access with Github. Here is how you troubleshoot:

A) Make sure you can SSH access from your computer

  1. Make sure you have Git installed on your machine Set up Git tutorial

  2. Make sure that you have an SSH Key on your local machine (with Linux or Mac)

    cd ~/.ssh then ls -a

    and look for the files id_rsa and id_rsa.pub

  3. If you don't have these rsa files, follow this tutorial Generating SSH keys

  4. Copy your SSH key

    pbcopy < ~/.ssh/id_rsa.pub # Copies the contents of the id_rsa.pub file to your clipboard

  5. Login with your browser on http://www.github.com and go to your_username -> edit profile -> settings -> ssh keys https://github.com/settings/ssh. Click the button Add keys, add the name that identifies your comptuter and paste the key code that you previously copied.

  6. Make sure you have SSH Agent on. In Terminal type

    ssh-add #enter a passphrase if you want to (recommended)

  7. Test if you can SSH with Github

    ssh git@github.com

The first time it may ask you to accept the connection. You should get the following response

PTY allocation request failed on channel 0
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

You can also make sure that your id_rsa is properly found by running

ssh -vT git@github.com
# make sure that this line is not -1 (it means it couldn't find the file)
=> debug1: identity file /Users/YOUR_USERNAME/.ssh/id_rsa type 1

Now you shouldn't have permission denied (Public Key)

B) Make sure you can SSH access from your server

  1. Run ssh root@your_server_ip_address if you didn't setup a user on your server or ssh username@your_server_ip_address. You will then be within the server shell and you want to repeat the same process for your computer.

NOTE: The server SSH Keys will be different than your computer. That means that on Github you need to add 2 SSH Keys, one for your computer and one for your server. That is why you need to repeat the process on both machines. Also to keep it simple, do not try to have more than one SSH Key on each machine.

NOTE 2: In your server after you generated your SSH key, to copy it run the command cat ~/.ssh/id_rsa.pub

Once both your computer and the server are accepted on Github, then you can update your rails app using capistrano and your Github repository. Yay!

Zedrian
  • 909
  • 9
  • 29