Create restricted SSH users that can only create tunnels (SOCKS proxy, local port forwarding).
- Creates system users with no shell access, no home directory
- Configures sshd with hardened settings for tunnel users
- Supports both password and SSH key authentication
- Auto-generates secure passwords in interactive mode
- Installs and configures fail2ban for brute-force protection
- Blocks cron/at access for tunnel users
- Users can only create
-L(local) and-D(SOCKS) tunnels, not-R(remote)
curl -sSL https://raw.githubusercontent.com/net2share/sshtun-user/main/install.sh | sudo bashgo build -o sshtun-user ./cmd/sshtun-user
sudo mv sshtun-user /usr/local/bin/sudo sshtun-user
# or
sudo sshtun-user <username>Prompts for username (if not provided), authentication method, and password. If fail2ban is not installed, prompts to install it.
# With password (warning: visible in process list)
sudo sshtun-user <username> --insecure-password <password>
# With SSH public key
sudo sshtun-user <username> --pubkey "ssh-ed25519 AAAA..."
# SSHD hardening only (no user creation)
sudo sshtun-user --configure-only
# Disable fail2ban
sudo sshtun-user <username> --no-fail2banNote: In non-interactive mode (when using --insecure-password or --pubkey), the username argument is required.
| Option | Description |
|---|---|
--insecure-password <pass> |
Set password (visible in process list/history) |
--pubkey <key> |
Set SSH public key for key-based auth |
--no-fail2ban |
Skip fail2ban installation/configuration |
--configure-only |
Only apply sshd hardening, no user creation |
--version, -v |
Show version |
--help, -h |
Show help |
After creating a tunnel user, clients can connect:
# SOCKS proxy on local port 1080
ssh -D 1080 -N tunneluser@server
# Local port forwarding
ssh -L 8080:internal-host:80 -N tunneluser@serverFor key-based auth, add -i <private_key>.
- Modern crypto algorithms only (curve25519, chacha20-poly1305, aes256-gcm)
- Connection rate limiting and keepalive
- Disabled: X11 forwarding, agent forwarding, remote forwarding, PTY
- ForceCommand prevents shell access
- Verbose logging for audit trails
sshtunnel-password: Users with password authenticationsshtunnel-key: Users with SSH key authentication
- Users are added to
/etc/cron.denyand/etc/at.denyto prevent scheduled tasks - Users are created as system users with
/usr/sbin/nologinshell
- Bans IPs after 5 failed attempts in 10 minutes
- 1-hour ban, doubling for repeat offenders (max 1 week)
- Fedora, RHEL, CentOS, Rocky, Alma, Oracle Linux (dnf/yum)
- Debian, Ubuntu, Linux Mint, Pop!_OS (apt)
- Arch, Manjaro, EndeavourOS (pacman)
- openSUSE, SLES (zypper)
- Alpine (apk)