Here are the complete implementations for setting up SSM Session Manager (eliminating SSH port 22), automating Lynis via Cron with email delivery, and remediating key Prowler IAM findings.
1. Configure AWS SSM Session Manager (Disable SSH Port 22)
Using AWS Systems Manager (SSM) Session Manager allows you to open interactive shell sessions to your EC2 instances through the AWS Management Console or AWS CLI—without opening inbound port 22 in your Security Groups.
Step 1: Attach the SSM IAM Policy to your EC2 Role
- Open the AWS IAM Console > Roles.
- Select (or create) the IAM Role attached to your EC2 instance.
- Attach the AWS-managed policy:
AmazonSSMManagedInstanceCore.
Step 2: Verify the SSM Agent is Active
Amazon Linux 2/2023 and modern Ubuntu AMIs come with the SSM Agent pre-installed. You can verify its status on the host:
sudo systemctl status amazon-ssm-agent
Verification: The service status should show active (running).
Step 3: Remove SSH Port 22 Inbound Rule
- Open the AWS EC2 Console > Security Groups.
- Edit the Inbound Rules for your instance’s security group.
- Delete the rule allowing TCP port 22.
Step 4: Connect via SSM Session Manager
From your local machine (with AWS CLI and the Session Manager plugin
installed):
aws ssm start-session --target i-0123456789example
Verification: You will receive a secure interactive bash prompt inside the instance over AWS HTTPS APIs without any open inbound ports.
2. Automate Lynis Audits via Cron with Email Reports
This setup automates a weekly Lynis security scan and emails the summarized report to your system administrator.
Step 1: Install Mail Utilities
Ensure mailx or postfix/mailutils is installed on your server:
# Amazon Linux / RHEL / CentOS:sudo dnf install -y s-nail# Ubuntu / Debian:sudo apt-get update && sudo apt-get install -y mailutils
Step 2: Create the Automated Audit Script (/usr/local/bin/cron_lynis.sh)
Create the script using your preferred editor:
#!/bin/bash# Description: Runs Lynis weekly audit and emails the report summaryADMIN_EMAIL="admin@example.com"REPORT_FILE="/var/log/lynis-reports/weekly_report.log"mkdir -p /var/log/lynis-reports# Run Lynis audit non-interactivelylynis audit system --quick --warnings-only > "${REPORT_FILE}"# Send report via emailmail -s "Weekly Lynis Security Audit Report - $(hostname)" "${ADMIN_EMAIL}" < "${REPORT_FILE}"
Make the script executable:
sudo chmod +x /usr/local/bin/cron_lynis.sh
Step 3: Schedule a Weekly Cron Job
Open the root user’s crontab:
sudo crontab -e
Add the following entry to run the script every Sunday at 2:00 AM:
Code snippet
0 2 * * 0 /usr/local/bin/cron_lynis.sh >/dev/null 2>&1Verification: Test the script execution manually by running sudo /usr/local/bin/cron_lynis.sh and checking /var/log/lynis-reports/weekly_report.log as well as your email inbox.
Verification: Test the script execution manually by running sudo /usr/local/bin/cron_lynis.sh and checking /var/log/lynis-reports/weekly_report.log as well as your email inbox.
3. Remediate Critical Prowler IAM Findings
Below are the three most frequent high-severity IAM flags reported by Prowler and their respective remediation steps.
Finding 1: iam_user_console_access_unused / Inactive IAM Users with Console/Access Keys
- The Risk: Inactive credentials increase the attack surface for credential theft and unauthorized access.
- Remediation: Enforce a policy to deactivate credentials unused for >90 days.
Bash# Delete or deactivate unused access keys via AWS CLI aws iam update-access-key --user-name <username> --access-key-id <key-id> --status Inactive
Finding 2: iam_policy_no_star_privileges / Policies containing AdministratorAccess or Wildcards ("Action": "*")
- The Risk: Violates the principle of least privilege, allowing compromised instances or roles full control over the AWS account.
- Remediation: Replace overly permissive inline or attached policies with scoped-down IAM policies.
- Example fix: Limit S3 operations to a single bucket rather than all AWS resources:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:PutObject" ], "Resource": "arn:aws:s3:::my-app-logs-bucket/*" } ] }
Finding 3: iam_root_hardware_mfa_enabled / Root Account Active or Missing MFA
- The Risk: The root account has unrestricted access to all resources and billing. If compromised without Multi-Factor Authentication (MFA), the entire cloud environment can be lost.
- Remediation:
- Log into the AWS Console as the Root User.
- Navigate to IAM > Dashboard > Root user environment.
- Enable MFA using a hardware key (FIDO2/YubiKey) or virtual authenticator app.
- Delete all root access keys and lock down root usage exclusively for emergency tasks.
Verification: Re-run Prowler specifically targeting IAM checks to verify remediations:
prowler aws --services iam

