Gitosis and Capistrano: unable to chdir or not a git archive

Capistrano, Git, Ruby on Rails No Comments »

If you get this error:

unable to chdir or not a git archive
fatal: The remote end hung up unexpectedly

after running

cap deploy:cold

you might have to add the public key of the deploy user you set up with

set :user, “deploy”

in your capistrano deploy.rb file, to the /home/git/.ssh/authorized_keys on the REMOTE server.

Of course gitosis has a special process managing the keys and users from the LOCAL machine in the ~/gitosis/gitosis-admin directory, so you have copy the public key you generated for the deploy user on your REMOTE server via

ssh-keygen -t rsa

to your LOCAL machine (via scp or cut and paste into a new deploy.pub file from the ssh shell for example) and then proceed as outlined here (under “Adding Users”):

cd ~/gitosis/gitosis-admin
cp ~/deploy.pub keydir/
git add keydir/deploy.rb

Add the user credentials to the gitosis.conf file:

[group myrailsteam]
writable = myrailsapp
members = deploy

Finally run

git commit -a -m “Granted deploy user access rights to myrailsapp”
git push
 

Now the cap deploy:cold should work (with one fewer errors that is ).
 

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

“could not open channel” after cap deploy:setup

Capistrano, Ruby on Rails No 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]
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in