git push不需要輸入密碼
阿新 • • 發佈:2019-02-20
使用SSH key即可搞定
以github為例
1.首先,在github上建立一個repository,如上圖:會有一個SSH ,複製它
2.如果以前https link進行推送的話,則需要先刪除
git remote -v 檢視使用的是https還是ssh
git remote rm origin
重新關聯一下
git remote add origin +複製的SSH ([email protected]: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)
-
-
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新增一遍即可