赞
踩
- 本文以为Azure Devlop的平台为例子操作三种获取Git权限的办法
- Github、Gitlab、Gitee、Gitcode等平台操作类似
- 主要是便于理解获取Git权限的几种采用方式
- Git工具安装时,如果没有特别勾选不安装SSH,默认是Git安装好之后是会携带了SSH工具
- 本文以git clone指令拉取代码为例子,当没有权限获取项目时,会出现类似错误:
R7000@DESKTOP-30AFPHP MINGW64 /d/Workspace/Py/gitest $ git clone https://XXXX8009@dev.azure.com/XXXX8009/GitTestProject/_git/GitTestProject Cloning into 'GitTestProject'... fatal: User canceled authentication. error: unable to read askpass response from 'D:/Git/mingw64/bin/git-askpass.exe' Password for 'https://XXXX8009@dev.azure.com/XXXX8009/GitTestProject/_git/GitTestProject': fatal: Authentication failed for 'https://dev.azure.com/XXXX8009/GitTestProject/_git/GitTestProject/' R7000@DESKTOP-30AFPHP MINGW64 /d/Workspace/Py/gitest $ git clone git@ssh.dev.azure.com:v3/XXXX8009/GitTestProject/GitTestProject Cloning into 'GitTestProject'... Load key "/c/Users/R7000/.ssh/id_rsa": invalid format git@ssh.dev.azure.com's password: Permission denied, please try again. git@ssh.dev.azure.com's password: Permission denied, please try again. git@ssh.dev.azure.com's password: git@ssh.dev.azure.com: Permission denied (password,publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
fatal: User canceled authentication.
但是用户名和密码是可以使用的R7000@DESKTOP-30AFPHP MINGW64 /d/Workspace/Py/gitest
$ git clone https://XXXX8009@dev.azure.com/XXXX8009/GitTestProject/_git/GitTestProject
Cloning into 'GitTestProject'...
fatal: User canceled authentication.
remote: Azure Repos
remote: Found 22 objects to send. (2 ms)
Unpacking objects: 100% (22/22), 5.62 KiB | 122.00 KiB/s, done.
R7000@DESKTOP-30AFPHP MINGW64 /d/Workspace/Py/gitest/GitTestProject (main)
$ git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
.git
文件夹查看config
文件[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = https://XXXX8009@dev.azure.com/XXXX8009/GitTestProject/_git/GitTestProject
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
Personal access token
按钮 创建tokenNew token
https://XXXX8009@dev.azure.com/XXXX8009/GitTestProject/_git/GitTestProject
现在的为https://XXXXXXXXXXXXXXXX7pgv6xxfeigim7ygw3lydz4xbpo7vyy2q@dev.azure.com/XXXX8009/GitTestProject/_git/GitTestProject
R7000@DESKTOP-30AFPHP MINGW64 /d/Workspace/Py/gitest
$ git clone https://XXXXXXXXXXXXXXXX7pgv6xxfeigim7ygw3lydz4xbpo7vyy2q@dev.azure.com/XXXX8009/GitTestProject/_git/GitTestProject
Cloning into 'GitTestProject'...
remote: Azure Repos
remote: Found 22 objects to send. (19 ms)
Unpacking objects: 100% (22/22), 5.62 KiB | 85.00 KiB/s, done.
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = https://XXXXXXXXXXXXXXXX7pgv6xxfeigim7ygw3lydz4xbpo7vyy2q@dev.azure.com/XXXX8009/GitTestProject/_git/GitTestProject
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
ssh-keygen -t rsa
,为了方便,提示选项可以enter键跳过,最后生成文件在C盘用户目录的.ssh文件夹下
,如这里的/c/Users/R7000/.ssh/
,其中.pub
为公钥$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/R7000/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/R7000/.ssh/id_rsa Your public key has been saved in /c/Users/R7000/.ssh/id_rsa.pub The key fingerprint is: SHA256:QevS8lBgx8OihC4ipYP+4fmg1vBuH9DrXTuzqRHmq2A R7000@DESKTOP-30AFPHP The key's randomart image is: +---[RSA 3072]----+ | . ooo | | o ...++. | |.+ . . .+. | |B . o + . | |+o . .+oS | | o .. +=. | | *Eoo o.. | | .oB+ o +oo | |..o.o=.+.++ | +----[SHA256]-----+
R7000@DESKTOP-30AFPHP MINGW64 /d/Workspace/Py/gitest
$ git clone git@ssh.dev.azure.com:v3/XXXX8009/GitTestProject/GitTestProject
Cloning into 'GitTestProject'...
remote: Azure Repos
remote: Found 22 objects to send. (6 ms)
Receiving objects: 100% (22/22), 5.64 KiB | 1.41 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。