Skip to content

Instantly share code, notes, and snippets.

@ianling
Created April 14, 2016 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianling/36e923097396f4708be2a39e7f962cd8 to your computer and use it in GitHub Desktop.
Save ianling/36e923097396f4708be2a39e7f962cd8 to your computer and use it in GitHub Desktop.
Creates SSH certificates for passwordless login
---
- name: Set up sshcerts for MYUSER
hosts: all
remote_user: MYUSER
tasks:
- name: Generate a unique key for this host
local_action: command /usr/bin/ssh-keygen -b 2048 -t rsa -f /home/MYUSER/sshkeys/{{ inventory_hostname }} -q -N ""
- name: Create /backup/.ssh recursively
file: path=/home/MYUSER/.ssh state=directory owner=MYUSER group=MYUSER mode=0700 recurse=yes
- name: Add public key to backup user
authorized_key: user=MYUSER
key="{{ lookup('file', '/home/MYUSER/sshkeys/'+inventory_hostname+'.pub') }}"
state=present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment