0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ssh key作成からGithubに認証リクエストを出すまで

0
Last updated at Posted at 2021-08-14

Githubにsshログインするときに結構躓いた部分について共有します。2021年8月13日からGithubはパスワード認証を廃止したとのことなので、sshでログインしてみました。

※筆者はMacを使用しています

既存のSSH keyの確認

まずはターミナルにアクセスして、既存のssh keyなどを確認

 $ ls -al ~/.ssh

実行例

```terminal -rw------- 1 username study 3389 Aug 14 11:16 something -rw-r--r-- 1 username study 751 Aug 14 11:16 something.pub ```

すでにssh keyを作成したことがある方は、このように出ると思います。

ssh keyの作成

以下のように聞かれるので、Passwordを入力するか、Enterを入力

Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

作成完了後、Macに秘密鍵を登録する

こうすることで、秘密鍵のパスフレーズの入力を省略可能

```terminal $ ssh-add ~/.ssh/'秘密鍵の場所' ```

Githubに公開鍵を登録する

以下のコマンドで公開鍵をクリップボードに貼り付ける

$ pbcopy < ~/.ssh/'ファイル名.pub' 

貼り付けた公開鍵を、GithubでSettings > SSH and GPG keys > New SSH key と進み、コピペする

Githubにsshで認証ログイン

最後に以下のコマンドで認証します

$ ssh -T git@github.com #sshでgithubに認証リクエストをだす

以下のように出れば認証成功です!

Hi 〇〇〇〇! You've successfully authenticated, but GitHub does not provide shell access.

備考

作成したssh keyが複数ある場合は、どれを利用するかconfigで設定できます
(参照先が間違っているとssh認証できません)

#登録したkeyを参照してもらうために、~/.ssh/configに以下のように追記
Host github.com
 User git
 Port 22
 HostName github.com
 IdentityFile ~/.ssh/'秘密鍵の場所'
 TCPKeepAlive yes
 PreferredAuthentications publickey
 IdentitiesOnly yes

参考文献

[新しいSSHキーを生成して ssh-agentに追加する] (https://docs.github.com/ja/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent)
[既存のSSHキーの確認] (https://docs.github.com/ja/github/authenticating-to-github/connecting-to-github-with-ssh/checking-for-existing-ssh-keys)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?