使用SSH key即可搞定
以github为例
1.首先,在github上创建一个repository,如上图:会有一个SSH ,复制它
2.如果以前https link进行推送的话,则需要先删除
git remote -v 查看使用的是https还是ssh
git remote rm origin
重新关联一下
git remote add origin +复制的SSH (git@github.com:chengandguo/abc.git 就是这样的格式)
3.如果本地没有创建SSH key的话
ls -al ~/.ssh 查看本地有无ssh key
没有就ssh-keygen 生成一个,一路回车即可
并按如下方法添加
Ensure ssh-agent is enabled:
If you are using Git Bash, turn on ssh-agent:
-
-
# start the ssh-agent in the background eval "$(ssh-agent -s)" Agent pid 59566
-
If you are using another terminal prompt, such as Git for Windows, turn on ssh-agent:
-
# start the ssh-agent in the background eval $(ssh-agent -s) Agent pid 59566
-
-
Add your SSH key to the ssh-agent. If you used an existing SSH key rather than generating a new SSH key, you'll need to replace id_rsa in the command with the name of your existing private key file.
$ ssh-add ~/.ssh/id_rsa
5.到此就大功告成了,如果你换个机器,一样生成个SSH key添加一遍即可