7

Is it possible to add ssh authorized keys for multiple users using a #cloud-config file with CloudInit?

I'm trying to initialize a new EC2 instance created from an Amazon Linux AMI using CloudInit. I'm able to add custom ssh authorized public keys to the ec2-user account using something like this:

#cloud-config

ssh_authorized_keys:
  - ssh-rsa AAAAB3NzaC1yc2EAAA...

What I'd really like to do is create several new users an add a separate public key for each of them. Is it possible to do this using a standard cloud-config directive, or do I just need to write a custom shell script to do that?

Mike Deck
  • 183
  • 1
  • 1
  • 7

2 Answers2

7

Looks like you can do this now

#cloud-config
users:
  - default
  - name: jdoe
    gecos: John Doe
    ssh-authorized-keys:
      - ssh-rsa ...
  - name: jroe
    gecos: Jane Roe
    ssh-authorized-keys:
      - ssh-rsa ...

from https://cloudonaut.io/avoid-sharing-key-pairs-for-ec2/

Aaron McMillin
  • 191
  • 1
  • 4
2

CloudInit doesn't support specifying multiple users to install SSH keys for. You'll need to write your own script to accomplish this.

mgorven
  • 30,615
  • 7
  • 79
  • 122
  • 1
    That's what I figured, but the documentation on CloudInit is so spotty I figured there was a chance someone else knew of a feature I didn't. Thanks for the confirmation. – Mike Deck Feb 04 '13 at 19:01
  • @MikeDeck It is, I had to look at the source. – mgorven Feb 04 '13 at 19:12