TIL

Today I Learned. 知ったこと、学んだことを書いていく

【GitHub】PullやPushでパスワードを聞かれないように設定する

~/.ssh/id_rsa(秘密鍵)と~/.ssh/id_rsa.pub(公開鍵)を作る

> ssh-keygen -t rsa

~/.ssh/id_rsa~/.ssh/id_rsa.pubが生成される

GitHubに登録する

Settings > SSH and GPG kers > SSH keys > New SSH key~/.ssh/id_rsa.pubの内容を貼り付ける

  • 接続の確認
> ssh -T git@github.com
Hi tamago324! You've successfully authenticated, but GitHub does not provide shell access.

ローカルリポジトリの設定を変更する

GitHubリポジトリClone or downloadUse SSHのテキストをコピーし、以下のコマンドを実行する

> git remote set-url origin xxxxxx

秘密鍵のパスを指定する( ~/.ssh/configの作成)

秘密鍵を以下のように生成した場合

> ssh-keygen -t rsa -f ~/.ssh/id_rsa_github

以下のような~/.ssh/configを作成する(全く同じ記述で作成する)

Host github github.com
    HostName github.com
    IdentityFile ~/.ssh/id_rsa_github
    User git

接続の確認

> ssh -T git@github.com
Hi tamago324! You've successfully authenticated, but GitHub does not provide shell access.

参考文献