Skip to content

Instantly share code, notes, and snippets.

@psct
Created February 26, 2021 16:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save psct/769d7b0d657e5c783f3793d7e62638aa to your computer and use it in GitHub Desktop.
Save psct/769d7b0d657e5c783f3793d7e62638aa to your computer and use it in GitHub Desktop.
Add ssh key for root access and disable PasswordAuthentication
---
- name: add ssh, deploy root key
hosts: all
become: yes
tasks:
- name: disable password authentication
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^PasswordAuthentication'
line: 'PasswordAuthentication no'
state: present
backup: yes
notify:
- restart ssh
- name: deploy key
authorized_key:
user: root
key: "{{ lookup('file', '~/ansible/.ssh/root.pub') }}"
handlers:
- 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