linux - bash 脚本从 bash 脚本添加 git 凭据

标签 linux bash shell scripting

我需要能够将我的 git 凭据添加到我的 bash 脚本中,但不知道该怎么做。

git clone https://xxxxxxx

会询问我的用户名和密码。

我如何在 bash 脚本中传递这些?

不胜感激

最佳答案

对于基本的 HTTP 身份验证,您可以:

  1. 在 url 中传递凭据:

    git clone http://USERNAME:PASSWORD@some_git_server.com/project.git
    

    WARN 这是不安全的:当您工作时,您机器上的其他用户可以使用 pstop 实用程序看到带有凭据的 url带远程仓库。

  2. 使用 gitcredentials :

    $ git config --global credential.helper store
    $ git clone http://some_git_server.com/project.git
    
    Username for 'http://some_git_server.com': <USERNAME>
    Password for 'https://USERNAME@some_git_server.com': <PASSWORD>
    
  3. 使用~/.netrc:

    cat >>~/.netrc <<EOF
    machine some_git_server.com
           login <USERNAME>
           password <PASSWORD>
    EOF
    

关于linux - bash 脚本从 bash 脚本添加 git 凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53914241/

相关文章:

android - 无法从 ubuntu 12.04 中的 adt 包启动 eclipse

linux - 使用一个脚本在具有多个命名选项卡的命名 screen session 中启动多个脚本? [ Derby 安]

c - 使用脚本运行在程序中运行多个命令的程序

linux - Linux bash shell 注入(inject)命令的可能列表是什么?

linux - 使用 printf 打印 ascii 字符,但 printf 不会打印八进制 100+ 的任何内容

linux - 将 JVM 移植到 MINIX

bash - 如果不被空格包围,为什么等于运算符不起作用?

bash - 检查文件是否存在于 "Variable"路径中

Linux shell脚本日期算法

linux - 全局变量中的更新值在 Shell 脚本中丢失