1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_collection_users.git synced 2024-08-16 10:29:50 +02:00

update and improving sshd config

This commit is contained in:
L3D 2024-02-15 03:37:33 +01:00
parent 0a1c76e21c
commit 3c8e560cfa
Signed by: l3d
GPG key ID: CD08445BFF4313D1
3 changed files with 65 additions and 55 deletions

View file

@ -29,17 +29,21 @@ l3d_users__local_users: []
l3d_users__ssh_login: [] l3d_users__ssh_login: []
# - name: 'dora' # - name: 'dora'
# state: 'present'
l3d_users__limit_login: true l3d_users__limit_login: true
l3d_users__sshd_port: 22 l3d_users__sshd_port: 22
l3d_users__sshd_password_authentication: false l3d_users__sshd_password_authentication: false
l3d_users__sshd_permitrootlogin: false
l3d_users__create_ansible: true
l3d_users__ansible_user_state: 'present'
l3d_users__sshd_manage_server_key_types: true l3d_users__sshd_manage_server_key_types: true
l3d_users__sshd_server_key_types: l3d_users__sshd_server_key_types:
- ed25519 - 'ed25519'
# - rsa # - 'rsa'
# - ecdsa # - 'ecdsa'
l3d_users__sshd_manage_key_algorithmus: true l3d_users__sshd_manage_key_algorithmus: true
l3d_users__sshd_key_algorithmus: l3d_users__sshd_key_algorithmus:

View file

@ -14,15 +14,15 @@
msg: "SSH Version: {{ _sshd_version }}" msg: "SSH Version: {{ _sshd_version }}"
verbosity: 1 verbosity: 1
# - name: Create SSHD configuration - name: Create SSHD configuration
# become: true become: true
# ansible.builtin.template: ansible.builtin.template:
# src: 'templates/sshd_config.j2' src: 'templates/sshd_config.j2'
# dest: '/etc/ssh/sshd_config' dest: '/etc/ssh/sshd_config'
# owner: 'root' owner: 'root'
# group: 'root' group: 'root'
# mode: 'u=rw,g=r,o=r' mode: 'u=rw,g=r,o=r'
# validate: '/usr/sbin/sshd -t -f %s' validate: '/usr/sbin/sshd -t -f %s'
# backup: true backup: true
# notify: notify:
# - 'systemctl restart sshd' - 'systemctl restart sshd'

View file

