- 生成一个新的SSH密钥:(windows需要进入Git Bash/cmd/ps)
ssh-keygen -t rsa -C "username@email.com"
- 启动 ssh-agent:
Windows:
eval $(ssh-agent -s)
Linux:
eval `ssh-agent -s`
- 将SSH私钥添加到 ssh-agent:
Windows:
ssh-add /c/Users/username/.ssh/id_rsa
Linux:
ssh-add ~/.ssh/id_rsa
- 复制SSH公钥的完整内容
Windows:
clip < /c/Users/username/.ssh/id_rsa.pub
Linux:
cat ~/.ssh/id_rsa.pub
- 进入GitHub的设置页面, SSH keys, add
- 测试连接:
ssh -T git@github.com
-
git clone SSH repo address
请注意 选择clone的地址必须是SSH地址(repo页面有) 而不是HTTPS地址 -
modify from https to ssh:
若你之前用的https地址, 可以用下面的命令改成ssh地址:
git remote set-url origin git@github.com:org_name/repo_name.git
网友评论