This repository has been archived by the owner on Jan 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ansible): secure sshd in bootstrap playbook
- Loading branch information
1 parent
9cfbcf9
commit 73fb675
Showing
4 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
- name: Secure OpenSSH Server # tag:dietpi | ||
hosts: kubernetes | ||
gather_facts: true | ||
become: true | ||
vars: | ||
sshd_config: "/etc/ssh/sshd_config" | ||
|
||
tasks: | ||
- name: Add identity key to authorized keys on host | ||
ansible.posix.authorized_key: | ||
user: "{{ ansible_user }}" | ||
key: "{{ item }}" | ||
loop: "{{ ssh_keys }}" | ||
register: bootstrap_add_identity_keys | ||
when: ssh_keys is defined and ansible_user is defined | ||
|
||
- name: Disable empty password login | ||
ansible.builtin.lineinfile: | ||
dest: "{{ sshd_config }}" | ||
regexp: '^#?PermitEmptyPasswords' | ||
line: 'PermitEmptyPasswords no' | ||
notify: Restart sshd | ||
|
||
- name: Disable remote root login | ||
ansible.builtin.lineinfile: | ||
dest: "{{ sshd_config }}" | ||
regexp: '^#?PermitRootLogin' | ||
line: 'PermitRootLogin no' | ||
notify: Restart sshd | ||
|
||
- name: Disable password login | ||
ansible.builtin.lineinfile: | ||
dest: "{{ sshd_config }}" | ||
regexp: '^(#\s*)?PasswordAuthentication ' | ||
line: 'PasswordAuthentication no' | ||
when: | ||
- bootstrap_add_identity_keys is succeeded | ||
- not bootstrap_add_identity_keys is skipped | ||
notify: Restart sshd | ||
|
||
handlers: | ||
- name: Restart sshd | ||
ansible.builtin.service: | ||
name: sshd | ||
state: restarted |
This file contains 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