SSH 完整操作流程

100 阅读1分钟
  1. 生成新的 SSH key:
ssh-keygen -t ed25519 -C "你的邮箱@example.com"
  1. 启动 ssh-agent:
eval "$(ssh-agent -s)"
  1. 添加 SSH key 到 ssh-agent:
ssh-add ~/.ssh/id_ed25519
  1. 复制公钥内容:
cat ~/.ssh/id_ed25519.pub
  1. 将公钥添加到你的 Git 仓库:
    • 打开 GitHub/GitLab 设置
    • 找到 "SSH and GPG keys"
    • 点击 "New SSH key"
    • 粘贴刚才复制的公钥内容
  2. 测试连接:
GitHub
ssh -T git@github.com

GitLab
ssh -T git@gitlab.com
  1. 配置仓库使用 SSH:
# 查看当前远程仓库
git remote -v

# 更改远程仓库地址为 SSH
git remote set-url origin git@github.com:用户名/仓库名.git

8.完成以上步骤后,你就可以通过 SSH 来推送代码了:

git add .
git commit -m "你的提交信息"
git push