0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Git でリモートリポジトリに SSH 接続する際に任意の秘密鍵を指定する

Last updated at Posted at 2024-10-15

やりたいこと

Git でリモートリポジトリに SSH 接続する際、デフォルトの秘密鍵 (~/.ssh/id_rsa~/.ssh/id_ed25519 など) ではなく任意の秘密鍵を指定したい。

方法

core.sshCommand を設定する。以下の例の ~/.ssh/id_ed25519.quanon を実際に指定したい秘密鍵のパスに置き換えること。

$ git ls-remote origin # リモートリポジトリにアクセスできない。
ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

$ git config --add --local core.sshCommand 'ssh -i ~/.ssh/id_ed25519.quanon'

$ git ls-remote origin # リモートリポジトリにアクセスできた!
694cd4a3eda71d53c4e2defe202eea345b0bbf40	HEAD
694cd4a3eda71d53c4e2defe202eea345b0bbf40	refs/heads/main

なおこの core.sshCommand の設定を削除したい場合は以下を実行する。

$ git config --unset --local core.sshCommand

参考

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?