Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
126 changes: 78 additions & 48 deletions SOLUTION.MD
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# SSH Connection and Security Best Practices Lab - Solution

**Student Name:** [Your Name]
**Date Completed:** [Date]
**Student Name:** Adnan Nooruddin
**Date Completed:** 15.07.2026

---

## Instance Details

- **Instance ID:** [i-xxxxxxxxxxxxx]
- **Instance ID:** [i-065ea8bd543565000]
- **Public IP:** [x.x.x.x — redact if repo is public]
- **Security Group:** [week2-web-server-sg]
- **Key Pair:** [bootcamp-week2-key.pem]
Expand All @@ -20,10 +20,16 @@

**My `~/.ssh/config`:**
```
[Paste your host entry here]
# Week 2 EC2 Instance
Host bootcamp-web
HostName 16.171.177.74
User ec2-user
IdentityFile ~/.ssh/bootcamp-week2-key.pem
ServerAliveInterval 60
ServerAliveCountMax 3
```

- [ ] Connected using the alias: `ssh bootcamp-web`
- [X] Connected using the alias: `ssh bootcamp-web`

---

Expand All @@ -33,23 +39,23 @@

| Test | Expected | Result |
|------|----------|--------|
| `ssh bootcamp-web` | ✅ Connects | [ ] |
| `curl -I http://YOUR_PUBLIC_IP` | ✅ HTTP 200 | [ ] |
| `ping YOUR_PUBLIC_IP` | ❌ Timeout | [ ] |
| `nc -zv YOUR_PUBLIC_IP 3306` | ❌ Blocked | [ ] |
| `ssh bootcamp-web` | ✅ Connects | [X] |
| `curl -I http://YOUR_PUBLIC_IP` | ✅ HTTP 200 | [X] |
| `ping YOUR_PUBLIC_IP` | ❌ Timeout | [X] |
| `nc -zv YOUR_PUBLIC_IP 3306` | ❌ Blocked | [X] |

**Why did ping and port 3306 fail?**

[Your answer]
ping failed because AWS security groups do not allow ICMP traffic by default. If the security group does not have an inbound rule allowing ICMP Echo Requests, the instance will not respond to ping. Some AWS services, such as Amazon RDS, also do not respond to ICMP ping even when they are reachable over the network.

---

## Step 3: Modify Security Group Rules

![Security Group Edit](Screenshots/security-group-edit.png)

- [ ] Added HTTPS rule (port 443, source 0.0.0.0/0)
- [ ] Tested it — what happened? [Your answer]
- [x] Added HTTPS rule (port 443, source 0.0.0.0/0)
- [X] Tested it — what happened? curl: (7) Failed to connect to 16.171.230.235 port 443 after 1 ms: Could not connect to server
- [ ] Removed the HTTPS rule again

---
Expand All @@ -58,26 +64,39 @@

**What these settings do:**

- `ServerAliveInterval 60` — [Your answer]
- `ServerAliveCountMax 3` — [Your answer]
- `TCPKeepAlive yes` — [Your answer]
- `Compression yes` — [Your answer]
- `ServerAliveInterval 60` — send keep alive every 60 seconds
- `ServerAliveCountMax 3` — disconnect after 3 failed alives
- `TCPKeepAlive yes` — enabled TCP keep alive
- `Compression yes` — compress data

**Idle for 2 minutes — did the connection stay alive?** [Yes / No]
**Idle for 2 minutes — did the connection stay alive?** yes

---

## Step 5: Practice SCP (Secure Copy)

![SCP File Transfer](Screenshots/scp-file-transfer.png)

- [ ] Copied a file TO the instance
- [ ] Copied a file FROM the instance
- [ ] Copied a whole directory
- [X] Copied a file TO the instance
- [X] Copied a file FROM the instance
- [X] Copied a whole directory

**Commands I used:**
```bash
[Paste your scp commands here]
scp test-file.txt bootcamp-web:~/


ssh bootcamp-web "cat ~/test-file.txt"

scp bootcamp-web:~/instance-info.txt ./downloaded-info.txt

cat downloaded-info.txt

mkdir my-website\necho "<h1>My Site</h1>" > my-website/index.html\necho "body { background: lightblue; }" > my-website/style.css

scp -r my-website bootcamp-web:~/

ssh bootcamp-web "ls -la ~/my-website/"
```

---
Expand All @@ -88,14 +107,16 @@

**Output of `sudo sshd -T | grep -i "passwordauthentication\|permitrootlogin\|pubkeyauthentication"`:**
```
[Paste output here]
permitrootlogin without-password
pubkeyauthentication yes
passwordauthentication no
```

