[英]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上看到的这个和许多方法的问题,例如与这个相关的问题 ,是两件事之一。
ssh
or scp
do not seem to work. ssh
或scp
键入显式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" ]
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.