あじちゃんの備忘録。

〜ここはメモ帳です

GitへのSSH接続時の設定など

SSH接続を2方向にするやつ。当然だけど、設定後 clone は ssh を使うこと!

 

[秘密鍵の生成] ファイル名、私は個人のユーザ名(asahina-dev)とcompanyで分けている

$ ssh-keygen -t rsa -C "your_email@example.com" -f "{file_name}"

 

[公開鍵のコピー]

$ pbcopy < ~/.ssh/{file_name}.pub

 

[公開鍵を Git に設定]

https://github.com/settings/keys

ここで設定する。余分な改行とかスペースとか入らないように気をつける。

Titleは好きにして良い。わかりやすいもの。自分のPC名とかだとわかりやすいかも。

 

[権限] 

$ ls -l ~/.ssh/
-rw-------  asahina-dev
-rw-r--r--  asahina-dev.pub
-rw-r--r--  config
-rw-------  company
-rw-r--r--  company.pub
-rw-r--r--  known_hosts #これは接続すると自動で追加されるファイル

 

[~/.ssh下の構成]

/.ssh
|--asahina-dev
|--asahina-dev.pub
|--config
|--company
|--company.pub
|--known_hosts #これは接続すると自動で追加されるファイル

 

[~/.ssh/config] ホストがかぶる場合は github.com.hoge とかで名前を分けると良い分けた場合はcloneのときつけ忘れないよう注意

Host github.com
  HostName github.com
  User git
  Port 22
  IdentityFile ~/.ssh/asahina-dev
  TCPKeepAlive yes
  IdentitiesOnly yes
Host {会社のGitnoHost名}
  HostName {会社のGitnoHost名}
  User git
  IdentityFile ~/.ssh/company
  TCPKeepAlive yes
  IdentitiesOnly yes

 

[接続を試す]

$ ssh -vT git@{会社のGitnoHost名}
$ ssh -vT git@github.com

 

SSHのオプションはここを見るとわかりやすい

https://euske.github.io/openssh-jman/ssh.html