git ssh配置问题

git clone 的两种方式

1、https方式

常见的命令:git clone https://github.com/18602435706/test.git

clone之后如果要push,一般需要输入账号密码,每次输入很麻烦,于是:

解决方案1:

修改 C:\Users\Administator\ .gitconfig 

[user]
 name = bossqiu  //你的用户名

 email = [email protected]  //你的git邮箱账号

[credential]
    helper = store

解决方案2:

git bash 输入 git config --global credential.helper store

2、ssh方式

常见的命令: git clone [email protected]:18602435706/test.git

注意:只有配置了ssh才能使用这种方式

配置方法:

1、按如下命令来生成 sshkey

ssh-keygen -t rsa -C "[email protected]"  // 后边是你的邮箱地址

这里的 [email protected] 只是生成的 sshkey 的名称,并不约束或要求具体命名为某个邮箱。
现网的大部分教程均讲解的使用邮箱生成,其一开始的初衷仅仅是为了便于辨识所以使用了邮箱。

2、通过查看 C:\Users\Administator/.ssh/id_rsa.pub 文件内容,获取到你的 public key

或者在git bash输入

cat ~/.ssh/id_rsa.pub

复制生成后的 ssh key,通过以下步骤 ,添加生成的 public key 添加到github中。

3、在git bash中输入 ssh -T [email protected]

首次使用需要确认并添加主机到本机SSH可信列表。若返回 Hi XXX! You've successfully authenticated, but Github.com does not provide shell access. 内容,则证明添加成功。

4、Git配置多个SSH-Key

当有多个git账号时,比如:

a. 一个gitee,用于公司内部的工作开发;
b. 一个github,用于自己进行一些开发活动;

1、生成一个公司用的SSH-Key

ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/gitee_id_rsa

2、生成一个github用的SSH-Key

ssh-keygen -t rsa -C '[email protected]' -f ~/.ssh/github_id_rsa

3、在 ~/.ssh 目录下新建一个config文件,添加如下内容(其中Host和HostName填写git服务器的域名,IdentityFile指定私钥的路径)

# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa

4、用ssh命令分别测试

ssh -T [email protected]
ssh -T [email protected]

这里以gitee为例,成功的话会返回下图内容

猜你喜欢

转载自blog.csdn.net/qq_41999592/article/details/108659139