以gitlab和github为例子
1. 生成rsa
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
根据要上传的仓库对rsa文件命名,如github,则rsa为id_rsa_github, gitlab,则rsa为id_rsa_gitlab
2. 编写config文件
进入C:\Users\【用户名】\.ssh 文件夹下
新建config,注意不是.txt文件,就是config文件名
# gitlab
Host 192.168.31.xxx #远程Git项目主机IP
HostName 192.168.31.xxx
Port 9998 #远程项目主机port
PreferredAuthentications publickey
IdentityFile C:\Users\hy\.ssh\id_rsa
User hu***
# github
Port 443
Host github.com #远程Git项目主机IP
HostName ssh.github.com
PreferredAuthentications publickey
IdentityFile C:\Users\hy\.ssh\id_rsa_github
User hu***
2021年8月13后,github 拉取,提交等操作都无法使用username+password方法直接使用,转而使用username+token的方式,否则报如下错误
remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for
方法就是申请一个token,地址:https://github.com/settings/apps
生成成功后会有一个token,在进行git操作时,使用username+password(token)就行
如果你拉取私有仓库的代码,需要使用到token,用法如下:
git clone https://[token]@github.com/huyu456/happy_buy.git
评论列表
已有0条评论