fatal: could not read Username for 解决方案

爱被打了一巴掌 2023-02-18 09:35 120阅读 0赞

fatal: could not read Username for ‘http:// 解决方案

在部署drone(CICD软件)后,触发提交时,drone-runner执行拉取仓库代码(在自己部署的gogs上)时出现该问题

  1. Initialized empty Git repository in /drone/src/.git/
  2. + git fetch origin +refs/heads/master:
  3. fatal: could not read Username for 'http://ip:port': terminal prompts disabled

原因提示为需要输入用户名密码,但由于这是CICD软件,并没有输入密码的时机,因此解决方案有两种:

  • 使用 ssh,在drone所在服务器生产 git 公钥,上传到代码托管(我这里用的自己搭建的 gogs,实际上也会有github、gitea、gitee、gitlab等等),即可不需要用户名密码下载上传
  • 使用git的记忆密码机制保存用户名密码

    • 进入 drone 所在服务器,使用 drone 进程用户登录,进入家目录(cd ~
    • 执行 git clone [你的git代码路径] ,发现需要输入密码,ctrl + c 中断
    • 执行 touch .git-credentials 创建 .git-credentials 文件
    • 执行 vim .git-credentials 编辑该文件
    • 按 i 键进入编辑模式,输入:http(s)://{你的用户名}:{你的密码}@你的git服务器地址 【注意选择 https/http,去掉花括号】
    • ESC 输入 :wq 保存并退出
    • 执行 git config --global credential.helper store
    • cat ~/.gitconfig 发现多了一项:

      1. [credential]
      2. helper = store
    • 说明已经配置好了,再次 git clone [你的git代码路径] 试试,不需要输入密码了

fatal: could not read Username for ‘http://…’ : terminal prompts disabled 问题解决~

发表评论

表情:
评论列表 (有 0 条评论,120人围观)

还没有评论,来说两句吧...

相关阅读