Git里的SSH key该如何使用?
PHP中文网
PHP中文网 2017-04-21 11:17:02
0
5
687

按照Github的帮助文档,将生成的SSH key添加到GitHub里了,通过下面的测试代码也返回成功了

ssh -T git@github.com

ssh key在登录服务器的时候可以不用每次输入用户名和密码,我以为git里也是提供这个功能,但是在命令行中提交私有仓库代码的时候,每次还是要输入用户名和密码,到底这key正确的使用方法是怎样的呢?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(5)
Ty80

Edit the .git/config file in the project directory

Found:

[remote "origin"]
    url =https://github.com/hit9/hit9.github.com.git
    fetch = +refs/heads/*:refs/remotes/origin/*

Change the url to the ssh address:

[remote "origin"]
    url =git@github.com:hit9/hit9.github.com.git
    fetch = +refs/heads/*:refs/remotes/origin/*

When the url is https, username authentication will be used. When it is an ssh address, ssh authentication will be used

伊谢尔伦

I encountered this problem before, so I just changed the remote address of the HTTPS protocol to SSH (git@github.com:name/code.git).
The SSH method and HTTPS method of the repository are different. On the surface, the URL information is different, but the actual authentication mechanism is also different. After the local key is established, there is actually no need to authenticate again when using ssh, while https requires entering a password each time.

洪涛

The password you need to enter should be the security policy implemented by github. The user name and password you enter are github’s username and password

阿神

You can modify it with the following command to change the HTTPS branch to the SSH branch. The effect is the same as modifying the .git/config file
git remote rm origingit remote rm origin
git remote add origin git@github.com:twlkyao/demo.git
git push origingit remote add origin git@github.com:twlkyao /demo.git

git push origin🎜
小葫芦

I also encountered this problem yesterday. I had to enter a password every time I submitted. Later, when I used ssh to clone, I couldn't enter the password. . .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template