简体   繁体   English

使用packer将文件从主机复制到生成的映像,无需密码

[英]Using packer to copy file from host to generated image without password

I am currently using packer to generate customized images from a given configuration. 我目前正在使用packer从给定配置生成自定义图像。 The packer .json file includes provisions, which are described in this packer tutorial . packer .json文件包含本包装程序教程中描述的条款。

Instead of typing the commands there, I used the shell option in which I can write a bunch of sudo apt-get install commands to customize the images. 我没有在那里输入命令,而是使用shell选项,我可以在其中编写一堆sudo apt-get install命令来自定义图像。

The problem is that I need to copy a file from a computer I own to the images. 问题是我需要将文件从我拥有的计算机复制到图像中。 To be clear, the computer I own is also the one I'm running the command packer build example.json . 要清楚,我拥有的计算机也是我正在运行命令packer build example.json

In the shell script, how can I do a secure copy so that from the perspective of the newly-created images , the image can securely copy the file from my computer to itself, without having to type a password? 在shell脚本中,如何进行安全复制,以便从新创建的图像的角度来看 ,图像可以安全地将文件从我的计算机复制到自身, 无需输入密码? This is a shell script so I couldn't type one in if I wanted to. 这是一个shell脚本,所以如果我愿意,我就无法输入。

I understand that to avoid typing in the password, I need public/private key authentication. 我知道为了避免输入密码,我需要公钥/私钥验证。 In the shell script, I have: 在shell脚本中,我有:

sudo ssh-keygen -t rsa -b 2048
sudo scp ~/.ssh/id_rsa.pub user@example.com:/home/user/.ssh/uploaded_key.pub
sudo ssh user@example.com "echo `cat ~/.ssh/uploaded_key.pub` >> ~/.ssh/authorized_keys"

(Taken from the example here and elsewhere. My understanding from this is that the image which is generated is running these commands.) (摘自此处和其他地方的示例 。我对此的理解是生成的图像正在运行这些命令。)

The problem with this and many approaches I see on StackOverflow, such as with this related question , is either one of two things. 我在StackOverflow上看到的这个和许多方法的问题,例如与这个相关的问题 ,是两件事之一。

  • The first time this public/private authentication happens, it seems like a password is needed. 这种公共/私有身份验证一次发生时,似乎需要密码。 However, this is done entirely in a shell script so I don't know how to avoid it. 但是,这完全是在shell脚本中完成的,所以我不知道如何避免它。
  • packer generates these images on the fly, so other approaches that require me to type in explicit AMI IDs for ssh or scp do not seem to work. packer会动态生成这些图像,因此需要我为sshscp键入显式AMI ID的其他方法似乎不起作用。

A closely related question uses the "file" provision type, but I would like to do this with the "shell" type and I'm not sure how to use both the file and the shell options. 一个密切相关的问题使用“文件”提供类型,但我想用“shell”类型执行此操作,我不知道如何使用文件和shell选项。

How may I resolve this? 我怎么解决这个问题?

You should use the file provisioner, something like: 您应该使用file配置器,例如:

"provisioners": [
  {
    "type": "file",
    "source": "source_file",
    "destination": "dest"
  },
  {
    "type": "script",
    "inline": [ "echo do something here" ]
  }
]

See documentation: provisioners 请参阅文档:供应商

暂无
暂无

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

相关问题 Shell脚本,该脚本使用SFTP将文件从另一台服务器复制到我的机器上,而无需提示输入密码 - Shell script which copy the file from another server to my box using SFTP without prompting for a password 将文件夹从远程位置复制到本地计算机,而无需提示输入密码 - Copy folders from remote location to local machine without Prompting for Password shell 脚本在 bash 中运行 docker 镜像,获取 db dump 并将文件复制到主机 - shell script to run the docker image in bash, take db dump and copy file to the host Shell脚本可将一个目录从一台服务器复制到另一台服务器,而无需输入密码 - Shell script to copy one directory from one server to another without asking for password 如何在不使用 expect 命令的情况下从 shell 脚本提供密码 - How to supply password from shell script without using expect command 从* os.file复制Golang而无需等待EOF - Golang copy from *os.file without hanging on waiting for EOF 将文件从存储桶拆分并复制到另一个存储桶,而无需在本地下载 - Split and copy a file from a bucket to another bucket, without downloading it locally 使用bash命令从文件中检索纯文本密码 - retrieve plaintext password from file using bash command 使用Shell脚本从另一个文件检查用户名和密码 - username and password checking from another file using shell script 使用bash从Txt文件设置用户名和密码 - Set User Name and Password from Txt file using bash
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM