一、生成新的SSH密钥
二、添加新的SSH密钥
三、测试SSH连接
四、SSH密钥密码
五、创建新仓库并推送到GitHub
使用 SSH URL 将 git clone、git fetch、git pull 或 git push 执行到远程存储库时,
须在计算机上生成 SSH 密钥对,并将公钥添加到GitHub帐户
GitHub•GitHub文档•Get started•身份验证•使用SSH进行连接•生成新的SSH密钥并将其添加到ssh-agent
https://docs.github.com/zh/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
1.打开Git Bash

2.创建SSH密钥对
❶输入以下命令( your_email@example.com 替换成GitHub电子邮件地址)
ssh-keygen -t ed25519 -C "your_email@example.com" (备注:
如果系统不支持 Ed25519 算法,请使用以下命令
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" )
❷设置保存密钥的路径
❸设置SSH密钥密码(备注:空内容表示不设置SSH密钥密码)
❹再次确认SSH密钥密码
示例:

GitHub•GitHub文档•Get started•身份验证•使用SSH进行连接•添加新的SSH密钥
https://docs.github.com/zh/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
1.点击【头像】->点击【Settings】


2.点击【SSH and GPG keys】

点击 SSH keys 下的 【New SSH key】

3.添加SSH密钥:
(备注:

)
自定义标题;
粘贴公钥;
点击【Add SSH key】

GitHub•GitHub文档•Get started•身份验证•使用SSH进行连接•测试SSH连接
https://docs.github.com/zh/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection
1.打开Git Bash

2.输入以下命令
ssh -T git@github.com 示例:

(备注:
如果提示 "permission denied" ,查阅Error: Permission denied (publickey)
https://docs.github.com/zh/authentication/troubleshooting-ssh/error-permission-denied-publickey
)
GitHub•GitHub文档•Get started•身份验证•使用SSH进行连接•SSH密钥密码
https://docs.github.com/zh/authentication/connecting-to-github-with-ssh/working-with-ssh-key-passphrases
要添加额外的安全层,可以给SSH密钥添加密码
使用 SSH URL 将
git clone、git fetch、git pull或git push执行到远程存储库时,系统将提示输入密码,须提供SSH密钥密码
添加或更改密码的命令
$ ssh-keygen -p -f ~/.ssh/id_ed25519 通过该命令,可以更改私钥密码,而不用重新生成密钥对
添加或更改SSH密钥密码:
1.输入命令
2.(如果SSH密钥已有密码,提示输入该密码,然后才能更改为新密码)
3.设置SSH密钥密码(备注:空内容表示不设置SSH密钥密码)
4.再次输入SSH密钥密码
示例:

使用SSH URL执行 git push

GitHub•GitHub文档•Collaborative coding•存储库•创建和管理存储库•创建新仓库
https://docs.github.com/zh/repositories/creating-and-managing-repositories/creating-a-new-repository
Git•Documentation
https://git-scm.com/docs
1.在GitHub创建新仓库
❶进入GitHub
GitHub
https://github.com/❷点击【+】->点击【New repository】
❸自定义仓库名,自定义设置,点击【Create repository】

❹点击【SSH】

2.在本地初始化git仓库

3.将本地Git仓库与GitHub上的空仓库连接起来

示例:

创建仓库并推送到GitHub:
⑴将本地目录初始化为Git仓库
#切换到本地目录 cd /xxx/xxx/xxx #将本地目录初始化为Git仓库 $ git init #跟踪所有文件 $ git add . #提交(使用给定的作为提交消息) $ git commit -m ⑵将已存在的Git仓库推送到GitHub
#使用git remote add命令将远程URL(git@github.com:xxx)和默认远程名称(origin)相关联 $ git remote add origin git@github.com:xxx #重命名分支 $ git branch -M main #推送(首次推送) $ git push -u origin main 命令:
命令名称:git commit (记录仓库的修改)
参数:
❶ -m
使用给定的
作为提交消息。
命令名称:git remote (管理一组追踪的仓库)
语法:
❶ git remote add
参数:
❶ add
为
中的存储库添加一个名称为 的远程。
命令名称:git branch(列出、创建或删除分支)
参数:
❶ -M
`--move --force`的快捷方式。
❷ -m
--move
移动/重命名分支及其配置和引用日志。
❸ --force
结合
-m(或--move),允许重命名分支,即使新的分支名称已经存在。
命令名称:git push(与相关对象一起更新远程分支引用)
参数:
❶ -u
对于每一个已经更新或成功推送的分支,添加上游(跟踪)引用。