注意: 此角色已迁移至我们的 hardening-collection:
请在那里提交任何 issue 和 pull request!
network_ipv6_enable
ssh_listen_to 也必须设置为监听 IPv6 地址(例如 [::])。ssh_server_ports
ssh_client_port
ssh_listen_to
ssh_host_key_files
ssh_host_key_algorithms
ssh_client_alive_interval
ssh_client_alive_count
ssh_permit_tunnel
ssh_remote_hosts
defaults/main.yml 中的示例。ssh_permit_root_login
without-password 或 yes 以启用 root 登录ssh_allow_tcp_forwarding
'no' 禁用 TCP 转发。设置为 'yes' 允许 TCP 转发。如果您使用 OpenSSH >= 6.2 版本,可以指定 'yes'、'no'、'all' 或 'local'。 'yes' 和 'no' 应带引号传递。ssh_gateway_ports
falsefalse 禁用将转发端口绑定到非回环地址。设置为 true 强制绑定到通配符地址。设置为 clientspecified 允许客户端指定要绑定的地址。ssh_allow_agent_forwarding
ssh_x11_forwarding
ssh_pam_support
ssh_use_pam
ssh_gssapi_support
ssh_kerberos_support
ssh_deny_users
ssh_allow_users
ssh_deny_groups
ssh_allow_groups
ssh_authorized_keys_file
ssh_trusted_user_ca_keys_file
ssh_trusted_user_ca_keys
ssh_trusted_user_ca_keys_file 时使用。ssh_authorized_principals_file
ssh_trusted_user_ca_keys_file 时使用。ssh_authorized_principals
default_custom.yml。仅在设置了 ssh_authorized_principals_file 时使用。ssh_print_motd
ssh_print_pam_motd
ssh_print_last_log
sftp_enabled
sftp_umask
sftp_chroot
sftp_chroot_dir
ssh_client_roaming
sshd_moduli_file
sshd_moduli_minimum
ssh_challengeresponseauthentication
ssh_client_password_login
true 允许 ssh 客户端使用基于密码的认证ssh_server_password_login
true 允许 ssh 服务器使用基于密码的认证ssh_banner
falsetrue 在登录时打印横幅ssh_banner_path
ssh_client_hardening
truefalse 停止加固客户端ssh_client_port
'22'ssh_client_compression
falsessh_compression
falsessh_login_grace_time
30sssh_max_auth_retries
2ssh_max_sessions
10ssh_print_debian_banner
falsetrue 打印 Debian 特定的横幅ssh_server_enabled
truefalse 禁用 opensshd 服务器ssh_server_hardening
truefalse 停止加固服务器ssh_server_match_address
ssh_server_match_group
ssh_server_match_user
ssh_server_match_local_port
ssh_server_permit_environment_vars
noyes 指定 sshd 处理 ~/.ssh/environment 和 ~/.ssh/authorized_keys 中的 environment= 选项。使用 openssh 7.8 版本时,除了全局的 "yes" 或 "no" 设置外,还可以指定环境变量名称的白名单。ssh_server_accept_env_vars
ssh_use_dns
falsessh_server_revoked_keys
ssh_max_startups
ssh_macs
defaults/main.ymlssh_kex
defaults/main.ymlssh_ciphers
defaults/main.ymlssh_custom_options
sshd_custom_options
sshd_syslog_facility
sshd_log_level
sshd_strict_modes
sshd_authenticationmethods
publickeydefaults/main.yml如果您想配置上面未列出的 ssh 选项,可以使用 ssh_custom_options(用于 /etc/ssh/ssh_config)或 sshd_custom_options(用于 /etc/ssh/sshd_config)进行设置。这些选项将设置在文件的开头,因此您可以在文件后面覆盖这些选项。
示例 playbook:
- hosts: localhost
roles:
- dev-sec.ssh-hardening
vars:
ssh_custom_options:
- "Include /etc/ssh/ssh_config.d/*"
sshd_custom_options:
- "AcceptEnv LANG"
此角色使用默认端口 22 或清单中配置的端口来连接服务器。如果通过 ssh_server_ports 更改了默认的 ssh 端口,一旦 ssh 服务器重启,它仍将尝试使用之前的端口连接。为了在同一服务器上再次运行此角色,必须更新清单以使用新的 ssh 端口。
如果幂等性很重要,请考虑使用角色 ssh-hardening-fallback,它是此角色的包装器,当配置的端口不可达时会回退到端口 22。
- hosts: localhost
roles:
- dev-sec.ssh-hardening
本地测试此角色的首选方式是使用 Docker。您需要在系统上安装 Docker。请参阅入门获取适合您系统的 Docker 软件包。
您也可以使用 vagrant 和 Virtualbox 或 VMWare 在本地运行测试。您需要在系统上安装 Virtualbox 和 Vagrant。请参阅 Vagrant 下载获取适合您系统的 vagrant 软件包。我们所有的测试都使用 test-kitchen。如果您不熟悉 test-kitchen,请查看他们的指南。
接下来安装 test-kitchen:
# 安装依赖
gem install bundler
bundle install
# 在单台机器上快速测试
bundle exec kitchen test ssh-ubuntu1804-ansible-latest
# 在所有机器上测试
bundle exec kitchen test
# 用于开发
bundle exec kitchen create ssh-ubuntu1804-ansible-latest
bundle exec kitchen converge ssh-ubuntu1804-ansible-latest
bundle exec kitchen verify ssh-ubuntu1804-ansible-latest
# 清理
bundle exec kitchen destroy ssh-ubuntu1804-ansible-latest
# 在单台机器上快速测试
KITCHEN_YAML=".kitchen.vagrant.yml" bundle exec kitchen test ssh-ubuntu-1804
# 在所有机器上测试
KITCHEN_YAML=".kitchen.vagrant.yml" bundle exec kitchen test