Search code examples
ssh-keysdigital-oceancloud-init

cloud-init .yaml script on Digital Ocean droplets


I am stuck with creating users with Cloud-Config.

Did anyone succeed and can share a .yaml gist to create a new user with ssh-authorized-keys and ability to sudo?


Solution

  • This article on DigitalOcean runs through doing some of the most common initial tasks using cloud-config files.

    Setting up a new sudo user would look like this:

    #cloud-config
    users:
      - name: username
        ssh-authorized-keys:
          - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCv60WjxoM39LgPDbiW7ne3gu18q0NIVv0RE6rDLNal1quXZ3nqAlANpl5qmhDQ+GS/sOtygSG4/9aiOA4vXO54k1mHWL2irjuB9XbXr00+44vSd2q/vtXdGXhdSMTf4/XK17fjKSG/9y3yD6nml6 user@example.com
        sudo: ['ALL=(ALL) NOPASSWD:ALL']
        groups: sudo
        shell: /bin/bash
    

    Of course, replace the ssh key with your public key.