• 为 GitHub 设置 SSH 密钥


    1. 起因

    给自己的 github 改个名,顺便就给原来 Hexo 对应的仓库也改了个名。然后发现 ub='hexo clean && hexo generate && hexo deploy' 失败了,报错如下:

    INFO  Deploying: git
    INFO  Clearing .deploy_git folder...
    INFO  Copying files from public folder...
    INFO  Copying files from extend dirs...
    [master 397fba4] Site updated: 2023-07-15 13:57:29
     173 files changed, 728 insertions(+), 559 deletions(-)
     create mode 100644 2023/07/15/Setting-Up-SSH-Keys-for-GitHub/index.html
    /Users/ritsu/.ssh/config line 4: no argument after keyword "k%u7h@j2s!wa"
    /Users/ritsu/.ssh/config: terminating, 1 bad configuration options
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    FATAL {
      err: Error: Spawn failed
          at ChildProcess.<anonymous> (/Users/ritsu/Study/Hexo/node_modules/hexo-util/lib/spawn.js:51:21)
          at ChildProcess.emit (node:events:512:28)
          at ChildProcess._handle.onexit (node:internal/child_process:293:12) {
        code: 128
      }
    } Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    划重点:Please make sure you have the correct access rights and the repository exists.

    好像我的 ssh 配置出问题了,想来那就重新配一遍吧,顺便记录下。

    2. 配置过程

    2.1 生成 SSH 密钥
    ssh-keygen -t ed25519 -C "your_email@example.com"
    
    • 1

    **注意:**如果您使用的是不支持Ed25519算法的遗留系统,请使用:

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    
    • 1
    > Enter a file in which to save the key (/Users/YOU/.ssh/id_ALGORITHM): [Press enter]
    > Enter passphrase (empty for no passphrase): [Type a passphrase]
    > Enter same passphrase again: [Type passphrase again]å
    
    • 1
    • 2
    • 3

    这时候在 ~/.ssh/ 下应该看到如下文件:

    image-20230715140759430

    2.2 将 SSH 密钥添加到 ssh-agent
    1. 在后台启动 ssh-agent

      $ eval "$(ssh-agent -s)"
      > Agent pid 51024
      
      • 1
      • 2
    2. 打开文件 ~/.ssh/config ,然后修改文件以包含以下行

      Host github.com
        AddKeysToAgent yes
        IdentityFile ~/.ssh/id_ed25519
      
      • 1
      • 2
      • 3
    3. 将 SSH 密钥添加到 ssh-agent

      ssh-add ~/.ssh/id_ed25519
      
      • 1
    2.3 将 SSH 公钥添加到 GitHub 上的帐户
    1. 将 SSH 公钥复制到剪贴板

      $ pbcopy < ~/.ssh/id_ed25519.pub
      
      • 1
    2. 在 GitHub 任何页面的右上角,点击头像,然后点击设置

      截屏2023-07-15 14.16.31
    3. 打开左侧的 SSH and GPG keys

      截屏2023-07-15 14.17.16
    4. New SSH key

      image-20230715141846805

      起个好听的名字,然后把第一步中复制的公钥粘贴进去

    2.4 恭喜🎉,快来测试下吧
    $ ssh -T git@github.com
    > Hi Kudoryafuka3! You've successfully authenticated, but GitHub does not provide shell access.
    
    • 1
    • 2

    3. 参考

    • https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
    • https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
  • 相关阅读:
    SpotBugs检查java代码:不应该依赖平台默认编码(DM_DEFAULT_ENCODING)
    树莓派进行导航时,定位问题
    Pr:导出设置之基本视频设置
    WebDAV之葫芦儿·派盘+i简记
    4. 死信队列
    安装最新版React devtool
    yolov5系列-[2]-数据标注、参数设置、训练优化
    基于Prometheus+Grafana搭建可视化监控服务 (一) Prometheus监控
    Spring注解驱动之@EnableAspectJAutoProxy注解
    # 杂谈偶感 × 基于QFD方法的质量屋构建
  • 原文地址:https://blog.csdn.net/weixin_45397995/article/details/131739938