0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

stepサーバーからcapistranoを使ってデプロイする際のssh(ed25519)のエラー

Posted at

前提

自分の職場ではstepサーバーからcapistranoのcapコマンドでデプロイをするという方法を取っているのだが、コマンド実行時にAuthenticationエラーが発生してしまった。

沼ったこと

stepサーバーとデプロイ先のステージングサーバー両方の~/.ssh/authorized_keysにed25519のsshキーを置いており、ローカル→step→ステージングへの認証はsshを使ってできている状況にもかかわらず以下のような認証エラーが起こってしまい、頭を抱えてしまった。。
(ステージングサーバーに普通に入ることはできる、つまり認証情報は渡せているのにcapistranoを使うとアクセスできないだと?!)

$ bundle exec cap staging deploy
=> SSHKit::Runner::ExecuteError: Exception while executing on host stg-web-02: Authentication failed for user ubuntu@ip

試したこと

・仮説
capistranoがサーバーに登録されているkeyとは異なるkeyを使ってしまっているのでは?
・実行したこと
以下を~/.ssh/configに追加

Host stg-web-02
  HostName ip
  User ubuntu
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes

※結局この記述はあってもなくてもできた。

・仮説
githubで使っているsshキーと違うものを使ってしまっているのではないか?
・結論
そもそもこのときは同じキーを使っていたし、後々異なるキー(githubではed25519、サーバー認証ではRSA)を使ってやってみたが問題なくできた。

解決

version

Capistrano Version: 3.18.1 (Rake Version: 13.2.1)
net-ssh (7.2.3, 7.2.1)

結論

上記のversionで行っていた為、ed25519は対応していると思い込んでいたのだが、capistranoでed25519を使う場合には以下のgemもインストールする必要があると分かった。(今回そのgemは入っていなかった)

gem 'ed25519'
gem 'bcrypt_pbkdf'

※net-ssh 5系以降対応

RSAにキーを変えると上手くいった!

終わりに

まだまだ駆け出しエンジニアの自分にとってSSH周りの知識が浅く一度沼にハマるとなかなか抜け出せないことがあります、、(苦)
早くサーバー、インフラ周りを一人前に扱えるようになりたいものです、、(笑)

今回の記事に関しまして、認識が間違っているところなどありましたらご指摘いただけると大変嬉しいです!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?