Comment out Port(s) in sshd_config to avoid port conflicts when multiple SSH Port definitions present (#1809)

- Comment out Port(s) in sshd_config to avoid port conflicts when multiple SSH Port definitions present
- Resolve duplication issue for repeatedly running the install playbook
- Avoid accidental uncommenting of Port 22
This commit is contained in:
dz 2025-07-04 10:57:00 -04:00 committed by GitHub
parent 6faf600d40
commit 8e79c596f3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View file

@ -478,6 +478,21 @@
tags: tags:
- "Ubuntu" - "Ubuntu"
- name: Comment out Port(s) in sshd_config, can cause port conflicts on deploy (AlmaLinux, Debian, Fedora, openSUSE Tumbleweed, Raspbian, Rocky, Ubuntu)
ansible.builtin.replace:
path: /etc/ssh/sshd_config
regexp: '^(Port (?!64295$)[0-9]+)'
replace: '# \1'
when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
tags:
- "AlmaLinux"
- "Debian"
- "Fedora"
- "openSUSE Tumbleweed"
- "Raspbian"
- "Rocky"
- "Ubuntu"
- name: Change SSH Port to 64295 (AlmaLinux, Debian, Fedora, Raspbian, Rocky, Ubuntu) - name: Change SSH Port to 64295 (AlmaLinux, Debian, Fedora, Raspbian, Rocky, Ubuntu)
lineinfile: lineinfile:
path: /etc/ssh/sshd_config path: /etc/ssh/sshd_config

View file

@ -215,6 +215,21 @@
- "Rocky" - "Rocky"
- "Ubuntu" - "Ubuntu"
- name: Revert Comment out Port(s) in sshd_config, can cause port conflicts on deploy (AlmaLinux, Debian, Fedora, openSUSE Tumbleweed, Raspbian, Rocky, Ubuntu)
ansible.builtin.replace:
path: /etc/ssh/sshd_config
regexp: '^# (Port (?!22$)[0-9]+)'
replace: '\1'
when: ansible_distribution in ["AlmaLinux", "Debian", "Fedora", "openSUSE Tumbleweed", "Raspbian", "Rocky", "Ubuntu"]
tags:
- "AlmaLinux"
- "Debian"
- "Fedora"
- "openSUSE Tumbleweed"
- "Raspbian"
- "Rocky"
- "Ubuntu"
- name: Remove vm.max_map_count setting (All) - name: Remove vm.max_map_count setting (All)
lineinfile: lineinfile:
path: /etc/sysctl.conf path: /etc/sysctl.conf