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?

Git_SSH設定_ローカルとクラウドの両立

Posted at

クラウドのGitlabとローカルネットワークのGitLab、どちらもSSHキーの設定をしたらSSHで接続できなくなったので正確な設定方法を残しておく。

手順

・キーの作成

# クラウドGitLab用
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_gitlab_cloud -C "your_email@example.com"

# ローカルGitLab用
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_gitlab_local -C "your_email@example.com"

各Gitlabに公開鍵を登録

例としてクラウド側の設定を残しておく。同じようにローカル側も実施。

以下コマンドで、ファイルを開き中身をコピーする

sudo gedit ~/.ssh/id_ed25519_gitlab_cloud.pub
  1. Gitのサイトを開く(クラウド)
  2. 左上のユーザーアイコンをクリック(↓でいうと緑色の謎模様)

Screenshot from 2025-10-10 09-23-05.png

  1. Edit profile
    Screenshot from 2025-10-10 09-25-31.png

  2. 左のタブの SSH Keys
    Screenshot from 2025-10-10 09-27-13.png

5.「Add new key」
Screenshot from 2025-10-10 09-28-32.png

  1. Keyという大きい空白欄にコピーしたものを貼り付ける
    Screenshot from 2025-10-10 09-29-01.png

  2. Title には登録するパソコンの名称を任意に決める(例:My Macbook)

  3. Expires at はいつまで登録するかの期限なので無期限ならそのまま

  4. Add keyで登録完了

ローカル側も以下コマンドで中身をコピーし同様に設定する

sudo gedit ~/.ssh/id_ed25519_gitlab_local.pub

SSHファイルの編集

下記コマンドでconfig開いて

sudo gedit ~/.ssh/config
# nanoとかでもいい

下記のように編集。保存してファイル閉じる。

# クラウドGitLab(gitlab.com)
Host gitlab.com
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_ed25519_gitlab_cloud
  IdentitiesOnly yes

# ローカルGitLab(例:gitlab.local または 192.168.1.10)
Host gitlab.local
  HostName 192.168.1.10 # ローカルのIPにしとく
  User git
  IdentityFile ~/.ssh/id_ed25519_gitlab_local
  IdentitiesOnly yes

接続できるかの確認は以下で出来る

ssh -T git@gitlab.com
# Welcome to ~~
ssh -T git@gitlab.local # IPのほうが確実かも。どっちでもいいはず
# Welcome to ~~
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?