“could not open channel” after cap deploy:setup

Capistrano, Ruby on Rails Add comments

After extensive setup work to deploy your Ruby on Rails app with capistrano and after you put 

set :user, “deploy”

as a dedicated deploy user into your deploy.rb as many advise, you finally get to run

cap deploy:setup

Then this error stares back at you:

 servers: ["mydomain.com"]
*** [mydomain.com] could not open channel
    command finished
failed: nil on mydomain.com

Check you auth.log on your remote server

tail -f /var/log/auth.log

and look at the message:

Accepted publickey for myuser

This myuser, who lacks the necessary deployment permissions on your server, might be set in your ~/.ssh/config file, possibly after you set a custom port for ssh (sample custom port 30440 used from here on):

Host mydomain.com
User myuser
Port 30440

[…other settings…]

Some say this file (~/.ssh/config) is ignored by capistrano, but this does not seem to be the case, and capistrano will always make the ssh connection with the first user found in the ~/.ssh/config file, so it doesn’t help if you add

Host mydomain.com
User deploy
Port 30440
[…other settings…]

to the file or to add

set :admin_runner, “deploy

to your deploy.rb, rather you can have only

Host mydomain.com
User deploy
Port 30440
[…other settings…]

in your ~/.ssh/config file for this particular host if you want to specify the user here.

As a side note, capistrano has no problems connecting on a custom ssh port if you set

ssh_options[:port] = 30440

so it might be time to clean out your ~/.ssh/config file for the hosts you deploy to with capistrano.

Specifying the port however won’t work with gitosis and git, i.e. you can’t have

set :repository, “ssh://git@mydomain.com:30440/myrepository.git”

in your deploy.rb file, as it will throw a

ssh: mydomain.com:30440: Name or service not known

, likely because of a gitosis issue. As a workaround you might just put

Host mydomain.com
Port 30440

[…other settings but no user specified…]

without any user settings into your ~/.ssh/config file for this particular host, and you’ll (hopefully) be able to deploy via a custom port with gitosis and capistrano.

Hope it helps.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in