➜ ~ ssh-keygen -t rsa -b 4096 -C "个人邮箱" Generating public/private rsa key pair. Enter file in which to save the key (/Users/james/.ssh/id_rsa): /Users/james/.ssh/id_rsa_personal Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/james/.ssh/id_rsa_personal. Your public key has been saved in /Users/james/.ssh/id_rsa_personal_pub. The key fingerprint is: SHA256:O3KyKB6lj5GKCr3NMzCj+uqq2DLJQ1BiTrpUOT/MMmc jameshopbourn@gmail.com The key's randomart image is: +---[RSA 4096]----+ | . | |.o.+ | |=o. = | |oo o E | |o. * . S | |.o++ . | |+o*+ o + | |O=.Oo. = . | |/BB.=o. | +----[SHA256]-----+
➜ ~ ssh-keygen -t rsa -b 4096 -C "公司邮箱" Generating public/private rsa key pair. Enter file in which to save the key (/Users/james/.ssh/id_rsa): /Users/james/.ssh/id_rsa_company Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/james/.ssh/id_rsa_company. Your public key has been saved in /Users/james/.ssh/id_rsa_company_pub. The key fingerprint is: SHA256:O3KyKB6lj5GKCr3NMzCj+uqq2DLJQ1BiTrpUOT/MMmc jameshopbourn@protonmail.com The key's randomart image is: +---[RSA 4096]----+ | . | |.o.+ | |=o. = | |oo o E | |o. * . S | |.o++ . | |+o*+ o + | |O=.Oo. = . | |/BB.=o. | +----[SHA256]-----+
上传公钥到 GitHub
1 2 3
➜ ~ cat ~/.ssh/id_rsa_personal.pub|pbcopy
➜ ~ cat ~/.ssh/id_rsa_company.pub|pbcopy
连通性测试:
1 2 3 4
➜ ~ ssh -T personal Hi JamesHopbourn! You've successfully authenticated, but GitHub does not provide shell access. ➜ ~ ssh -T company Hi Username! You've successfully authenticated, but GitHub does not provide shell access.
vim ~/.ssh/config 然后复制以下内容到 config 文件
1 2 3 4 5 6 7 8 9 10 11
Host personal User git HostName github.com IdentityFile ~/.ssh/id_rsa_personal ProxyCommand nc -X 5 -x 127.0.0.1:6153 %h %p
Host company User git HostName github.com IdentityFile ~/.ssh/id_rsa_company ProxyCommand nc -X 5 -x 127.0.0.1:6153 %h %p