Mac generate multiple accounts start ssh-agent service mode
- Generate a public key with multiple names
ssh-keygen -t rsa -C "[email protected]" # Generating public/private rsa key pair...# 三次回车即可生成 ssh key# 第一次回车修改默认密钥名称 比如: github.com
- Start the Ssh-agent service
$ eval "$(ssh-agent -s)"Agent pid 2429
- Add the newly added ssh-key to the Ssh-agent service
$ ssh-add ~/.ssh/github.comIdentity added: /Users/andyniu/.ssh/gitee.com (/Users/andyniu/.ssh/gitee.com)
This may be problematic when you close the terminal and may fail
Add Config file config
- Create config configuration file
$ touch ~/.ssh/config
Edit Config file
#该文件用于配置私钥对应的服务器#gitHub user([email protected]***.com) Host github.com HostName github.com User git #用户 IdentityFile ~/.ssh/id_rsa_github.com#######################################Add gitLab user([email protected]****.com) Host git.****.com HostName git.****.com User git IdentityFile ~/.ssh/id_rsa_***
- Verify
$ ssh -T [email protected]Hi username! You've successfully authenticated, but GitHub does not provide shell access.# 上面是github的成功返回语句,下面是gitlab的成功返回语句。$ ssh -T [email protected]Welcome to GitLab, username!
Add multiple git accounts to your Mac