クラウドの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
- Gitのサイトを開く(クラウド)
- 左上のユーザーアイコンをクリック(↓でいうと緑色の謎模様)
-
Title には登録するパソコンの名称を任意に決める(例:My Macbook)
-
Expires at はいつまで登録するかの期限なので無期限ならそのまま
-
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 ~~




