enjoy life and code

Git 配置 SSH keys

生成 rsa key

打开PowerShell

#切换到当前用户目录
cd  $env:USERPROFILE
#添加.ssh文件夹
mkdir .ssh
cd .ssh

#生成 rsa 文件
ssh-keygen -t rsa -C "your@mail.com"
#填入文件名字会生成相应的文件名
#例如:rsa_github 会生成 rsa_github 和 rsa_github.pub

编写配置文件 config

添加配置文件同样是用户目录下的.ssh文件夹,添加config文件

cd  $env:USERPROFILE/.ssh
notepad config
Host github.com
    HostName github.com
    IdentityFile ~/ssh/rsa_github
    PreferredAuthentications publickey
    User yourname

Host gitee.com
    HostName gitlab.com
    IdentityFile ~/.ssh/rsa_gitlab
    PreferredAuthentications publickey
    User yourname

添加到Github并测试

ssh -T git@github.com

如果有需要接受 RSA key fingerprint,yes 接受。
然后正常情况应该像下面这样:

Hi alluLinger! You've successfully authenticated, but GitHub does not provide shell access.

Gitlab, Gitee 等同理

添加新评论