← Back to team overview

cloud-init team mailing list archive

Re: How to regenerate ssh key by cloud-init ?

 

#/etc/cloud/cloud.cfg
runcmd:
   - sudo ssh-keygen -A

# why My openstack data source does not take effect ?
/etc/cloud/cloud.cfg.d/xxx
add lines here. It would override  all configuration before.

On Fri, Mar 4, 2022 at 9:42 AM luckydog xf <luckydogxf@xxxxxxxxx> wrote:

> Sorry it's my fault. There are not many 'bootcmd` in cloud.cfg. I made a
> mistake.
>
> On Fri, Mar 4, 2022 at 9:29 AM luckydog xf <luckydogxf@xxxxxxxxx> wrote:
>
>> One more question, as you can see `bootcmd` appears many times in
>> cloud.cfg, like cloud-init/cloud_config/cloud_final stage.
>>
>> How can I run a command in a specific stage, like cloud_config ?
>>
>> And  if I want to add datasource like openstack,  I just add lines
>> datasource:
>>     Openstack:
>>       metadata_urls: [ 'http://169.254.169.254:80' ]
>>       timeout: 5 # (defaults to 50 seconds)
>>      max_wait: 10 # (defaults to 120 seconds)
>>
>> right?
>>
>>
>> On Fri, Mar 4, 2022 at 9:12 AM luckydog xf <luckydogxf@xxxxxxxxx> wrote:
>>
>>> I added lines like
>>>
>>> ssh_authorized_keys:  - ssh-rsa AAAAxxxx  - ssh-rsa AAAxxxxx# new random keys will not be generated#  in addition to 'rsa' and 'dsa' as shown below, 'ecdsa' is also supportedssh_keys:  rsa_private: |    -----BEGIN RSA PRIVATE KEY-----
>>>
>>> in /var/lib/cloud/instance/user-data.txt and reboot it. Keys were not been  created.
>>>
>>>
>>> On Thu, Mar 3, 2022 at 4:39 PM luckydog xf <luckydogxf@xxxxxxxxx> wrote:
>>>
>>>> Hello,
>>>>    I created ubuntu 20.04 LTS image for openstack by
>>>> https://docs.openstack.org/image-guide/ubuntu-image.html.
>>>>    There is a sysprep in the final stage which would remove MAC and
>>>> ssh_host_xxx of sshd.
>>>>     So I have to generate a new one, othewide sshd daemon fails to
>>>> start.
>>>>     This is cloud.cfg created by ubuntu server autoinstall.
>>>>
>>>>      ===
>>>> #cloud-config
>>>> disable_root: true
>>>> growpart: {mode: 'off'}
>>>> locale: en_US.UTF-8
>>>> power_state: {mode: reboot}
>>>> preserve_hostname: true
>>>> resize_rootfs: false
>>>> ssh_pwauth: true
>>>> timezone: Asia/Hong_Kong
>>>> users:
>>>> - gecos: ubuntu
>>>>   groups: [adm, cdrom, dip, plugdev, lxd, sudo]
>>>>   lock_passwd: false
>>>>   name: ubuntu
>>>>   passwd:
>>>> $6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0
>>>>   shell: /bin/bash
>>>> ===
>>>> How can I generate these keys? Normally it should be generate by `sudo
>>>> ssh-keygen -A' manually.
>>>>
>>>> One more thing, how can I use openstack user-data ?
>>>>
>>>

References