配置SSH访问GitHub

经常切换账号与设备进行部署等操作,整理一下相关指令。

GitHub_SSH帮助文件

检查已存在的Key

1
$ ls -al ~/.ssh

生成一个新的SSH Key

  1. 生成

    1
    $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  2. 输入文件路径

    1
    2
    //直接回车即可,可重命名文件
    Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
  3. 输入密码

    1
    2
    3
    //直接回车即可
    Enter passphrase (empty for no passphrase): [Type a passphrase]
    Enter same passphrase again: [Type passphrase again]

添加SSH key到ssh-agent

  1. 确保ssh-agent可用

    1
    $ eval "$(ssh-agent -s)"
  2. 添加SSH key到ssh-agent

    1
    $ ssh-add ~/.ssh/id_rsa

将SSH key添加到GitHub账号

  1. 复制key

    1
    $ pbcopy < ~/.ssh/id_rsa.pub
  2. Setting/SSH and GPG keys/New SSH key

测试SSH连接

  1. 测试

    1
    ssh -T git@github.com
  2. 确认指纹

    1
    2
    3
    The authenticity of host 'github.com (192.30.252.1)' can't be established.
    RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
    Are you sure you want to continue connecting (yes/no)?
  3. 大功告成

    1
    2
    Hi username! You've successfully authenticated, but GitHub does not
    provide shell access.
文章目录
  1. 1. 检查已存在的Key
  2. 2. 生成一个新的SSH Key
  3. 3. 添加SSH key到ssh-agent
  4. 4. 将SSH key添加到GitHub账号
  5. 5. 测试SSH连接
|