diff --git a/ssh/README.md b/ssh/README.md index b96bbba..7da040d 100644 --- a/ssh/README.md +++ b/ssh/README.md @@ -1,78 +1,43 @@ -# Multi-Instance SSH Server Generator -A lightweight Bash script that automatically creates, configures, and manages completely isolated OpenSSH server instances on Linux. - -Perfect for providing dedicated SSH access to specific teams, contractors, or applications without touching your primary server's SSH configuration. +# Multi-Instance SSH Server Manager +A lightweight Bash suite that automatically creates, configures, and safely removes completely isolated OpenSSH server instances on Linux. +Perfect for providing dedicated SSH access to specific users, teams, or applications without modifying your primary server's SSH configuration. ## Features - +* **User Restriction:** Prompts for a username during setup, optionally creates the user, and uses `AllowUsers` to restrict the instance exclusively to them. * **Complete Isolation:** Each instance gets its own configuration directory (`/opt/custom_sshd/`) and independent host keys. * **Auto-Port Assignment:** Automatically scans for the next available port starting from `2222` to prevent collisions. * **Systemd Integration:** Generates a dedicated `systemd` service for each instance so they start on boot and auto-restart if they crash. -* **Auto-Firewall:** Detects your active firewall (`ufw`, `firewalld`, or `iptables`) and automatically opens the required TCP port. +* **Auto-Firewall Management:** Detects your active firewall (`ufw`, `firewalld`, or `iptables`) to open the port on creation, and cleanly closes it on removal. -## Prerequisites - -* A Linux distribution using `systemd` -* Root privileges (`sudo`) -* `sshd` (OpenSSH Server) installed - -## Usage - -1. **Make the script executable:** +## Setup +Make both scripts executable: ```bash - chmod +x create_ssh_service.sh - +chmod +x create_ssh_service.sh +chmod +x remove_ssh_service.sh ``` -2. **Create a new SSH instance:** -Pass the desired name of your instance as the only argument. -```bash -sudo ./create_ssh_service.sh dev_team +## Creating an Instance +Pass the desired name of your instance as the argument. You will be prompted to specify (and optionally create) the user who is allowed to connect. +```bash +sudo ./create_ssh_service.sh contractor ``` - -3. **Connect to your new instance:** -The script will output the assigned port (e.g., `2222`). Use it to connect: +**Connection Example:** ```bash -ssh -p 2222 username@your-server-ip - +ssh -p 2222 bob@your-server-ip ``` -## Management & Maintenance +## Removing an Instance +To cleanly tear down an instance, close its firewall port, remove its systemd service, and optionally delete the user data: +```bash +sudo ./remove_ssh_service.sh contractor +``` + +## Manual Service Management Every instance runs as its own systemd service named `custom-sshd-.service`. - -**Check status:** - -```bash -sudo systemctl status custom-sshd-dev_team.service - -``` - -**View live logs:** - -```bash -sudo journalctl -u custom-sshd-dev_team.service -f - -``` - -**Restart the instance:** - -```bash -sudo systemctl restart custom-sshd-dev_team.service - -``` - -**Completely remove an instance:** - -```bash -sudo systemctl disable --now custom-sshd-dev_team.service -sudo rm /etc/systemd/system/custom-sshd-dev_team.service -sudo rm -rf /opt/custom_sshd/dev_team -sudo systemctl daemon-reload - -``` - -Note: If you uninstall, you will need to manually remove the port rule from your firewall. +* **Check status:** `sudo systemctl status custom-sshd-contractor.service` +* **View logs:** `sudo journalctl -u custom-sshd-contractor.service -f` +* **Restart:** `sudo systemctl restart custom-sshd-contractor.service`