ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
> 初始化仓库目的:把本地项目推送到github服务端,实现共享。 1、进入项目目录,执行以下命令,生成SSH_KEY ``` ssh-keygen -t rsa -b 4096 -C "你的邮箱" ``` ![](https://img.kancloud.cn/45/4c/454cc3fa5496438fcc536e11480e0252_496x482.png) <br> 2、创建密钥对成功后,SSH 公钥默认储存在账户的主目录下的 ~/.ssh 目录。可查看是否存在id_rsa和id_rsa.pub ![](https://img.kancloud.cn/71/dd/71dd37d24d811b04f79ccfb345596ba5_380x111.png) 3、cat id_rsa.pub 查看公钥 ![](https://img.kancloud.cn/79/55/7955f04ec9f7a06745945a00bd5889f2_960x105.png) 4、添加公钥到你的远程仓库(github或者gitee):复制公钥内容粘贴至远程仓库的公钥内容区域,标题自定义设置即可 ![](https://img.kancloud.cn/25/51/2551018c55da994e5281b8397bc7a041_1398x423.png) 5、修改git的remote url ``` // 使用命令 git remote -v 查看你当前的 remote url [root@localhost erp]# git remote -v origin https://gitee.com/cyclouds/ltd_shop.git (fetch) origin https://gitee.com/cyclouds/ltd_shop.git (push) // 进入远程仓库复制git ssh协议相应的url // 使用命令 git remote set-url进行修改 [root@localhost erp]# git remote set-url origin git@gitee.com:cyclouds/ltd_shop.git // 使用it remote -v 查看当前的 remote url是否已改变 [root@localhost erp]# git remote -v origin git@gitee.com:cyclouds/ltd_shop.git (fetch) origin git@gitee.com:cyclouds/ltd_shop.git (push) ``` 6、执行` ssh -T git@gitee.com`或者` ssh -T git@github.com`命令试ssh keys是否设置成功 ![](https://img.kancloud.cn/59/f1/59f1df8807c67ea3118749b8ed2a8ffb_628x119.png)