简体   繁体   English

从shell脚本进行git clone期间传递密码

[英]Passing password during git clone from shell script

I have written a shell script to clone the project from multiple location which is sent as a file. 我编写了一个Shell脚本来从多个位置克隆项目,该文件以文件形式发送。 I read the file and pass the each location in a loop and perform my operation. 我读取文件并循环传递每个位置并执行我的操作。

LocationFile.txt LocationFile.txt

Project1=https://enduser1@stash.my.org/my/path/testProject1.git
Project2=https://enduser2@stash.my.org/my/path/testProject2.git
Project3=https://enduser3@stash.my.org/my/path/testProject3.git
Project4=https://enduser4@stash.my.org/my/path/testProject3.git

Password.txt 密码.txt

Project1=password1
Project2=password2
Project3=password3
Project4=password4

I have a password file encrypted and stored in server, which I can read as part of script and passing into my script When I run my script during clone step its prompting for a password, I tried to pass the password like below which is not working 我有一个加密的密码文件,并存储在服务器中,可以将其作为脚本的一部分读取并传递到脚本中。在克隆步骤中运行脚本时,系统会提示输入密码,但我尝试通过以下密码进行操作,但该密码无法正常工作

##############
gitpassword=$password1 #retrieved from Password.txt

for xxx
    do
    ...
    ... 
    git clone "${ProjectArrayList[1]}" 
    read $gitpassword
    ...
    ..
    done
##############

I know I can do password less if I use ssh, which I don't want to do. 我知道如果我不想使用ssh,则可以减少密码。 Is there a way to achieve this with my exsiting approach 有没有办法通过我现有的方法来实现这一目标

You can use the expect and send functions to simulate user input automatically. 您可以使用Expectsend函数自动模拟用户输入。

Here is what the syntax would be like: 语法如下所示:

expect -c 'spawn sudo git clone "${ProjectArrayList[1]}"; expect assword; send "password\n"; interact'

Git has a "credential helper" that can do the job [it is designed to work over https]. Git有一个“凭证助手”可以完成这项工作[它旨在通过https工作]。

See: https://git-scm.com/docs/git-credential-store and https://help.github.com/articles/caching-your-github-password-in-git/ 参见: https : //git-scm.com/docs/git-credential-storehttps://help.github.com/articles/caching-your-github-password-in-git/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM