Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用令牌向GitHub进行身份验证_Github_Github Pages - Fatal编程技术网

使用令牌向GitHub进行身份验证

使用令牌向GitHub进行身份验证,github,github-pages,Github,Github Pages,我正在尝试使用个人访问令牌通过GitHub进行身份验证。在github的帮助文件中,它声明使用cURL方法进行身份验证()。我已经试过了,但是我仍然无法推到GitHub。请注意,我正在尝试从未经验证的服务器(Travis CI)推送 cd$HOME git config--global user.email“emailaddress@yahoo.com" git config--全局user.name“username” curl-u“用户名:”https://github.com/userna

我正在尝试使用个人访问令牌通过GitHub进行身份验证。在github的帮助文件中,它声明使用cURL方法进行身份验证()。我已经试过了,但是我仍然无法推到GitHub。请注意,我正在尝试从未经验证的服务器(Travis CI)推送

cd$HOME
git config--global user.email“emailaddress@yahoo.com"
git config--全局user.name“username”
curl-u“用户名:”https://github.com/username/ol3-1.git
git克隆--分支=gh页https://github.com/username/ol3-1.git gh页面
cd页
mkdir构建测试
cd构建测试
触摸asdf.asdf
git-add-f。
git提交-m“Travis build$Travis_build_数量推送到gh页面”
git推送-fq源gh页面
此代码导致以下错误:

远程:拒绝匿名访问scuzzlebuzzle/ol3-1.git

致命:对“”的身份验证失败


您的
curl
命令完全错误

curl -H 'Authorization: token <MYTOKEN>' ...
curl-H“授权:令牌”。。。
除此之外,如果存储库是私有的,则不会授权您的计算机克隆该存储库。(但是,看一看,表明它不是私有的。)您通常会执行以下操作:

git clone https://scuzzlebuzzle:<MYTOKEN>@github.com/scuzzlebuzzle/ol3-1.git --branch=gh-pages gh-pages
$ sudo apt-get install xclip
git克隆https://scuzzlebuzzle:@github.com/scuzzlebuzzle/ol3-1.git--branch=gh pages gh pages
这会将您的凭据添加到克隆存储库时创建的远程。但是,不幸的是,您无法控制Travis如何克隆存储库,因此您必须像这样编辑远程

# After cloning
cd gh-pages
git remote set-url origin https://scuzzlebuzzle:<MYTOKEN>@github.com/scuzzlebuzzle/ol3-1.git
克隆后的
#
cd页
git远程设置url源https://scuzzlebuzzle:@github.com/scuzzlebuzzle/ol3-1.git
这将修复您的项目以使用内置凭据的远程服务器

警告:令牌具有读/写访问权限,应将其视为密码。如果在克隆或添加远程时将令牌输入克隆URL,
Git会以纯文本形式将其写入.Git/config文件,这是一种安全风险。

为了避免交出“城堡钥匙”。。。 请注意,sigmavirus24的响应要求您向Travis提供一个具有相当广泛权限的令牌——因为GitHub只提供具有广泛范围的令牌,如“写我所有的公共回购”或“写我所有的私有回购”

如果您想减少访问(需要做更多的工作!),可以使用GitHub部署密钥和Travis加密的yaml字段相结合

下面是这项技术如何工作的草图

首先生成一个名为
my_key
的RSA部署密钥(通过
ssh-keygen
),并将其作为部署密钥添加到github repo设置中

然后

$ password=`openssl rand -hex 32`
$ cat my_key | openssl aes-256-cbc -k "$password" -a  > my_key.enc
$ travis encrypt --add password=$password -r my-github-user/my-repo
然后使用
$password
文件在集成时解密部署密钥,方法是向yaml文件中添加:

before_script: 
  - openssl aes-256-cbc -k "$password" -d -a -in my_key.enc -out my_deploy_key
  - echo -e "Host github.com\n  IdentityFile /path/to/my_deploy_key" > ~/.ssh/config
  - echo "github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" > ~/.ssh/known_hosts

注意:最后一行预先填充github的RSA密钥,这避免了在连接时手动接受。

自动化/Git自动化使用OAuth令牌

$ git clone https://github.com/username/repo.git
  Username: your_token
  Password:
它还可以在git push命令中使用

参考:

首先,您需要创建个人访问令牌(PAT)。如下所述:

可笑的是,这篇文章告诉你如何创建它,但却完全没有给出如何使用它的线索。经过大约一个小时的拖网文档和StackOverflow,我终于找到了答案:

$ git clone https://github.com/user-or-organisation/myrepo.git
Username: <my-username>
Password: <my-personal-access-token>
(@YMHuang通过文档链接让我走上了正确的轨道。)

这对我使用ssh很有效:

背景→ 开发人员设置→ 生成新令牌


通过在应用GitHub令牌上苦苦挣扎了这么多小时,最终它的工作原理如下:

