自动将主机的SSH公钥迁移到基于Puppet的Vagrant虚拟机可以通过以下步骤实现:
config.vm.provision "shell", inline: <<-SHELL
echo '添加主机公钥到authorized_keys文件'
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDL...' >> /home/vagrant/.ssh/authorized_keys
SHELL
class ssh_keys {
ssh_authorized_key { 'vagrant':
user => 'vagrant',
type => 'ssh-rsa',
key => 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDL...',
ensure => present,
require => File['/home/vagrant/.ssh'],
}
}
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "site.pp"
puppet.module_path = "modules"
end
这样,当Vagrant虚拟机启动时,会自动将主机的SSH公钥迁移到虚拟机中,实现了自动化的过程。
推荐的腾讯云相关产品:腾讯云虚拟机(CVM)。
领取专属 10元无门槛券
手把手带您无忧上云