SSH Keyを作成
1. SSH Keyを生成する
$ ssh-keygen -t ed25519 -C "メールアドレス"
-t : 鍵の種類を選択。安全面と性能面で最強なEd25519アルゴリズム -c:コメントを指定
実行結果
Generating public/private ed25519 key pair. Enter file in which to save the key (/Users/xxxx/.ssh/id_ed25519): //←これが出たらEnterキーを押す
『/Users/xxxx/.ssh/id_ed25519』はキーの保存先です。
2. パスワード入力
続いて下記の表示がされるのでSSH Keyを管理するためのパスワードを入力します。2回聞かれるので、2回入力。
Enter passphrase (empty for no passphrase): //※パスワードは入力しても画面に何も表示されません。
SSH KeyをGit Hubに登録
1. 生成した公開鍵をクリップボードにコピー
GitHubの設定画面に登録するためにクリップボードにコピーします。 この時のコマンドはOSによって異なります
//MacOCの場合 $ pbcopy < /Users/xxxx/.ssh/id_ed25519.pub
2. Git Hubの設定画面表示
右のMyアイコン > setting > 左メニュー『SSH and GPG keys 』 > SSH Keys『New SSH Key』
3. 公開鍵を貼り付ける
4.sshの鍵の読み込み分け設定 次に~/.ssh/configに読み分けの記載をします。configファイルがまだない場合は作成して保存
Host github HostName github.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_ed25519 UseKeychain yes AddKeysToAgent yes
正しく設定できたか確認
$ ssh -T git@github.com
実行結果
This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? //yes
実行結果
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts. Enter passphrase for key '/Users/xxxx/.ssh/id_ed25519': //SSH key生成時に設定したパスワード
さらに実行結果
Hi! You've successfully authenticated, but GitHub does not provide shell access.
上記のように出たら成功。 『Permission denied』と表示されたら失敗なので、もう一度手順通りに設定し直します。
今までDreamweaverからgithubに接続できなくなっていたのが、解決できました。
複数githunアカウント作成する場合は、SSH Keyももう一度作成する必要があります。
$ ssh-keygen -t ed25519 -C "メールアドレス" -f "作成したい鍵の名前"
~/.ssh/config
Host github HostName github.com User git PreferredAuthentications publickey IdentityFile ~/.ssh/id_ed25519 UseKeychain yes AddKeysToAgent yes Host github.com # 2つ目 HostName github.com User git Port 22 IdentityFile ~/.ssh/id_rsa_github_xxx #2つめの鍵の名前 TCPKeepAlive yes IdentitiesOnly yes
$ pbcopy < /Users/xxxx/.ssh/2つ目の鍵の名前.pub
github登録
正しく設定できたか確認
ssh -T git@github.com