A Bash script that installs and configures OpenSSH with support for multiple SSH ports.
It compiles OpenSSh from source, modifies the MAX_LISTEN_SOCKS limit, creates a new systemd service (sshnew), and automatically opens a user-defined number of SSH ports.
- Installs OpenSSH 8.6p1 from source.
- Modifes
MAX_LISTEN_SOCKSto support multiple listening ports. - Creates a dedicated systemd service (
sshnew) separate from the defaultssh. - Automatically generates a configuration with random SSH ports.
- Provides helper script
openports.shfor regenerating port configuration. - Validates SSH configuration before starting the service.
- Supports root login and password authentication by default (customizable).
- Debian/Ubuntu-based system (APT package manager).
- Root privileges (
sudo). - Internet connection (to download OpenSSH sources).
Clone the repository and run the script:
git clone https://github.com/Hanashiko/setup-ssh-multiport.git
cd setup-ssh-multiport
chmod +x setup_ssh_multiport.sh
sudo ./setup_ssh_multiport.sh During installation, the script will prompt you for:
- Number of SSH ports to open (default: 30).
- Port range (
minandmax, defaults:2000-65000). - Confirmation before proceeding with compilation and setup.
After installation, a new SSH service will be available:
- Service name:
sshnew - Main config file:
/opt/openssh-9.6p1/etc/sshd_config - Ports configuration:
/opt/openssh-9.6p1/etc/sshd_config.d/70-ports.conf - Port regeneration script:
/opt/openssh-9.6p1/openports.sh
cat /opt/openssh-9.6p1/etc/sshd_config.d/70-ports.confbash /opt/openssh-9.6p1/openports.shsystemctl status sshnew systemctl restart sshnewjournalctl -u sshnew -fAfter installation, you'll see a summary like:
┌─────────────────────────────────────┐
│ OPEN PORTS │
├─────────────────────────────────────┤
│ 1. SSH Port: 22 │
│ 2. SSH Port: 23456 │
│ 3. SSH Port: 34567 │
│ ... │
├─────────────────────────────────────┤
│ Total ports: 30 │
└─────────────────────────────────────┘- By default, the script enabes root login and password authentication. You should adjuct
/opt/openssh-9.6p1/etc/sshd_configfor production security. - Make sure your fiewall (UFW/iptables/Firewalld/SELinux) is configred to allow the newly opened ports.
- Keep OpenSSH updated to avoid security vulnerablities.
To remove the custom OpenSSH installation:
systemctl stop sshnew
systemctl disable sshnew
rm -rf /opt/openssh-9.6p1
rm -f /lib/systemd/system/sshnew.service
systemctl daemon-reloadThis project is released under the MIT License.