A modern, dependency-free bash utility for scanning and managing SSH connections to hosts on local networks.
- Fast Network Scanning: Automatically discover SSH-enabled hosts on your local network
- Parallel Scanning: Scan multiple hosts simultaneously for faster results
- Flexible Connection: Connect using full IPs or short notation (e.g.,
lhssh 152
) - Command Execution: Run commands on remote hosts directly
- Colored Output: Easy-to-read results with optional color coding
- Configurable: Customize scan ranges, timeouts, and display preferences
- No External Dependencies: Pure bash implementation (beyond standard SSH tools)
- Bash 5.0 or later
- SSH client (OpenSSH)
- Either
ssh-keyscan
ORnc
(netcat) for network scanning timeout
command (part of GNU coreutils)- Standard Unix tools:
sed
,grep
,cut
,sort
,xargs
- Clone or download the repository:
git clone https://github.com/Open-Technology-Foundation/lhssh.git
cd lhssh
- Make the scripts executable:
chmod +x lhssh lhssh-cmd
- Create symlinks in your PATH:
sudo ln -s $(pwd)/lhssh /usr/local/bin/lhssh
sudo ln -s $(pwd)/lhssh-cmd /usr/local/bin/lhssh-cmd
Copy the scripts to a directory in your PATH:
sudo cp lhssh lhssh-cmd /usr/local/bin/
sudo chmod +x /usr/local/bin/lhssh /usr/local/bin/lhssh-cmd
- Scan your network for SSH hosts:
lhssh
- Connect to a host using short notation:
lhssh 152 # Connects to 192.168.1.152
- Run a command on a remote host:
lhssh 152 uptime
- Show only IP addresses:
lhssh -s # Show full IPs
lhssh -p # Show last octet only
lhssh [OPTIONS] [IP [COMMAND...]]
-s, --short
- Show IP addresses only (no hostnames)-p, --supershort
- Show only last octet of IP addresses-C, --no-color
- Disable colored output-v, --verbose
- Enable verbose output (use -vv for debug)-q, --quiet
- Disable all non-essential output
-n, --network PREFIX
- Set network prefix (default: 192.168.1.)-b, --begin IP
- Start IP for scanning (default: 50)-f, --finish IP
- End IP for scanning (default: 230)
-u, --user USERNAME
- SSH username (default: current user)-t, --timeout SECS
- Connection timeout (default: 10)-T, --session-time SECS
- Session timeout (default: 600)
-l, --list
- Show current configuration-e, --edit
- Edit configuration file-S, --save-config
- Save current options to configuration
-h, --help
- Show help message-V, --version
- Show version information
Scan a different network range:
lhssh -n 10.0.0. -b 1 -f 50
Quick scan with short output:
lhssh -p
Connect as different user:
lhssh -u admin 152
Execute command on all discovered hosts:
for ip in $(lhssh -p); do
echo "=== Host .$ip ==="
lhssh $ip hostname -f
done
Use with lhssh-cmd for parallel execution:
lhssh-cmd "df -h" # Run on all discovered hosts
lhssh stores its configuration in ~/.lhssh.conf
. You can edit this file directly or use the built-in options.
# Network prefix (must end with dot)
LOCALHOST_HEAD='192.168.1.'
# IP range to scan (last octets)
LOCALHOST_START_IP=50
LOCALHOST_END_IP=230
# SSH login username
LOGIN_USERNAME='root'
# Display preferences
SHORT_DISPLAY=0 # 0=detailed, 1=IPs only
SUPER_SHORT=0 # 0=full IPs, 1=last octet only
# Timeouts (in seconds)
SSH_CONNECT_TIMEOUT=10
SSH_SESSION_TIMEOUT=600
# Features
COLOR_OUTPUT=1 # 0=disable, 1=enable
PARALLEL_SCAN=1 # 0=sequential, 1=parallel
Generate a new configuration file with default values:
lhssh -S
lhssh -e # Opens in default editor
lhssh supports combining short options:
lhssh -vp # Verbose + supershort display
Scan a specific range on your current network:
lhssh -b 100 -f 200 # Scan .100 to .200
Run commands on multiple specific hosts:
for host in 152 153 160; do
lhssh $host "systemctl status sshd"
done
Use lhssh output with other commands:
# Find hosts with specific service
lhssh -p | xargs -I{} sh -c 'lhssh {} "systemctl is-active nginx" 2>/dev/null | grep -q active && echo {}'
# Copy file to all hosts
for ip in $(lhssh -p); do
scp myfile.txt [email protected].$ip:/tmp/
done
- Check network connectivity:
ip addr show
ping 192.168.1.1
- Verify SSH service on target hosts:
systemctl status sshd # On target host
- Test scanning tools:
which ssh-keyscan nc
ssh-keyscan -T 1 192.168.1.1
- Try verbose mode:
lhssh -v
- Check SSH keys:
ssh-keygen -t rsa # Generate if needed
ssh-copy-id user@host # Copy to target
- Verify username:
lhssh -u correctuser 152
- Increase timeout:
lhssh -t 30 152 # 30 second timeout
- Disable parallel scanning:
# Edit config
lhssh -e
# Set PARALLEL_SCAN=0
- Reduce scan range:
lhssh -b 100 -f 150 # Smaller range
- lhssh uses key-based authentication only (
PasswordAuthentication=no
) - Configuration file is created with 600 permissions
- SSH host key checking is set to
accept-new
for convenience
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
- Complete refactor to remove external dependencies
- Added parallel scanning support
- Improved error handling and logging
- Enhanced configuration system
- Better shellcheck compliance
- Initial release with nmap dependency
- Basic scanning and connection features
GPL-3 License - see LICENSE file for details
For issues, questions, or contributions:
- GitHub Issues: https://github.com/Open-Technology-Foundation/lhssh/issues
- Email: [email protected]