【问题标题】:Doing git clone with bash script, could not read Password for repository使用 bash 脚本执行 git clone,无法读取存储库的密码
【发布时间】:2018-06-22 02:49:21
【问题描述】:

我正在尝试通过 CloudFormation 部署 Amazon EC2 实例,并且我正在尝试使用带有 cfn-init 的 bash 脚本克隆存储库。

"UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [
                "#! /bin/bash -xe\n",
                "yum install -y aws-cfn-bootstrap\n",
                "/opt/aws/bin/cfn-init -v ",
                "       --stack ", { "Ref" : "AWS::StackName" },
                "       --resource DocumentationInstance ",
                "       --configsets Install ",
                "       --region ", { "Ref" : "AWS::Region" }, "\n",
                "git clone https://", { "Ref": "GitLabUsn" },"@gitlab.com/user/repository.git \n", { "Ref": "GitLabPwd" }  
                ]]}}
        }

但是,当我部署 EC2 实例时,我可以从cloud-init-output.log 看到 git clone 失败,这是错误:

fatal: could not read Password for 'https://username@gitlab.com': No such device or address

如何使用 bash 脚本正确输入密码?我试过yes 找到here

【问题讨论】:

    标签: linux bash git amazon-ec2 amazon-cloudformation


    【解决方案1】:

    像这样添加密码(也可以设置为参数) git clone https://user:password@gitlab.com/....git

    在你的情况下,它将是:

    "git clone https://", { "Ref": "GitLabUsn" },":", { "Ref": "GitLabPwd" },"@gitlab.com/user/repository.git \n"
    

    【讨论】:

    • 您好,感谢您的评论!我也试过了,但是在尝试这个时我得到了这个错误。致命:无法访问 https:// 用户名:pwd@gitlab.com/user/repo.git :非法端口号
    猜你喜欢
    • 2021-09-01
    • 2019-09-16
    • 1970-01-01
    • 2014-07-09
    • 2013-08-13
    • 2020-10-06
    • 2017-01-06
    • 1970-01-01
    • 2018-02-20
    相关资源
    最近更新 更多