mina-deploy / mina

Blazing fast deployer and server automation tool
https://rubygems.org/gems/mina
Other
4.35k stars 490 forks source link

Can't get SSH agent forwarding to work #484

Closed Frexuz closed 7 years ago

Frexuz commented 7 years ago

mina deploy always asks for my password when trying to ssh to the server.

local system's /etc/ssh/ssh_config

Host *
   ForwardAgent yes

server's /etc/ssh/sshd_config has

AllowAgentForwarding yes

A normal ssh SERVER-IP works fine. Trace:

ssh 100.100.100.100 -v
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 100.100.100.100 [100.100.100.100] port 22.
debug1: Connection established.
debug1: identity file /home/frexuz/.ssh/id_rsa type 1
debug1: identity file /home/frexuz/.ssh/id_rsa-cert type -1
debug1: identity file /home/frexuz/.ssh/id_dsa type -1
debug1: identity file /home/frexuz/.ssh/id_dsa-cert type -1
debug1: identity file /home/frexuz/.ssh/id_ecdsa type -1
debug1: identity file /home/frexuz/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/frexuz/.ssh/id_ed25519 type -1
debug1: identity file /home/frexuz/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA b2:67:04:e0:33:54:ec:3b:ec:52:17:d8:3b:02:fd:f8
debug1: Host '100.100.100.100' is known and matches the ECDSA host key.
debug1: Found key in /home/frexuz/.ssh/known_hosts:24
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/frexuz/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Authentication succeeded (publickey).
Authenticated to 100.100.100.100 ([100.100.100.100]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Requesting authentication agent forwarding.
debug1: Sending environment.
debug1: Sending env LC_IDENTIFICATION = en_US.UTF-8
debug1: Sending env LC_TIME = en_US.UTF-8
debug1: Sending env LC_NUMERIC = en_US.UTF-8
debug1: Sending env LC_PAPER = en_US.UTF-8
debug1: Sending env LC_MEASUREMENT = en_US.UTF-8
debug1: Sending env LC_ADDRESS = en_US.UTF-8
debug1: Sending env LC_MONETARY = en_US.UTF-8
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending env LC_NAME = en_US.UTF-8
debug1: Sending env LC_TELEPHONE = en_US.UTF-8
debug1: Sending env LC_CTYPE = en_US.UTF-8
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-101-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Sat Nov 19 10:45:10 2016 from 1-00-000-000.static.domain.com
frexuz@domain:~$ 

my deploy.rb with set :forward_agent, true

### MULTISTAGE SETUP
################################################################################

case ENV['to']
when 'production'
  set :stage, 'production'
else
  set :stage, 'staging'
end

set :app_name, 'test.com'
set :app_name_short, 'test'
set :deploy_to, "/var/www/#{fetch(:app_name)}/#{fetch(:stage)}"

### REQUIRE CORE STUFF
################################################################################

require 'mina/bundler'
require 'mina/rails'
require 'mina/git'
require 'mina/rbenv'
require 'highline/import' # ask for password
require_relative 'deploy/mina/helpers'

### SERVER
################################################################################

set :repository, 'git@github.com:frexuz/test.git'
set :branch, 'master'

set :domain, '100.x.x.x'
set :user, 'deployer'
set :forward_agent, true

set :app_root, "/var/www/#{fetch(:app_name)}"
set :template_path, "#{File.join('config', 'deploy', 'templates')}"

set :shared_dirs, fetch(:shared_dirs, []).push('log')
set :shared_files, ['config/database.yml', 'config/initializers/mail_settings.rb']

### REQUIRE EVERYTHING
################################################################################

require_glob("config/deploy/mina/*.rb")
require_glob("config/deploy/settings/*.rb")
require_glob("config/deploy/provisioning/*.rb")
require_glob("config/deploy/tasks/*.rb")

### MINA DEPLOY PROCEDURE
################################################################################

on :environment do
  on :before_hook do
    print_status("Using [#{color("#{fetch(:stage).capitalize}", 96)}]")
  end
end

desc "Deploys the current version to the server."
task deploy: :environment do
  on :before_hook do
    invoke :'slack:deploy:started'
  end

  deploy do
    invoke :'rbenv:load'
    invoke :'git:clone'
    invoke :'deploy:link_shared_paths'
    invoke :'bundle:install'
    invoke :'rails:db_migrate'
    invoke :'rails:assets_precompile'
    invoke :'deploy:cleanup'

    on :launch do
      # TODO: invoke :'puma:restart'
      # TODO: invoke :'sidekiq:start'
    end
  end

  on :after_hook do
    invoke :'slack:deploy:completed'
  end
end

mina (1.0.3)

what am i missing?

KjellMorgenstern commented 7 years ago

What does "doesn't work" mean? Are you getting an error message? Does it stall? Maybe try set :repository, 'ssh://git@github.com:frexuz/test.git' instead of set :repository, 'git@github.com:frexuz/test.git'

d4be4st commented 7 years ago

mina adds -A option flag to ssh connection

does your ssh -A SERVER_ID work fine?

Frexuz commented 7 years ago

Hey guys, I redid my whole setup and now it works. Seems it must have been something weird with my authorized keys. Sorry! :)