Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Ansible Roles
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pi-Lab
Infrastructure
Ansible Roles
Commits
b795616e
Commit
b795616e
authored
2 years ago
by
istmxrein
Browse files
Options
Downloads
Patches
Plain Diff
add secure-ssh role
parent
949dcccb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
basic/roles/secure-ssh/tasks/main.yaml
+73
-0
73 additions, 0 deletions
basic/roles/secure-ssh/tasks/main.yaml
with
73 additions
and
0 deletions
basic/roles/secure-ssh/tasks/main.yaml
0 → 100644
+
73
−
0
View file @
b795616e
# Configure Fail2Ban
# Configure SSH with same port as fail2ban
-
name
:
Save ssh port
set_fact
:
ansible_host_port
:
"
{{
ansible_port
}}"
-
name
:
Change ssh port to
22
set_fact
:
ansible_port
:
22
-
name
:
Install System Tools
apt
:
pkg
:
-
fail2ban
state
:
latest
update_cache
:
yes
install_recommends
:
no
-
name
:
sshd configuration file update
lineinfile
:
path
:
/etc/ssh/sshd_config
regexp
:
"
^{{
item.key
}}"
line
:
"
{{
item.key
}}
{{
item.value
}}"
validate
:
/usr/sbin/sshd -T -f %s
with_items
:
-
{
key
:
"
PermitRootLogin"
,
value
:
"
no"
}
-
{
key
:
"
PasswordAuthentication"
,
value
:
"
no"
}
-
{
key
:
"
ClientAliveInterval"
,
value
:
"
300"
}
-
{
key
:
"
ClientAliveCountMax"
,
value
:
"
1"
}
-
{
key
:
"
AllowUsers"
,
value
:
"
{{
ansible_user
}}"
}
-
{
key
:
"
Port"
,
value
:
"
{{
ansible_host_port
}}"
}
-
{
key
:
"
MaxAuthTries"
,
value
:
"
2"
}
-
{
key
:
"
AllowTcpForwarding"
,
value
:
"
no"
}
-
{
key
:
"
X11Forwarding"
,
value
:
"
no"
}
-
{
key
:
"
AllowAgentForwarding"
,
value
:
"
no"
}
-
{
key
:
"
AuthorizedKeysFile"
,
value
:
"
.ssh/authorized_keys"
}
-
name
:
Enable service fail2ban
ansible.builtin.systemd
:
name
:
fail2ban
enabled
:
yes
state
:
started
-
name
:
copy fail2ban config
copy
:
src
:
/etc/fail2ban/jail.conf
dest
:
/etc/fail2ban/jail.local
remote_src
:
true
-
name
:
fail2ban configuration file update
lineinfile
:
path
:
"
/etc/fail2ban/jail.local"
firstmatch
:
true
regexp
:
"
^port.*=.*ssh$"
line
:
"
port
=
{{
ansible_host_port
}}"
-
name
:
fail2ban configuration file update
lineinfile
:
path
:
"
/etc/fail2ban/jail.local"
insertafter
:
|
^\[sshd\]
line
:
"
enabled
=
true"
-
name
:
Enable service fail2ban
ansible.builtin.systemd
:
name
:
fail2ban
enabled
:
yes
state
:
restarted
-
name
:
Restart SSHD
service
:
name
:
sshd
state
:
restarted
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment