この記事について
Windows PCから自分のGithubのレポジトリに変更を加えたく、環境を整備していました。途中でつまづきポイントがあったので、備忘録がてら整理しようと思います。
環境
OS: Windows 11
Windowsにgitを導入する。
Windowsにgitが入っていない人は下記のページを参考にして導入してください。
https://prog-8.com/docs/git-env-win
1. sshキーの生成
まずはsshキーを生成します。
$ ssh-keygen -t ed25519 -C "your e-mail address"
Overwriteするかどうか聞かれます。y
にしないと進めないので一旦y
にしました。将来何かトラブルが起きるかもしれませんがそれはそのときで。
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\sophytoeat/.ssh/id_ed25519):
C:\Users\sophytoeat/.ssh/id_ed25519 already exists.
Overwrite (y/n)? y
パスキーの設定を聞かれます。ここで何かパスキーを入力するとgit push
の度にパスキーを聞かれることになるので、セキュリティ上問題がなければパスキーを入力せずにエンターキーを押します。
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
2. 公開鍵の登録
公開鍵の表示とコピー
以下のコマンドで公開鍵が表示されるので、それを全てコピーする。
$ cat C:\Users\username\.ssh\id_ed25519.pub
3. sshキーの登録]
生成された公開鍵をクリップボードにコピー。
$ pbcopy < ~/.ssh/id_ed25519.pub
Githubにコピーした公開鍵を追加する
GitHubの「Settings(設定)」から「Deploy keys」を選択(Github pageのリポジトリでは「SSH and GPG keys」ではなく「Deploy keys」になっていた)し、「Add deploy key」をクリックします。
※この時に「Allow write access」にチェックを入れるのを忘れないように
4. ssh接続をテスト
$ ssh -T git@github.com
以下が表示されると成功。
Hi sophytoeat/sophytoeat.github.io! You've successfully authenticated, but GitHub does not provide shell access.
5. git pushまで
プッシュ先のリモートリポジトリを指定。URLはGitHubの作成したリポジトリ画面を開いて、 「HTTPS/SSH」と書かれたボタンの「SSH」を押してください。 git@github.com
から始まる1行をコピーして<URL>
の部分にペーストしてください。
$ git remote add origin <URL>
以下のコマンドを入力するとpushが出来るはずです。
$ git add .
$ git commit -m "test"
$ git push
参考文献
https://prog-8.com/docs/git-env-win
https://qiita.com/suke_qiita/items/0ce8b55d0b8af4258dc6