LoginSignup
0
0

More than 3 years have passed since last update.

【git ssh接続】〜複数のアカウントでgit ssh接続する方法〜

Posted at

暗号鍵の生成

# sshのセッティングディレクトリに移動
$cd ~/.ssh

# 暗号鍵を生成
$ ssh-keygen -t rsa
# Generating public/private rsa key pair.
# Enter file in which to save the key (/Users/(username)/.ssh/id_rsa): id_git_rsa
# Enter passphrase (empty for no passphrase):
# Enter same passphrase again:

GitHubへの公開鍵のアップロード

以下URLで公開鍵の設定
https://github.com/settings/ssh

「title」に公開鍵名、「key」に公開鍵の中身を入れる
image.png

ssh接続の設定

~/.ssh/conifg
Host github
  HostName github.com
  IdentityFile ~/.ssh/main_rsa
  User git
  Port 22
  TCPKeepAlive yes
  IdentitiesOnly yes

Host github-sub
  HostName github.com
  IdentityFile ~/.ssh/sub_rsa
  User git
  Port 22
  TCPKeepAlive yes
  IdentitiesOnly yes

github-subとgithubは任意
IdentityFileのファイル名も任意

githubへのssh接続確認

# ssh接続確認 (<HOST NAME>には「github-sub」などが入る)
$ ssh -T <HOST NAME>
# Hi ******! You've successfully authenticated, but GitHub does not provide shell access.

# git cloneを実行 (ssh用のURLをコピーし、HOST NAMEを書き換える)
$ git clone <HOST NAME>:******/******.git

参考

GitHubでssh接続する手順~公開鍵・秘密鍵の生成から~
https://qiita.com/shizuma/items/2b2f873a0034839e47ce
複数のgitアカウントを使用する場合
https://qiita.com/yamataku29/items/4744c9c70ad793c83b82

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