生成SSH密钥
ssh-keygen -t rsa -C "youremail@xxx.com"
为避免覆盖原来的密钥,回车后输入密钥文件名称

GitHub新建SSH密钥
 输入title,粘贴公钥内容,然后点击“Add SSH key”即可。
公钥在上一步生产密钥的文件夹下,记得是.pub结尾的文件是公钥。


添加config文件
在.ssh/下创建config文件,内容如下
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Host zh4men9.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_zh4men9
Host后面的内容可以任意修改,我的为“zh4men9.github.com”,你可以修改为“abc.github.com”等等。
输入ssh -T git@zh4men9.github.com (如果你的Host为“abc.github.com”,那输入ssh -T git@abc.github.com ),如果显示如下内容,则表示配置成功了。

测试GitHub仓库
新建仓库(我建立了一个名为RLPaper1 的仓库)

然后在本地初始化仓库: git init 配置本地仓库用户和邮箱: git config --local user.name 'zh4men9' git config --local user.email 'zh4men9@163.com' 添加远程仓库: git remote add origin git@zh4men9.github.com:zh4men9/RLPaper1.git 通过git confit --lsit 查看配置好的内容

执行如下命令,添加新文件,然后push到远程仓库
echo 'this is my rep' > README.MD
git add README.MD
git commit README.MD -m 'update'
git branch -m master main
git push -u origin main
完整测试命令:
git init
git config --local user.name 'zh4men9'
git config --local user.email 'zh4men9@163.com'
git remote add origin git@zh4men9.github.com:zh4men9/RLPaper1.git
echo 'this is my rep.' > README.MD
git add README.MD
git commit README.MD -m 'update'
git branch -m master main
git push -u origin main

push成功。

|