cd ~/.ssh ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
替換正確的郵箱,按entergit
Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/FlyingHorse/.ssh/id_rsa): id_rsa.gitee
建立gitee的ssh key時輸入id_rsa.gitee,建立github的ssh key時輸入id_rsa.githubgithub
Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in id_rsa.gitee. Your public key has been saved in id_rsa.gitee.pub. The key fingerprint is: SHA256:lmjU8A4k+r6liYJmENBPM/7Frx3XDg98VeWvIQ9dLyw xxxxx@xxxxx.com The key's randomart image is: +---[RSA 2048]----+ | . . o o| |. ..+o + ..| |. .+ oo.o +| |. .o. +o. o .+| | . ..o.S. .E.=.o| |. . ... o ==o+ | |o . . o o *o | |oo . = . . o | |o.. + | +----[SHA256]-----+
一路按enter,知道輸出如圖shell
cat id_rsa.gitee.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDZbvgUEj3XAXH4HkW27ibdXgV6VHdrA9/WdSDHtiiC55mjPvxj3OtPxIbpeJmhWyHiJWR6 uUuK+gkb//O51uWCPhHqxKR7+45tZ9jHqXW+hEKPp+odQgc+3hiHAjTkn3JGeIJlQp2UdJCDHBrp+kcgVeg91+y7cU3ufaUQ/hpD rCgn6uvwjwJgnDhV9DYi+gFUFe7LUwa1o4nfwg43ycuOOuT7c6VO2dj/0pLRUVTPQYu/C3kaaPVedir7mKIu/dM6Ec44bhYTp1Dq qp8BO42Cfo+n+dempqYTe2wcPvuDjSj884IATc/KvBfc86Yd2Uj7NI7li90Y3i6adoxUIWQh xxxxx@xxxxx.com
查看公鑰,gitee輸入id_rsa.gitee.pub,github輸入id_rsa.github.pubbash
將第二行到結尾的內容複製到gitee或github的ssh中保存dom
在.ssh文件夾中建立config文件,添加如下內容以區分兩個ssh keyssh
# gitee Host gitee.com HostName gitee.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa.gitee # github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa.github
輸入ide
ssh -T git@gitee.com
若返回以下圖,則gitee則鏈接正常測試
Welcome to Gitee.com, yourname!
輸入spa
ssh -T git@github.com
若返回以下圖,則github則鏈接正常code
Hi yourname! You've successfully authenticated, but GitHub does not provide shell access.