Github配置SSH Keys
Github配置SSH Keys

Github配置SSH Keys

  • 设置Git 的user name和email
  • 创建SSH Key
ssh-keygen -t rsa -C "<你的邮箱>"

系统提示输入文件保存位置等信息,默认连续敲三次回车即可获得定义密码和名字,生成的 SSH key 文件保存在中 ~/.ssh/id_rsa.pub

  • 获取Key
cat ~/.ssh/id_rsa.pub
  • 将终端拿到的ssh密钥复制添加到github上
这里写上注释
  • 利用 git remote set-url 将HTTPS协议换成SSH协议
git remote -v #先查看当前链接方式
> origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
> origin  https://github.com/USERNAME/REPOSITORY.git (push)

在github查看你的URL

选择SSH协议
  • 在终端输入
git remote set-url origin git@github.com:username/repository.git
  • 查看是否生效
git remote -v
# Verify new remote URL
> origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
> origin  git@github.com:USERNAME/REPOSITORY.git (push)

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注