此版本的 GitHub Enterprise 已停止服务 2021-09-23. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持

新增 SSH 密钥到 GitHub 帐户

要配置 GitHub Enterprise Server 帐户使用新的(或现有)SSH 密钥,您还需要将其添加到 GitHub Enterprise Server 帐户。

在新增 SSH 密钥到 GitHub Enterprise Server 帐户之前,您应该已:

在新增 SSH 密钥到 GitHub Enterprise Server 帐户后,您可以重新配置任何本地仓库使用 SSH。 更多信息请参阅“将远程 URL 从 HTTPS 转换为 SSH”。

Note: GitHub is improving security by dropping older, insecure key types.

DSA keys (ssh-dss) are no longer supported. Existing keys will continue to function through March 15, 2022. You cannot add new DSA keys to your user account on GitHub Enterprise Server.

RSA keys (ssh-rsa) with a valid_after before November 2, 2021 may continue to use any signature algorithm. RSA keys generated after that date must use a SHA-2 signature algorithm. Some older clients may need to be upgraded in order to use SHA-2 signatures.

  1. 将 SSH 公钥复制到剪贴板。

    如果您的 SSH 公钥文件与示例代码不同,请修改文件名以匹配您当前的设置。 在复制密钥时,请勿添加任何新行或空格。

    $ pbcopy < ~/.ssh/id_ed25519.pub
    # Copies the contents of the id_ed25519.pub file to your clipboard

    提示:如果 pbcopy 不可用,可找到隐藏的 .ssh 文件夹,在常用的文本编辑器中打开该文件,并将其复制到剪贴板。

  2. 在任何页面的右上角,单击您的个人资料照片,然后单击 Settings(设置)用户栏中的 Settings 图标

  3. 在用户设置侧边栏中,单击 SSH and GPG keys(SSH 和 GPG 密钥)身份验证密钥

  4. 单击 New SSH key(新 SSH 密钥)Add SSH key(添加 SSH 密钥)SSH 密钥按钮

  5. 在 "Title"(标题)字段中,为新密钥添加描述性标签。 例如,如果您使用的是个人 Mac,此密钥名称可能是 "Personal MacBook Air"。

  6. 将密钥粘贴到 "Key"(密钥)字段。 密钥字段

  7. 单击 Add SSH key(添加 SSH 密钥)添加密钥按钮

  8. 如有提示,请确认您的 GitHub Enterprise Server 密码。 Sudo 模式对话框

  1. 将 SSH 公钥复制到剪贴板。

    如果您的 SSH 公钥文件与示例代码不同,请修改文件名以匹配您当前的设置。 在复制密钥时,请勿添加任何新行或空格。

    $ clip < ~/.ssh/id_ed25519.pub
    # Copies the contents of the id_ed25519.pub file to your clipboard

    提示:如果 clip 不可用,可找到隐藏的 .ssh 文件夹,在常用的文本编辑器中打开该文件,并将其复制到剪贴板。

  2. 在任何页面的右上角,单击您的个人资料照片,然后单击 Settings(设置)用户栏中的 Settings 图标

  3. 在用户设置侧边栏中,单击 SSH and GPG keys(SSH 和 GPG 密钥)身份验证密钥

  4. 单击 New SSH key(新 SSH 密钥)Add SSH key(添加 SSH 密钥)SSH 密钥按钮

  5. 在 "Title"(标题)字段中,为新密钥添加描述性标签。 例如,如果您使用的是个人 Mac,此密钥名称可能是 "Personal MacBook Air"。

  6. 将密钥粘贴到 "Key"(密钥)字段。 密钥字段

  7. 单击 Add SSH key(添加 SSH 密钥)添加密钥按钮

  8. 如有提示,请确认您的 GitHub Enterprise Server 密码。 Sudo 模式对话框

  1. 将 SSH 公钥复制到剪贴板。

    如果您的 SSH 公钥文件与示例代码不同,请修改文件名以匹配您当前的设置。 在复制密钥时,请勿添加任何新行或空格。

    $ cat ~/.ssh/id_ed25519.pub
    # Then select and copy the contents of the id_ed25519.pub file
    # displayed in the terminal to your clipboard

    Tip: Alternatively, you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.

  2. 在任何页面的右上角,单击您的个人资料照片,然后单击 Settings(设置)用户栏中的 Settings 图标

  3. 在用户设置侧边栏中,单击 SSH and GPG keys(SSH 和 GPG 密钥)身份验证密钥

  4. 单击 New SSH key(新 SSH 密钥)Add SSH key(添加 SSH 密钥)SSH 密钥按钮

  5. 在 "Title"(标题)字段中,为新密钥添加描述性标签。 例如,如果您使用的是个人 Mac,此密钥名称可能是 "Personal MacBook Air"。

  6. 将密钥粘贴到 "Key"(密钥)字段。 密钥字段

  7. 单击 Add SSH key(添加 SSH 密钥)添加密钥按钮

  8. 如有提示,请确认您的 GitHub Enterprise Server 密码。 Sudo 模式对话框

To learn more about GitHub CLI, see "About GitHub CLI."

To add an SSH key to your GitHub account, use the ssh-key add subcommand, specifying your public key.

gh ssh-key add key-file

要包括新密钥的标题,请使用 -t--title 标记。

gh ssh-key add key-file --title "personal laptop"