Git共有三个级别的config文件,分别是system、global和local。global的在$home\.gitconfig
,local的在仓库目录下的.git\config
。这三个级别都分别配置了用户信息,当git commit
时,会依次从local、global、system里读取用户信息。所以,咱们利用local的配置来设置不一样的用户信息git
能够使用如下命令查看用户信息github
git config user.name git config user.email
在仓库目录下,使用如下命令设置local级别的用户信息,只对当前仓库生效bash
git config --local user.name LemonCat git config --local user.email lemoncat@***.com
使用如下命令生成秘钥。注意,须要指定目录及文件名,避免覆盖。-C后面的字符串为标识用,可自定义ssh
ssh-keygen -t rsa -b 4096 -f C:/Users/BeiTa/.ssh/github -C "lemoncat@***.com"
或者到用户目录下的.ssh文件夹内执行如下第一行命令,并在第三行提示时指定文件名ide
$ ssh-keygen -t rsa -b 4096 -C "lemoncat@***.com" Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/BeiTa/.ssh/id_rsa): 1 Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in 1. Your public key has been saved in 1.pub.
以github为例,依次点击Setting->SSH and GPB keys->New SSH Key
,复制粘贴生成的.pub文件中的秘钥3d
在用户目录下的.ssh文件夹下输入如下指令开启ssh代理代理
ssh-agent bash
继续输入如下命令添加秘钥code
$ ssh-add ~/.ssh/github
核对地址是否正确ip
Identity added: /c/Users/BeiTa/.ssh/github (/c/Users/BeiTa/.ssh/github)
在此目录下建立config文件,文件名没有后缀,加入如下配置字符串
Host alias User lemoncat HostName github.com IdentityFile ~/.ssh/github Host github.com User lemoncat2 HostName github.com IdentityFile ~/.ssh/id_rsa
Host
为别名,能够本身设置。设置后SSH地址git@github.com:lemoncat/test.git中的github.com须要替换成别名来使用,如git@alias:lemoncat/test.git
做者:脑壳Mini
连接:https://www.jianshu.com/p/0ad...
指定ssh秘钥的bat命令:
set rsa_path=operation/keygen/id_rsa git config core.sshCommand "ssh -i %rsa_path% "