gitlab/github 设置 SSH

最近项目要部署到另一台机器上,故要重新 git clone 一下

一开始只是简单的设置 config 里的 user.name 和 user.email,以为就可以 clone(邮箱账户拥有项目的权限)

 

设置 config user.name 和 email 的方法

git config --global user.name "Your Username"

git config --global user.email "your.email@example.com"

  

查看设置的参数:

git config user.name

git config user.email

  

后面研究得知,需要配置 SSH 密钥,简单说来,需要本地生成一对 SSH key,将公钥放到 gitlab/github 上,本地留有私钥就行

步骤:

1. 填写你的邮箱

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

  

2. 运行之后会有提示消息,一直 Enter 就行,如果要区分多个 SSH,则需要添加能区分的名字

 3. 查看本地生成的 id_rsa.pub,如果是以 ssh-rsa 开头的,则是生成正确了

cat ~/.ssh/id_rsa.pub

  

 

4. 最后将 id_rsa.pub 的内容复制到 gitlab/github 的 SSH Keys 下

 

完成之后,再次 git clone git.xxx 就成功了

注意:此方法只适用于 ssh 的 clone 方法,也就是 git.xxx 这种链接,如果需要 clone http://xxx 这种链接,则需要设置 access token

参考文章:

posted @ 2023-11-23 11:10  strive-sun  阅读(91)  评论(0编辑  收藏  举报