Created
February 26, 2021 16:38
-
-
Save psct/769d7b0d657e5c783f3793d7e62638aa to your computer and use it in GitHub Desktop.
Add ssh key for root access and disable PasswordAuthentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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