公司和github,常常会遇到要多用户使用git的状况,如下为配置信息,如下拿xiaoxuete1 & xiaofute2举例
ssh-keygen -t rsa -C "xiaofute1@mail.com"
新建config 文件,用来指定不一样的用户读取的rsa文件 // 注释部分须要删除
# Default user Host coding // host地址对应的别名,切换用户使用该名称 HostName xxx.xx.xx.xx // host地址 我这里填的是公司搭建的git仓库的ip地址 User xiaofute1 IdentityFile ~/.ssh/id_rsa_default // ssh-key文件地址 默认只会读取id_rsa # second user Host github HostName github.com User xiaofute2 IdentityFile ~/.ssh/id_rsa_github
// 这里就用到了配置文件中的host对应的字段 ssh -T git@github // 输出表示成功 Hi xiaofute2! You've successfully authenticated, but GitHub does not provide shell access.
验证过程当中出现 Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).git
删除 known_hosts 文件。执行如下命令github
ssh -T -v git@xxx.xx.xx.xx
git config --global user.name "xiaofute1" git config --global user.email "xiaofute1@mail.com"
本地仓库文件夹下配置用户名 会在当前仓库中提交试用该用户信息提交,覆盖全局的配置、
git config user.name "xiaofute2" git config user.email "xiaofute2@mail.com"
git init
后须要配置该本地仓库的用户信息