| Setting | Expected | Actual |
|---------|----------|--------|
| PasswordAuthentication | no | [ ] |
| PermitRootLogin | without-password | [ ] |
| PubkeyAuthentication | yes | [ ] |
| PasswordAuthentication | no | no |
| PermitRootLogin | without-password | without-password |
| PubkeyAuthentication | yes | yes |

> Only verify these settings — do not modify `sshd_config`.

Expand All @@ -105,10 +126,19 @@

**My `connect-bootcamp.sh`:**
```bash
[Paste your script here]
#!/bin/bash
# Quick connection script for bootcamp instance

# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

echo -e "${BLUE}Connecting to bootcamp instance...${NC}"
ssh bootcamp-web
```

- [ ] Made it executable and tested it
- [X] Made it executable and tested it

---

Expand All @@ -120,12 +150,12 @@

| Port | Source | Purpose |
|------|--------|---------|
| [22] | [YOUR_IP/32] | [SSH access] |
| [22] | [89.245.17.90/32] | [SSH access] |
| [80] | [0.0.0.0/0] | [Web traffic] |

**Is this configuration secure? What would you improve?**

[Your answer]
The security group is reasonably secure because SSH access is restricted to my public IP address instead of being open to the Internet, while HTTP is open to allow users to access the website. The outbound rule allows all traffic, which is the default AWS configuration. To improve security, I would add an HTTPS (port 443) rule and configure SSL/TLS for encrypted communication, continue following the principle of least privilege by opening only required ports and enable monitoring services such as CloudTrail and CloudWatch to audit and monitor access.

---

Expand Down Expand Up @@ -158,49 +188,49 @@

### 1. Why use an SSH config file instead of typing the full command every time?

[Your answer]
Using an SSH config file simplifies the connection process by storing the hostname, username, and private key in one place. Instead of typing a long SSH command each time, I can connect using a short alias such as ssh bootcamp-web. It also reduces typing errors and makes managing multiple servers easier.

### 2. Why restrict SSH to your IP instead of 0.0.0.0/0?

[Your answer]
Restricting SSH access to my public IP address reduces the attack surface by allowing only my computer to connect to the server. Allowing 0.0.0.0/0 would expose the SSH service to the entire Internet, increasing the risk of brute-force attacks and unauthorized access.

### 3. What did the blocked ping and port 3306 tests teach you about security groups?

[Your answer]
The tests showed that AWS Security Groups act as virtual firewalls that control network traffic. If ICMP (ping) or port 3306 (MySQL) is not explicitly allowed, the traffic is blocked. This demonstrates the principle of least privilege, where only the necessary ports are opened to improve security.

### 4. Why disable password authentication for SSH?

[Your answer]
Disabling password authentication makes SSH more secure because it requires a private key instead of a password. SSH keys are much harder to guess or crack than passwords, reducing the risk of brute-force attacks and unauthorized access.

---

## Key Learnings

**What was most challenging about this lab?**

[Your reflection]
The most challenging part was configuring networking and security correctly. Understanding how Security Groups, SSH keys, inbound rules, and AWS CLI work together required careful troubleshooting. It helped me understand how small configuration changes can affect connectivity and security.

**What security practice will you always follow from now on?**

[Your reflection]
I will always follow the principle of least privilege by granting only the minimum permissions required. I will also restrict SSH access to my own IP address, use SSH key authentication instead of passwords, and open only the ports that are necessary for the application. These practices help protect cloud resources from unauthorized access and improve overall security.

---

## Checklist

- [ ] SSH config file working with alias
- [ ] Security group tests done and documented
- [ ] Security group rule added and removed
- [ ] SCP tested both directions
- [ ] SSH daemon settings verified
- [ ] Connection script created
- [ ] Security group audited
- [ ] All screenshots captured
- [ ] Reflection questions answered
- [ ] Work committed to Git
- [ ] Pull request created
- [x] SSH config file working with alias
- [x] Security group tests done and documented
- [x] Security group rule added and removed
- [x] SCP tested both directions
- [x] SSH daemon settings verified
- [x] Connection script created
- [x] Security group audited
- [x] All screenshots captured
- [x] Reflection questions answered
- [x] Work committed to Git
- [x] Pull request created

---

**Completed By:** [Your Name]
**Date:** [Date]
**Completed By:** Adnan Nooruddin
**Date:** 15.07.2026
Binary file added Screenshots/scp-file-transfer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/security-group-audit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/security-group-edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/security-tests.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/ssh-config-working.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/ssh-hardening.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.