您的位置:首页 > 其它

git push不需要输入密码

2016-10-19 23:23 239 查看
使用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


4.登录到Github上,在settings设置下有一个SSH 栏目,进去把刚才生成的id_rsa.pub  (默认地址:C:\Users\您的用户名\.ssh)里的内容添加进去即可

5.到此就大功告成了,如果你换个机器,一样生成个SSH key添加一遍即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: