git 设置ssh无密码登录

使用git的时候每次都输入密码很是麻烦,所以通常的情况下采用SSH公匙登录。下面是配置SSH公匙登录的方法:

1、初次使用git的话要设置用户名和邮箱

$ git config --global user.name "***"
$ git config --global user.email "***@***.com"

2、生成公匙

$ ssh-keygen -t rsa -C "***@***.com"

如果不需要密码的就连续回车。
最后得到了两个文件:id_rsaid_rsa.pub。这两个文件一般放在~/.ssh目录下。

3、打开id_rsa.pub文件,将里面的内容复制到代码托管平台上

4、测试ssh是否生效

ssh -T git@git.coding.com #我采用的是coding代码托管平台,所以测试地址是git@git.coding.com,成功则出现:Hello name You've connected to Coding.net by SSH successfully!

5、将本地的https访问方式改为ssh方式,修改.git文件夹下config中的url

[remote "origin"]
    url = git@git.coding.net:test/test.git
    fetch = +refs/heads/*:refs/remotes/origin/*

修改后

[remote "origin"]
    url = git@git.coding.net:test/test.git
    fetch = +refs/heads/*:refs/remotes/origin/*  






原文地址:https://www.cnblogs.com/qmsu/p/5276244.html