ゆるーい備忘録

まいにちべんきょう

gitコマンド使うときパスワードを聞かれないようにしたい

毎度毎度、githubのログインIDとパスワードを求められてしまうので今回の対応を行う

参考サイト

http://qiita.com/suthio/items/2760e4cff0e185fe2db9

http://qiita.com/0084ken/items/2e4e9ae44ec5e01328f1

鍵ペア作成

$ ssh-keygen -t rsa -b 4096 -C "XXXX@gmail.com" -f ~/github_key

-Cで鍵にコメントがつけられるので、メールアドレスを記入する パスフレーズは今回は使用しない

githubに公開鍵登録

クリップボードにコピーする

$ pbcopy < ~/github_key.pub

githubのaccountsのsettingsから、SSH and GPG keysを選択し ペーストする f:id:uchiharu_memo:20170523013219p:plain 赤丸のところ

sshのconfigを設定

$ vi ~/.ssh/config

以下を追記

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

設定は以上。 あとはリポジトリhttps://~になっているのをsshにしてあげれば完了!

$ git remote set-url origin {{SSHのリポジトリ}}