美文网首页
ssh 秘钥

ssh 秘钥

作者: 开心就好2008 | 来源:发表于2024-08-14 10:54 被阅读0次

生成 SSH 密钥

  1. 打开终端

    在 Mac 上,你可以按 Command + Space 并输入 "Terminal" 打开终端。

  2. 生成 SSH 密钥: 在终端中,输入以下命令来生成 SSH 密钥:

    `ssh-keygen -t ed25519 -C "your_email@example.com"` 

.
如果你使用的是较旧的系统,不支持 ed25519,你可以使用 rsa

    `ssh-keygen -t rsa -b 4096 -C "your_email@example.com"` 

将 `"your_email@example.com"` 替换为你在 GitHub 上注册的邮箱。
  1. 保存 SSH 密钥

    • 当提示 “Enter a file in which to save the key” 时,按 Enter 使用默认路径(通常是 ~/.ssh/id_ed25519~/.ssh/id_rsa)。
    • 当提示输入密码短语时,你可以选择输入密码来增加安全性,或者直接按 Enter 跳过。
  2. 添加 SSH 密钥到 SSH Agent

    在生成密钥后,运行以下命令来启动 SSH agent 并添加你的 SSH 密钥:

    `eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519` 

.
如果你使用 rsa,命令应为:

    `ssh-add ~/.ssh/id_rsa` 

2. 将 SSH 公钥添加到 GitHub

  1. 复制 SSH 公钥

    • 使用以下命令复制你的公钥内容到剪贴板:

      <pre>

      bash

      复制代码

      pbcopy < ~/.ssh/id_ed25519.pub

      </pre>

      如果你使用的是 rsa

      <pre>

      bash

      复制代码

      pbcopy < ~/.ssh/id_rsa.pub

      </pre>

  2. 登录 GitHub 并添加 SSH 密钥

    • 打开 GitHub 并登录你的账户。
    • 点击右上角的头像,然后选择 Settings
    • 在左侧栏中,点击 SSH and GPG keys
    • 点击 New SSH key 按钮。
    • 给你的密钥一个标题,然后在 Key 字段中粘贴你刚刚复制的公钥。
    • 点击 Add SSH key 按钮保存。

相关文章

网友评论

      本文标题:ssh 秘钥

      本文链接:https://www.haomeiwen.com/subject/rwhskjtx.html