なぜ?
Github は公式に、Git アクセスのパスワード認証を停止していくと宣言したためです。
曰く 2021/8/13 にパスワード認証を廃止するとの事です。
August 13, 2021 – Token (or SSH key) authentication will be required for all authenticated Git operations.
やり方
Windows に git をインストールした場合、「Git bash」がインストールされています。
Mac/Linux はターミナル開けば ok
起動したら $ ssh-keygen -o
を叩けばやれます
azale@LAPTOP-T5MQIJ18 MINGW64 ~ $ ssh-keygen -o Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/azale/.ssh/id_rsa): Created directory '/c/Users/azale/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/azale/.ssh/id_rsa Your public key has been saved in /c/Users/azale/.ssh/id_rsa.pub The key fingerprint is: SHA256:XhR0d0uB6se0C+n9YGJB4mJOktzVqlq74u/+wZg29Zk azale@LAPTOP-T5MQIJ18 The key's randomart image is: +---[RSA 3072]----+ | .o . ooo| | .o o...| | o.o. . | | . o o.+. . | | + =S+o.+ . | | =.B..+++ | | O.o.E+o. | | .+ o o.oo. | | .o=*o. .. | +----[SHA256]-----+
すると、~/.ssh/id_rsa.pub
が生成されます。これが ssh 公開鍵です。
そしたらこの中身を開いてコピーします。
$ cat .ssh/id_rsa.pub ~省略(見せられないよ~)~
Windows だと必要ないかもだけど、chmod 600 ~/.ssh/id_rsa
もやっておいて、ほかのユーザから参照できないようにしませう。
github に登録
次のリンクから、「New SSH Key」を指定します。
https://github.com/settings/keys
コピった内容を貼り付けで OK です。
ssh config の生成
そしてホームディレクトリに .ssh
ディレクトリができているので、.ssh/config
を追加しましょう。
個人的には vi 使いますが、まぁお好きに。
Host github HostName github.com IdentityFile ~/.ssh/id_rsa User git
ここまで書いたら保存。
接続確認でござる
$ ssh github The authenticity of host 'github.com (52.192.72.89)' can't be established. RSA key fingerprint is SHA256:... 中略 Hi Sunao-Yoshii! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
successfully authenticated,
と出ていれば設定は成功です。