[Capistrano] How to deploy with SSH from Windows?

2,625 views
Skip to first unread message

Masuda

unread,
Mar 30, 2009, 4:52:03 AM3/30/09
to Capistrano
Hi,there.
I'm trying to deploy with Capistrano 2.5.5 and git.
But when using "cap deploy" command, server requires password for
Windows login user name, permission denied and tries to roll back.
I set ssh public key and deploy.rb with ssh_options.

Command prompt is below.
--------------------------------------------------------------------------------------------------------------------------------
C:\Users\WindowsLoginName\Project\project\src>cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote ssh://remote.host.address:22/var/git/project.git
HEAD"
WindowsL...@remote.host.address's password:
Permission denied, please try again.
WindowsL...@remote.host.address's password:
Permission denied, please try again.
WindowsL...@remote.host.address's password:
Permission denied (publickey,gssapi-with-mic,password).
fatal: The remote end hung up unexpectedly
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/project/releases/20090330082824; true"
servers: ["remote.host.address"]
Password:
[remote.host.address] executing command
command finished
--------------------------------------------------------------------------------------------------------------------------------

deploy.rb is below.
--------------------------------------------------------------------------------------------------------------------------------
set :application, "app"
set :repository,"ssh://remote.host.address:22/var/git/#
{application}.git"
set :deploy_to, "/var/www/#{application}"
set :scm, :git
set :user, "root"
set :runner, "root"
role :app, "remote.host.address"
role :web, "remote.host.address"
role :db, "remote.host.address", :primary => true
ssh_options[:keys] = %w(~/.ssh/id_rsa.pub)
ssh_options[:port] = 22
ssh_options[:forward_agent] = true
--------------------------------------------------------------------------------------------------------------------------------

I'm trying these 3days but I can't yet...
Please give me advice!!

I'm not good at english because I'm Japanese.
So, please be patient with me.
Regards.

Lee Hambley

unread,
Mar 30, 2009, 1:27:40 PM3/30/09
to capis...@googlegroups.com
Di you have an SSH key, and is it at %w(~/.ssh/id_rsa.pub) ?

What SSH client are you using ?

- Lee

2009/3/30 Masuda <msd...@gmail.com>

Masuda

unread,
Mar 30, 2009, 5:57:33 PM3/30/09
to Capistrano
Thanks for reply.

> Di you have an SSH key, and is it at %w(~/.ssh/id_rsa.pub) ?
Yes I have a SSH key but I made a mistake.
It is at "~/.ssh/authorized_key"
so I collected it %w(~/.ssh/authorized_keys).

> What SSH client are you using ?
I thought that no SSH client needed, so just command prompt only.
And then I did deploy command with Pagent.

Command prompt are below.
-----------------------------------------------------------------------------------------------------------------------------
C:\Users\WindowsLoginName\Project\project\src>cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote ssh://remote.host.address:22/var/git/project.git
HEAD"
WindowsL...@remote.host.address's password:
Permission denied, please try again.
WindowsL...@remote.host.address's password:
Permission denied, please try again.
WindowsL...@remote.host.address's password:
Permission denied (publickey,gssapi-with-mic,password).
fatal: The remote end hung up unexpectedly
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/project/releases/20090330213903; true"
servers: ["remote.host.address"]
** [deploy:update_code] exception while rolling back:
Capistrano::ConnectionError, connection failed for:
remote.host.address (TypeError: can't convert nil into String)
c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/recipes/
deploy/scm/git.rb:224:in `query_revision': Unable to resolve revision
for 'HEAD' on repository 'ssh://remote.host.address:22/var/git/si
s.git'. (RuntimeError)
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/
capistrano/recipes/deploy/scm/base.rb:35:in `send'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/
capistrano/recipes/deploy/scm/base.rb:35:in `method_missing'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/
capistrano/recipes/deploy/scm/base.rb:63:in `local'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/
capistrano/recipes/deploy/scm/base.rb:35:in `method_missing'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/
capistrano/recipes/deploy.rb:37:in `load'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/
capistrano/configuration/variables.rb:87:in `call'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/
capistrano/configuration/variables.rb:87:in `fetch'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/
capistrano/configuration/variables.rb:110:in `protect'
... 38 levels...
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/
capistrano/cli/execute.rb:14:in `execute'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/bin/cap:4
from c:/ruby/bin/cap:19:in `load'
from c:/ruby/bin/cap:19
-----------------------------------------------------------------------------------------------------------------------------

Password requirements without Windows login name, Password:,
disappeared.
But yet it requires password for Windows login user name and new
errors occurred.
I have no idea.

Lee Hambley

unread,
Mar 30, 2009, 6:10:09 PM3/30/09
to capis...@googlegroups.com
I'm not familiar with a windows installation, since Net::SSH is a pure-ruby implementation of an SSH client, there shouldn't be one required.... if you are deploying *to* windows that isn't going to work very well for you... looking at the logs, you aren't entering a valid password for the target computer, that is more of a configuration issue, if the remote host is Windows based, running an open SSH server, then you need to ensure you can SSH to it manually, you can read an example of how to test that using Net::SSH here: http://net-ssh.rubyforge.org/ssh/v2/api/index.html -

-- Lee

2009/3/30 Masuda <msd...@gmail.com>

Masuda

unread,
Mar 30, 2009, 10:55:02 PM3/30/09
to capis...@googlegroups.com
The server which I want to deploy is not windows.
It's Linux, CentOS 5.2 .

Now I realized that when I using command "cap deploy:setup"
it doesn't require password for Windows login user name but requires
root user password, not authorized public key.
Though it went well. I confirmed directories were made.

And comment out "set :scm, :git" for test, of course it couldn't
deploy well, but command finished and doesn't require password for
Windows login user name.

So, it seems that this problem occurs when using git, not Windows.
I found past similar problem.
http://www.mail-archive.com/capis...@googlegroups.com/msg05494.html
quote:
Both 'user' variables are set to 'rails-app-user' in deploy.rb:.
But Capistrano 2.5.3 keeps using my local username to log into the
server. [OS X Leopard, 10.5.5.]
This problem seems unsolved.

What should I do?

Masuda

unread,
Mar 31, 2009, 3:56:23 AM3/31/09
to capis...@googlegroups.com
I fixed the password problem.
It is caused using git without "PLink".

I re-installed Git (msysgit) "Use Plink" on Coosing SSH executable step.
Then, the problem which require password for Windows login user name fixed.

But ... access denied and got a fatal error.

Command prompt
---------------------------------------------------------------


>cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote
ssh://remote.host.address:22/var/git/project.git HEAD"

fatal: protocol error: bad line length character
Access denied
Access denied
Access denied
Access denied
Access denied
Access denied
FATAL ERROR: Server sent disconnect message
type 2 (protocol error):
"Too many authentication failures for "


*** [deploy:update_code] rolling back

* executing "rm -rf /var/www/project/releases/20090331074542; true"


** [deploy:update_code] exception while rolling back:

Capistrano::NoMatchingServersError, `deploy:update_code' is only run
for servers matching {:except=>{:no_release=>true}}, but no servers
matched
c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/recipes/deploy/scm/git.rb:224:in


`query_revision': Unable to resolve revision for 'HEAD' on repository
'ssh://remote.host.address:22/var/git/si
s.git'. (RuntimeError)

from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/recipes/deploy/scm/base.rb:35:in
`send'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/recipes/deploy/scm/base.rb:35:in
`method_missing'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/recipes/deploy/scm/base.rb:63:in
`local'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/recipes/deploy/scm/base.rb:35:in
`method_missing'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/recipes/deploy.rb:37:in
`load'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/configuration/variables.rb:87:in
`call'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/configuration/variables.rb:87:in
`fetch'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/configuration/variables.rb:110:in
`protect'
... 38 levels...
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/lib/capistrano/cli/execute.rb:14:in


`execute'
from c:/ruby/lib/ruby/gems/1.8/gems/capistrano-2.5.5/bin/cap:4
from c:/ruby/bin/cap:19:in `load'
from c:/ruby/bin/cap:19
---------------------------------------------------------------------------------

What's wrong?

Lee Hambley

unread,
Mar 31, 2009, 9:34:51 AM3/31/09
to capis...@googlegroups.com
your server has locked you out ? .. can you SSH in with a net-ssh test script ?

- Lee

2009/3/31 Masuda <msd...@gmail.com>

Vassilis Rizopoulos

unread,
Apr 1, 2009, 3:18:32 AM4/1/09
to capis...@googlegroups.com
Masuda wrote:
> Hi,there.
> I'm trying to deploy with Capistrano 2.5.5 and git.
> But when using "cap deploy" command, server requires password for
> Windows login user name, permission denied and tries to roll back.
> I set ssh public key and deploy.rb with ssh_options.
>
>
I guess you want to setup passwordless login from a windows computer to
any ssh server.
Here's how to go about it:

Get the id_rsa.* files for your keys and copy them to /Documents and
Settings/<username>/.ssh
Be advised that there is no way to create a .ssh (watch the '.' at the
start) from windows explorer, you will have to open a command window and
use mkdir.

The key in you id_rsa.pub should be added to the authorized keys file of
your server.
I initially had a bit of trouble getting cap to see the keys so I had to
add a couple of lines in my capfile. Also because it's for work I use a
different pair of keys than privately so I renamed the _rsa files:

ssh_options[:paranoid] = false
if File.exists?("#{ENV["USERPROFILE"]}/.ssh/other_rsa")
ssh_options[:keys] = "#{ENV["USERPROFILE"]}/.ssh/other_rsa"
end
ssh_options[:forward_agent] = true

Cheers,
V.-

--
http://www.braveworld.net/riva

Masuda

unread,
Apr 1, 2009, 7:51:55 AM4/1/09
to Capistrano
Thanks for replies.

Capistrano SSH key authentication seems to be going well, because cap
deploy:setup command was finished and I confirmed directories were
created.
Perhaps the problem is "git" SSH key authentication.
I had investigated by myself but not figured out yet how to config git
for SSH key authentication.

Lee Hambley

unread,
Apr 1, 2009, 7:53:30 AM4/1/09
to capis...@googlegroups.com
Where is your Git repository hosted?

- Lee

2009/4/1 Masuda <msd...@gmail.com>

Masuda

unread,
Apr 2, 2009, 3:45:27 AM4/2/09
to capis...@googlegroups.com
My Git repository is VPS,remote hosted.

I fixed the problem which got a message "Access denied".

It was deploy.rb and pageant which caused.
I did below.
1.deploy.rb


set :repository, "ssh://remote.host.address:22/var/git/#{application}.git"
 ↓

set :repository,
"ssh://ro...@remote.host.address:22/var/git/#{application}.git" #add
"root@"

2.I found that pagent does not save SSH keys, so added keys.

Then SSH key required and "Access denied" didn't show.


But... I got an another error "ssh_exchange_identification".

Command prompt messages are below.
-----------------------------------------------------------------------------------


>cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote

ssh://ro...@remote.host.address:22/var/git/project.git HEAD"
* executing "git clone -q
ssh://ro...@remote.host.address:22/var/git/project.git
/var/www/project/releases/20090402055505 && cd
/var/www/project/releases/20090402055505 && git checkout -q -b deploy
82594de76a1b6c43505
2a678e4aa13f52d93084a && rm -Rf
/var/www/project/releases/20090402055505/.git && (echo
82594de76a1b6c435052a678e4aa13f52d93084a >
/var/www/project/releases/20090402055505/REVISION)"
servers: ["remote.host.address"]
[remote.host.address] executing command
** [remote.host.address :: out] ssh_exchange_identification:
Connection closed by remote host #<This is the ploblem.
** [remote.host.address :: out] fatal: The remote end hung up unexpectedly
command finished


*** [deploy:update_code] rolling back

* executing "rm -rf /var/www/project/releases/20090402055505; true"
servers: ["remote.host.address"]


[remote.host.address] executing command
command finished

failed: "sh -c \"git clone -q
ssh://ro...@remote.host.address:22/var/git/project.git
/var/www/project/releases/20090402055505 && cd
/var/www/project/releases/20090402055505 && git checkout -q -b deploy
82594de76a1b6c435
052a678e4aa13f52d93084a && rm -Rf
/var/www/project/releases/20090402055505/.git && (echo
82594de76a1b6c435052a678e4aa13f52d93084a >
/var/www/project/releases/20090402055505/REVISION)\"" on
remote.host.address
-----------------------------------------------------------------------------------
It seemed to be concerned "/ect/hosts.allow" file,so I added my IP
addres for /ect/hosts.allow, but nothing changed.

Execute "git push origin master" finished without error, so git seems
to be authenticated fine.

Reply all
Reply to author
Forward
0 new messages