ssh key 多用户配置
删除全局用户信息
多用户情况下,尽量不要设置全局用户信息
# 添加全局用户信息
git config --global user.name "用户名"
git config --global user.email "邮箱"
#删除全局用户信息
git config --global --unset user.name
git config --global --unset user.email
生成 key
$ ssh-keygen -t rsa -C "github@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_github
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in id_rsa_github.
Your public key has been saved in id_rsa_github.pub.
The key fingerprint is:
SHA256:K8ZzHA4rrhgHlv7qyP+dAmvpQIq+jPUpbMdjXZncAnE github@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| |
| . E |
| o |
| . . |
|.+ .oS+ |
|*. . . =*o. |
|++o.=.*.=. |
|*=**==o+. |
|=OBO=o.o |
+----[SHA256]-----+
将 key 添加至相应的网站
配置 config
文件位置
~/.ssh/config
注意:不可有注释
Host github.com
User github
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
Host 192.168.12.5
User gitlab
Hostname 192.168.12.5
Port 122 # 如果不是22则添加次行
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitlab
将密码加入密匙管理器
$ ssh-agent bash
$ ssh-add ~/.ssh/id_rsa_github
Enter passphrase for /c/Users/Administrator/.ssh/id_rsa_github:
Identity added: /c/Users/Administrator/.ssh/id_rsa_github (/c/Users/Administrator/.ssh/id_rsa_github)
$ ssh-add ~/.ssh/id_rsa_gitlab
Enter passphrase for /c/Users/Administrator/.ssh/id_rsa_gitlab:
使用细节
- clone 项目时, 最好使用
ssh
而不是https
- 由于删除了全局用户配置信息,所以每次 clone 之后都需要配置当前项目的用户名与邮箱
git config user.name "xxx"
git config user.emial "xxx"
使用 beyond compare 比较代码
参考
Ubuntu Git配置Beyond Compare为比较工具
配置
[diff]
tool = bc4
[difftool]
prompt = false
[difftool "bc4"]
cmd = /usr/bin/bcompare \"$LOCAL\" \"$REMOTE\"
[merge]
tool = bc4
[mergetool]
prompt = false
[mergetool "bc4"]
cmd = /usr/bin/bcompare \"$LOCAL\" \"$REMOTE\" \"-savetarget=$MERGED\"
trustexitcode = true
[alias]
d = difftool
m = mergetool
dd = difftool --dir-diff --no-symlinks
laolang@laolang-pc:~$ cat .gitconfig
[diff]
tool = bc4
[difftool]
prompt = false
[difftool "bc4"]
cmd = /usr/bin/bcompare \"$LOCAL\" \"$REMOTE\"
[merge]
tool = bc4
[mergetool]
prompt = false
[mergetool "bc4"]
cmd = /usr/bin/bcompare \"$LOCAL\" \"$REMOTE\" \"-savetarget=$MERGED\"
trustexitcode = true
[alias]
d = difftool
dc = difftool --cached
m = mergetool
dd = difftool --dir-diff --no-symlinks
ddc = difftool --dir-diff --no-symlinks --cached
使用说明
- git d 文件名 : 比较某个文件
- git dc 文件名 : 比较某个文件 (已暂存的)
- git dd : 比较文件夹
- git ddc : 比较文件夹 (已暂存的)