@ -4,13 +4,14 @@
# This is the sshd server system-wide configuration file. See # This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information. # sshd_config(5) for more information.
{% if sshd__version_is_above_eight | default(false) | bool %} {% if _sshd_version | default(7) > 8.0 | bool %}
# Include SSHD config snippets # Include SSHD config snippets
# Support fot this starts with sshd 8.0
Include /etc/ssh/sshd_config.d/*.conf Include /etc/ssh/sshd_config.d/*.conf
{% endif %} {% endif %}
# Networking # Networking
Port {{ sshd__port }} Port {{ l3d_users__sshd_port }}
AddressFamily any AddressFamily any
#ListenAddress 0.0.0.0 #ListenAddress 0.0.0.0
#ListenAddress :: #ListenAddress ::
@ -18,41 +19,34 @@ AddressFamily any
TCPKeepAlive yes TCPKeepAlive yes
# SSHD Key exchange # SSHD Key exchange
{% if l3d_users__sshd_manage_key_algorithmus | bool %}
# -> HostkeyAlgorithms # -> HostkeyAlgorithms
{% if not sshd__manage_key_algorithmus | bool %}#{% endif -%} HostkeyAlgorithms {{ l3d_users__sshd_key_algorithmus | join(',') }}
{{ 'HostkeyAlgorithms ' }} {% else %}
{%- for algo in sshd__key_algorithmus -%} # No HostkeyAlgorithms defined
{{- algo -}} {% endif %}
{{- "," if not loop.last -}}
{%- endfor %}
{% if l3d_users__sshd_manage_kex_algorithmus | bool %}
# -> KexAlgorithms # -> KexAlgorithms
{% if not sshd__manage_kex_algorithmus | bool %}#{% endif -%} KexAlgorithms {{ l3d_users__sshd_kex_algorithmus | join(',') }}
{{ 'KexAlgorithms ' }} {% else %}
{%- for algo in sshd__kex_algorithmus -%} # No KexAlgorithms defined
{{- algo -}} {% endif %}
{{- "," if not loop.last -}}
{%- endfor %}
# Ciphers and keying # Ciphers and keying
# RekeyLimit default none {% if l3d_users__sshd_manage_ciphers | bool %}
# -> Ciphers # -> Ciphers
{% if not sshd__manage_ciphers | bool %}#{% endif -%} Ciphers {{ l3d_users__sshd_ciphers | join(',') }}
{{ 'Ciphers ' }} {% else %}
{%- for cipher in sshd__ciphers -%} # No Ciphers defined
{{- cipher -}} {% endif %}
{{- "," if not loop.last -}}
{%- endfor %}
{% if l3d_users__sshd_manage_macs | bool %}
# -> Macs # -> Macs
{% if not sshd__manage_macs | bool %}#{% endif -%} MACs {{ l3d_users__sshd_macs | join(',') }}
{{ 'MACs ' }} {% else %}
{%- for mac in sshd__macs -%} # No MACs defined
{{- mac -}} {% endif %}
{{- "," if not loop.last -}}
{%- endfor %}
# Server Authentication # Server Authentication
Protocol 2 Protocol 2
@ -62,23 +56,23 @@ SyslogFacility AUTH
LogLevel INFO LogLevel INFO
# SSHD Host Keys # SSHD Host Keys
{% for key in sshd__key_types %} {% if l3d_users__sshd_manage_server_key_types | bool %}
{% for key in l3d_users__sshd_server_key_types %}
# -> {{ key }} # -> {{ key }}
{% if not sshd__manage_key_types | bool %}#{% endif -%}
HostKey /etc/ssh/ssh_host_{{ key }}_key HostKey /etc/ssh/ssh_host_{{ key }}_key
{% endfor %} {% endfor %}
{% endif %}
# Client authentication # Client authentication
MaxAuthTries 6 MaxAuthTries 6
MaxSessions 10 MaxSessions 10
PasswordAuthentication {{ sshd__password_authentication | ternary('yes', 'no') }} PasswordAuthentication {{ l3d_users__sshd_password_authentication | ternary('yes', 'no') }}
ChallengeResponseAuthentication no ChallengeResponseAuthentication no
PubkeyAuthentication yes PubkeyAuthentication yes
PermitRootLogin without-password PermitRootLogin {{ l3d_users__sshd_permitrootlogin | ternary('without-password', 'no') }}
LoginGraceTime 120 LoginGraceTime 120
StrictModes yes StrictModes yes
X11Forwarding {{ sshd__xforwarding | ternary('yes', 'no') }} X11Forwarding {{ l3d_users__sshd_xforwarding | ternary('yes', 'no') }}
AllowTcpForwarding yes AllowTcpForwarding yes
#GatewayPorts no #GatewayPorts no
@ -110,13 +104,25 @@ TCPKeepAlive yes
# and ChallengeResponseAuthentication to 'no'. # and ChallengeResponseAuthentication to 'no'.
UsePAM yes UsePAM yes
{% set _sshd_accounts = [] %}
{% for user in _l3d_users__merged_users %}
{% if user.name is defined and user.state | default('present') == 'present' %}
{% set _ = _sshd_accounts.append(user.name) %}
{% endif %}
{% endfor %}
# User Authentication # User Authentication
{% if not sshd__restrict_users -%}#{%- endif -%} {% if l3d_users__create_ansible | bool and l3d_users__ansible_user_state == 'present' %}
AllowUsers {{ sshd__allowed_users|join(' ') }} AllowUsers ansible {{ _sshd_accounts | join(' ') }}
# Group Authentication # Group Authentication
{% if not sshd__restrict_groups -%}#{%- endif -%} AllowGroups ansible {{ _sshd_accounts | join(' ') }}
AllowGroups {{ sshd__allowed_groups|join(' ') }} {% else %}
AllowUsers {{ _sshd_accounts | join(' ') }}
# Group Authentication
AllowGroups {{ _sshd_accounts | join(' ') }}
{% endif %}
# Allow client to pass locale environment variables # Allow client to pass locale environment variables
AcceptEnv LANG LC_* AcceptEnv LANG LC_*