Я развертываю приложение ruby на рельсах с Capistrano. Работает нормально, но у меня есть проблема, связанная с s sh -агентом. Затем net-ssh
не проходит проверку подлинности.
, когда я печатаю значение ENV ['SSH_AUTH_SOCKET'] внутри моего ruby в журналах приложений rails, выполненных puma, я получаю следующее:
/tmp/ssh-wJBDegaQTF/agent.20252
Но этот файл не существует и net -s sh не удается:
ls -ld /tmp/ssh-*
drwx------ 2 deploy deploy 4096 févr. 26 21:50 /tmp/ssh-68VlKUx0U0
drwxr-xr-x 2 deploy deploy 4096 févr. 27 01:25 /tmp/ssh-agVZL13989
drwx------ 2 deploy deploy 4096 févr. 27 01:26 /tmp/ssh-gI2PL5GzWSYP
drwx------ 2 deploy deploy 4096 févr. 27 01:22 /tmp/ssh-ljKjGefBv5pq
drwx------ 2 deploy deploy 4096 févr. 27 01:25 /tmp/ssh-MRba1SdndgWH
drwx------ 2 deploy deploy 4096 févr. 27 01:08 /tmp/ssh-NT03p6Wnpeiv
drwx------ 2 deploy deploy 4096 févr. 25 22:08 /tmp/ssh-o4CJII5PVx
drwx------ 2 deploy deploy 4096 févr. 27 01:31 /tmp/ssh-UhktcutfMxJV
drwx------ 2 deploy deploy 4096 févr. 27 01:26 /tmp/ssh-VqPg9JEEvBpq
drwx------ 2 deploy deploy 4096 févr. 26 21:05 /tmp/ssh-VTIv4ZuG5zjk
drwx------ 2 deploy deploy 4096 févr. 27 01:26 /tmp/ssh-wvbVUbRNF95O
, тогда я получаю эту проблему, когда эта строка выполняется:
Net::SSH.start('192.168.0.1', 'root', keys: ['/home/deploy/.ssh/id_rsa'], port: 2002, verbose: :debug) { |ssh| ssh.exec!('ls') }
D, [2020-02-27T11:35:27.301451 #20998] DEBUG -- net.ssh.transport.session[128a4]: establishing connection to 192.168.0.100:2002
D, [2020-02-27T11:35:27.302142 #20998] DEBUG -- net.ssh.transport.session[128a4]: connection established
I, [2020-02-27T11:35:27.302282 #20998] INFO -- net.ssh.transport.server_version[128b8]: negotiating protocol version
D, [2020-02-27T11:35:27.302299 #20998] DEBUG -- net.ssh.transport.server_version[128b8]: local is `SSH-2.0-Ruby/Net::SSH_5.0.2 x86_64-linux'
D, [2020-02-27T11:35:27.309225 #20998] DEBUG -- net.ssh.transport.server_version[128b8]: remote is `SSH-2.0-OpenSSH_7.9p1 Debian-10+deb10u2'
I, [2020-02-27T11:35:27.309667 #20998] INFO -- net.ssh.transport.algorithms[128cc]: sending KEXINIT
D, [2020-02-27T11:35:27.309798 #20998] DEBUG -- socket[128e0]: queueing packet nr 0 type 20 len 1164
D, [2020-02-27T11:35:27.309847 #20998] DEBUG -- socket[128e0]: sent 1168 bytes
D, [2020-02-27T11:35:27.311354 #20998] DEBUG -- socket[128e0]: read 1080 bytes
D, [2020-02-27T11:35:27.311441 #20998] DEBUG -- socket[128e0]: received packet nr 0 type 20 len 1076
I, [2020-02-27T11:35:27.311469 #20998] INFO -- net.ssh.transport.algorithms[128cc]: got KEXINIT from server
I, [2020-02-27T11:35:27.311530 #20998] INFO -- net.ssh.transport.algorithms[128cc]: negotiating algorithms
D, [2020-02-27T11:35:27.311621 #20998] DEBUG -- net.ssh.transport.algorithms[128cc]: negotiated:
* kex: diffie-hellman-group14-sha1
* host_key: ecdsa-sha2-nistp256
* encryption_server: aes128-ctr
* encryption_client: aes128-ctr
* hmac_client: hmac-sha1
* hmac_server: hmac-sha1
* compression_client: none
* compression_server: none
* language_client:
* language_server:
D, [2020-02-27T11:35:27.311639 #20998] DEBUG -- net.ssh.transport.algorithms[128cc]: exchanging keys
D, [2020-02-27T11:35:27.317698 #20998] DEBUG -- socket[128e0]: queueing packet nr 1 type 30 len 268
D, [2020-02-27T11:35:27.317744 #20998] DEBUG -- socket[128e0]: sent 272 bytes
D, [2020-02-27T11:35:27.320892 #20998] DEBUG -- socket[128e0]: read 504 bytes
D, [2020-02-27T11:35:27.320931 #20998] DEBUG -- socket[128e0]: received packet nr 1 type 31 len 484
D, [2020-02-27T11:35:27.321766 #20998] DEBUG -- socket[128e0]: queueing packet nr 2 type 21 len 20
D, [2020-02-27T11:35:27.321814 #20998] DEBUG -- socket[128e0]: sent 24 bytes
D, [2020-02-27T11:35:27.321885 #20998] DEBUG -- socket[128e0]: received packet nr 2 type 21 len 12
D, [2020-02-27T11:35:27.322065 #20998] DEBUG -- net.ssh.authentication.session[128f4]: beginning authentication of `root'
D, [2020-02-27T11:35:27.322133 #20998] DEBUG -- socket[128e0]: queueing packet nr 3 type 5 len 28
D, [2020-02-27T11:35:27.322157 #20998] DEBUG -- socket[128e0]: sent 52 bytes
D, [2020-02-27T11:35:27.365167 #20998] DEBUG -- socket[128e0]: read 52 bytes
D, [2020-02-27T11:35:27.365242 #20998] DEBUG -- socket[128e0]: received packet nr 3 type 6 len 28
D, [2020-02-27T11:35:27.365302 #20998] DEBUG -- net.ssh.authentication.session[128f4]: trying none
D, [2020-02-27T11:35:27.365391 #20998] DEBUG -- socket[128e0]: queueing packet nr 4 type 50 len 44
D, [2020-02-27T11:35:27.365429 #20998] DEBUG -- socket[128e0]: sent 68 bytes
D, [2020-02-27T11:35:27.372915 #20998] DEBUG -- socket[128e0]: read 68 bytes
D, [2020-02-27T11:35:27.373110 #20998] DEBUG -- socket[128e0]: received packet nr 4 type 51 len 44
D, [2020-02-27T11:35:27.373172 #20998] DEBUG -- net.ssh.authentication.session[128f4]: allowed methods: publickey,password
D, [2020-02-27T11:35:27.373217 #20998] DEBUG -- net.ssh.authentication.methods.none[12908]: none failed
D, [2020-02-27T11:35:27.373249 #20998] DEBUG -- net.ssh.authentication.session[128f4]: trying publickey
D, [2020-02-27T11:35:27.373418 #20998] DEBUG -- net.ssh.authentication.agent[1291c]: connecting to ssh-agent
E, [2020-02-27T11:35:27.373487 #20998] ERROR -- net.ssh.authentication.agent[1291c]: could not connect to ssh-agent: No such file or directory - connect(2) for /tmp/ssh-wJBDegaQTF/agent.20252
если я запускаю ENV ['SSH_AUTH_SOCK'] на консоли с командой cap deploy rails:c
, файл хорошо создан.
> ENV['SSH_AUTH_SOCK']
=> "/tmp/ssh-mtQQDdCoPl/agent.3797"
$ ls -ld /tmp/ssh-mtQQDdCoPl/*
srwxr-xr-x 1 deploy deploy 0 févr. 27 15:33 /tmp/ssh-mtQQDdCoPl/agent.3797
ниже, мой deploy.rb
# frozen_string_literal: true
lock '~> 3.12.0'
set :application, 'my_app'
set :repo_url, 'git@github.com:patdec/my_app'
set :user, 'deploy'
set :puma_threads, [4, 16]
set :puma_workers, 0
set :deploy_to, '/home/my_app/www'
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
# Default #
# set :format, :airbrussh
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto
# set :pty, true
# set :keep_releases, 5
append :linked_files, 'config/database.yml', '.env.production'
append :linked_dirs, 'log',
'tmp/pids',
'tmp/cache',
'tmp/sockets',
'public/packs',
'node_modules'
set :rails_env, :production
server 'x.x.x.x',
port: 2002,
user: 'deploy',
roles: %w[app db web]
set :ssh_options,
forward_agent: true,
user: fetch(:user),
keys: %w[~/.ssh/id_rsa.pub]
set :sidekiq_user, fetch(:user)
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not
# using ActiveRecord
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
before 'deploy:assets:precompile', 'deploy:yarn_install'
namespace :deploy do
desc 'Run rake yarn install'
task :yarn_install do
on roles(:web) do
within release_path do
execute("cd #{release_path} && yarn install " \
'--silent --no-progress --no-audit --no-optional')
end
end
end
end
namespace :deploy do
desc 'Runs rake db:seed'
task seed: [:set_rails_env] do
on primary fetch(:migration_role) do
within release_path do
with rails_env: fetch(:rails_env) do
execute :rake, 'db:seed'
end
end
end
end
end