Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
---
- hosts: all
become: true
become_user: "root"
become_method: sudo
tasks:
- name: Make .ssh directory
file:
path: "/root/.ssh"
state: directory
- name: Delete existing authorized_keys file
file:
state: absent
path: "/root/.ssh/authorized_keys"
- name: Create authorized_keys file
file:
path: "/root/.ssh/authorized_keys"
state: touch
- name: Put pubkey - User 1
lineinfile:
path: "/root/.ssh/authorized_keys"
line: "ssh-rsa Keyhere"
- name: Put pubkey - User 2
lineinfile:
path: "/root/.ssh/authorized_keys"
line: "ssh-rsa Keyhere"
- name: Permit root login
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^PermitRootLogin'
line: 'PermitRootLogin Yes'
- name: Restart SSH
service: name=sshd state=restarted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment