Multiple server deploy: asking ssh password for ea

2019-02-18 20:07发布

I'm setting up Capifony (Capistrano for symfony) but I've an issue with ssh password when testing multiple server deploy.

Here some versions:

daniel@fiji:~$ ruby --version
ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-linux]

daniel@fiji:~$ cap --version
Capistrano v2.9.0

daniel@fiji:~$ uname -a
Linux fiji 3.0.0-13-generic-pae #22-Ubuntu SMP Wed Nov 2 15:17:35 UTC 2011 i686 i686 i386 GNU/Linux

And some configurations from deploy.rb:

set :domain, "mydomain"
...
set :user, "sshuser"
set :password, "sshpassword"
...
role :web, domain
role :app, domain
...

Deploying to a single server works great, no need to enter passwords. All fine. But if I try to add more servers to the configuration (I'll need to deploy to 6 to 9 machines) with a configuration like this:

...
set :user, "sshuser"
set :password, "sshpassword"
role :web, "ipaddr1", "ipaddr2"
role :app, "ipaddr1", "ipaddr2"
...

Capistrano starts to ask me ssh password for each server listed even if it's set as before...what's wrong with this configuration? Entering the password lets the process continue and all works, but I'd like to avoid to enter the password every time.

Thanks Daniel

2条回答
家丑人穷心不美
2楼-- · 2019-02-18 20:38

I don't see why capistrano keeps asking for your password. However, one way to solve this issue is to use public key authentication, which is suggested in the capistrano wiki as well. (see this tutorial for an example of how to set this up)

In short:

  1. You generate a key using ssh-keygen -t rsa -C "youremail"
  2. You copy the public key to the remote host scp -p .ssh/id_rsa.pub remoteuser@remotehost:
  3. You add the public key to the authorized keys file on the server: cat id_rsa.pub >> ~/.ssh/authorized_keys. (You might need to create the .ssh dir)

After that you should only need to enter your password once and you won't need to have your password hardcoded in your deploy.rb file.

查看更多
淡お忘
3楼-- · 2019-02-18 20:38

According to more experienced users I can say that using password for ssh authentication is not a good practice. Far better using ssh keys and rely on them. Just need to remove the row

set :password, "sshpassword"

and obviously set up public keys on every server where to deploy.

查看更多
登录 后发表回答