$cf\u export GITHUB\u TOKEN=$(codefresh获取上下文GITHUB--decrypt-o
yaml | yq-y.spec.data.auth.password)

  • 代码遵循关于使用令牌(freestyle}克隆回购协议的指南
  • 测试进行:sed
    %d%H%M
    匹配单词
    “-123456随便什么”
  • 推回回购(即私人回购
  • 由网络挂钩触发
以下是完整的代码:

version: '1.0'
steps:
  get_git_token:
    title: Reading Github token
    image: codefresh/cli
    commands:
      - cf_export GITHUB_TOKEN=$(codefresh get context github --decrypt -o yaml | yq -y .spec.data.auth.password)
  main_clone:
    title: Updating the repo
    image: alpine/git:latest
    commands:
      - git clone https://chetabahana:$GITHUB_TOKEN@github.com/chetabahana/compose.git
      - cd compose && git remote rm origin
      - git config --global user.name "chetabahana"
      - git config --global user.email "chetabahana@gmail.com"
      - git remote add origin https://chetabahana:$GITHUB_TOKEN@github.com/chetabahana/compose.git
      - sed -i "s/-[0-9]\{1,\}-\([a-zA-Z0-9_]*\)'/-`date +%d%H%M`-whatever'/g" cloudbuild.yaml
      - git status && git add . && git commit -m "fresh commit" && git push -u origin master
输出

On branch master 
Changes not staged for commit: 
  (use "git add ..." to update what will be committed) 
  (use "git checkout -- ..." to discard changes in working directory) 

modified:   cloudbuild.yaml 

no changes added to commit (use "git add" and/or "git commit -a") 
[master dbab20f] fresh commit 
 1 file changed, 1 insertion(+), 1 deletion(-) 
Enumerating objects: 5, done. 
Counting objects:  20% (1/5) ...  Counting objects: 100% (5/5), done. 
Delta compression using up to 4 threads 
Compressing objects:  33% (1/3) ... Writing objects: 100% (3/3), 283 bytes | 283.00 KiB/s, done. 
Total 3 (delta 2), reused 0 (delta 0) 
remote: Resolving deltas:   0% (0/2)  ...   (2/2), completed with 2 local objects. 
To https://github.com/chetabahana/compose.git 
   bbb6d2f..dbab20f  master -> master 
Branch 'master' set up to track remote branch 'master' from 'origin'. 
Reading environment variable exporting file contents. 
Successfully ran freestyle step: Cloning the repo 

用于登录github.com门户的密码在VS Code CLI/Shell中不起作用。您应该通过生成新的令牌从URL复制PAT令牌,并将该字符串作为密码粘贴到CLI中。

通常我会这样做

 git push https://$(git_token)@github.com/user_name/repo_name.git
git_令牌正在从azure devops中的变量配置读取


您可以阅读我的完整博客

如果您正在使用GitHub Enterprise,并且克隆回购或推送会给您一个403错误,而不是提示您输入用户名/令牌,您可以使用以下方法:

  • 删除回购协议
  • 打开命令提示符并导航到您希望回购的文件夹
  • 类型:

  • 为了解决这个问题,我们在ORG/REPO部分花了几乎一整天的时间在构建脚本中硬编码,得到了可怕的“remote not found”(远程未找到)错误,最终找到了一个可行的解决方案,即使用
    TRAVIS_REPO_SLUG
    。将其转换为硬编码属性立即奏效

    git远程设置url源https://[ORG]:${TOKEN}@github.com/${TRAVIS_REPO_SLUG}
    
    步骤1:获取访问令牌 转到此链接:
    然后在那里生成令牌

    步骤2:使用令牌
    $git推送
    用户名:
    密码:
    
    现在,您不必每次推送更改时都键入用户名和密码。

    您只需键入git push并按Enter键,更改将被推送。

    我使用的是Ubuntu 20.04,我一直收到消息,很快我就无法从控制台登录。我感到非常困惑。 最后,我找到了下面的URL,它可以工作。但是你需要知道如何创建一个PAT(个人访问令牌),你必须将它保存在你计算机上的文件中

    以下是最终URL的外观:

    git push https://1234567890123456789012345678901234567890@github.com/user-name/repo.git
    
    long PAT(个人访问令牌)value——符号//和@i之间的整个long值
     git push https://$(git_token)@github.com/user_name/repo_name.git
    
    git clone https://[USERNAME]:[TOKEN]@[GIT_ENTERPRISE_DOMAIN]/[ORGANIZATION]/[REPO].git
    
    git push https://1234567890123456789012345678901234567890@github.com/user-name/repo.git
    
    $ cat ~/files/myPatFile.txt
    
    $ xclip -selection clipboard < ~/files/myPatFile.txt
    
    $ sudo apt-get install xclip