Securing SSH with Tailscale for Pangolin VPS
Overview
This guide explains how to secure SSH access on your Pangolin VPS using Tailscale and includes instructions for both OpenSSH and PuTTY users. The setup script creates a secure user, disables password authentication, and binds SSH to your Tailscale network.
Prerequisites
- A running Pangolin VPS
- Tailscale installed and authenticated on your VPS
- Root access to your VPS
- Tailscale installed on your local machine
- (For Windows users) PuTTY installed
Important Security Notes
- This script will disable password authentication completely
- SSH will only be accessible through your Tailscale network
- A new secure user will be created with limited sudo privileges
- The original SSH configuration will be backed up
- Recovery requires access to either:
- An existing SSH session
- VPS provider’s console access
- The backup SSH configuration
Step-by-Step Implementation Guide
1. Preparation (CRITICAL)
Before running the script:
- Ensure you have an active terminal session to your VPS
- Keep the terminal session open until verification is complete
- Verify Tailscale is running:
tailscale status - Note your current SSH access method for emergency recovery
2. Tailscale Authentication
When you first run the script, it will check if Tailscale is authenticated. If not:
- The script will present a Tailscale authentication link
- Open this link in your browser
- Log in to your Tailscale account
- Authorize the machine
- Wait for the script to confirm the authentication
3. Running the Script
# Download the script
wget -O bind-ssh-tailscale.sh https://gist.githubusercontent.com/hhftechnology/5949d566fdb5377d21b49d39a82de36f/raw/3637a8a9fa66c7af88592f17d191233429a1ed3a/bind-ssh-tailscale.sh
# Make it executable
chmod +x bind-ssh-tailscale.sh
# Run the script
sudo ./bind-ssh-tailscale.sh
4. During Script Execution
- The script will create a new secure user
- CRITICAL: When the SSH private key is displayed:
- Copy it immediately
- Store it securely (password manager recommended)
- Verify you have copied it correctly before proceeding
- The script will wait for your confirmation
5. SSH Key Setup Based on Your Client
For OpenSSH Users (Linux/Mac/Windows with OpenSSH)
- Save the private key to a file (e.g.,
~/.ssh/pangolin_key) - Set correct permissions:
chmod 600 ~/.ssh/pangolin_key - Test connection:
ssh -i ~/.ssh/pangolin_key secureuser@YOUR_TAILSCALE_IP
For PuTTY Users (Windows)
-
Converting the Key to PPK Format
Using PuTTYgen GUI:
- Open PuTTYgen
- Click “Load”
- Change file filter to “All Files (.)”
- Select your private key file
- Click “Save private key”
- Choose “Yes” when asked about saving without a passphrase (though adding one is recommended)
- Save the file with a .ppk extension
Using Command Line:
# If you haven't installed PuTTY tools: sudo apt-get install putty-tools # Convert the key puttygen private_key -o converted_key.ppk -
Connecting with PuTTY:
- Open PuTTY
- Go to Connection → SSH → Auth → Credentials
- Browse and select your .ppk file under “Private key file for authentication”
- Set the connection details:
- Host Name: Your Tailscale IP
- Port: 22
- Username: secureuser
- (Optional) Save the session for quick access
6. Verification Steps
After the script completes:
- Keep your original SSH session open
- Open a new terminal/PuTTY window
- Test SSH access using Tailscale IP
- Only close original session after successful connection test
7. Emergency Recovery
If you lose access:
- Use your original SSH session to revert changes:
# Find the backup file
ls -l /etc/ssh/sshd_config.backup.*
# Restore the backup
sudo cp /etc/ssh/sshd_config.backup.[TIMESTAMP] /etc/ssh/sshd_config
# Restart SSH
sudo systemctl restart sshd
Security Features Implemented
- SSH bound to Tailscale IP only
- Password authentication disabled
- Root login restricted to key-based authentication
- Secure user created with limited sudo access
- Custom SSH configuration with security enhancements:
- Protocol 2 only
- Empty passwords prohibited
- Maximum 3 authentication attempts
- Client alive interval: 300 seconds
- X11 forwarding enabled only for secure user
Best Practices
- Regular key rotation
- Keep Tailscale and system updated
- Monitor SSH access logs
- Maintain backup access method (e.g., VPS provider’s console)
- Document recovery procedures
- Test access regularly
- Store SSH keys securely:
- Use a password manager for private keys
- Keep backup copies in secure locations
- Consider using hardware security keys
Troubleshooting
General Issues
- Verify Tailscale status on both machines
- Check SSH key permissions (should be 600)
- Verify SSH service is running
- Check firewall rules
- Verify correct Tailscale IP
PuTTY-Specific Issues
- Ensure key is properly converted to .ppk format
- Check PuTTY event log for connection issues
- Verify username is set correctly in PuTTY configuration
- Confirm Tailscale IP is correct
- If using a passphrase, ensure it’s entered correctly
Common Error Messages
- “Server refused our key”: Check if the key was properly copied and converted
- “No supported authentication methods available”: Ensure password authentication is not being attempted
- “Network error: Connection timed out”: Check Tailscale connectivity
- “Host key verification failed”: May need to clear known_hosts entry
Regular Maintenance
- Check SSH logs periodically:
sudo journalctl -u sshd - Monitor failed login attempts
- Update SSH keys every 6-12 months
- Keep backup recovery procedures updated
- Test recovery procedures quarterly