SSH config for Git
If you don’t want to execute git command with password, you can do the following:
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/path/key1
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/path/key2
vi ~/.ssh/config
Note: you can distinguish different repository with custom Host, then you should replace HostName with Host.1 2 3 4 5 6 7 8 9 10 11
# github.com Host github.com HostName github.com User $username IdentityFile ~/path/key1 # gitlab.com Host gitlab.com HostName gitlab.com User $username IdentityFile ~/path/key2
- if you configure it in windows, maybe you need to configure the ssh-agent
1 2 3 4
$ eval "$(ssh-agent -s)" $ ssh-add ~/path/key1 $ ssh-add ~/path/key2 $ ssh-add -l # do this for ensure had add correctly
Now you can use git protocol without password. Just test as following:
|
|
Author Linfeng
LastMod 2023-09-01