Example Path: examples/SSH/sshMinimalServer
SSH Minimal Server Example
Overview
This NetBurner application implements a minimal SSH server that listens for incoming SSH client connections on TCP port 22. The server demonstrates basic SSH functionality using the NetBurner's built-in SSH library and certificate management system.
Enabling SSH
SSH is off by default. This example ships one file that turns it on:
overload/nbrtos/include/predef-overload.h
#define NB_SSH_SUPPORTED (1)
predef.h includes predef-overload.h on its last line, so the definition gets the final word without editing the shared SDK header. The build system searches the project's overload directory before the SDK, and finds the file by name. Run make clean the first time, then rebuild.
Without this file the example does not build. See Overload Directory & System Files and Modifying System Files with Overload.
Features
- SSH server listening on port 22
- Automatic certificate and key generation
- Bidirectional communication between SSH client and server
- Serial console integration for monitoring and sending data
- Connection timeout handling (120 seconds)
- TCP error state reporting
- Multi-client support with connection queuing
Architecture
The application consists of two main components:
SSH Server Task
- Runs as a separate high-priority task
- Listens for incoming SSH connections
- Handles client authentication and session management
- Processes incoming data from SSH clients
- Manages connection lifecycle and cleanup
Main User Interface
- Provides serial console interface for monitoring
- Allows sending data to connected SSH clients via keyboard input
- Displays connection status and diagnostic information
Usage Instructions
Setup
- Compile and load the application into your NetBurner device
- Ensure the device is connected to your network
- Run MTTTY or similar terminal emulator to connect to the device's USB/Serial port
Connecting SSH Clients
- Use any SSH client (PuTTY, OpenSSH, etc.)
- Connect to the NetBurner device's IP address on port 22
- The server will display a welcome message: "Welcome to the NetBurner SSH Server"
- Connection details will be shown on both the SSH client and serial console
Sending Data
- From Serial Console: Type ASCII strings followed by Enter to send data to connected SSH clients
- From SSH Client: Any data sent from the SSH client will be displayed on the serial console
Configuration
Key Parameters
- SSH_LISTEN_PORT: Server listening port (default: 22)
- CONNECTION_TIMEOUT: Inactivity timeout in seconds (default: 120)
- BUFSIZE: Buffer size for data transmission (default: 4096 bytes)
Security
- Uses NetBurner's built-in SSH key management
- Automatic certificate creation is enabled via EnableOnboardCertificateCreation()
- Standard SSH encryption and authentication protocols
Error Handling
The application includes comprehensive error handling for various TCP and SSH conditions:
- TCP connection errors (timeout, reset, abort)
- SSH negotiation failures
- Session establishment failures
- Socket availability issues
- Connection timeouts
Error states are reported through the serial console with descriptive messages.
Technical Details
Memory Usage
- SSH Server task stack: 4x standard user task stack size
- Separate receive and transmit buffers (4KB each)
- Efficient memory management with proper cleanup
Network Interface
- Automatically detects and uses the first available network interface
- Displays IP address and interface information on startup
- Supports standard Ethernet connections
Task Management
- SSH server runs at higher priority than UserMain
- Proper task synchronization and resource management
- Clean connection handling and resource cleanup
Dependencies
Build Requirements
- NetBurner development environment
- SSH library support enabled in NetBurner configuration
- Certificate generation support
Troubleshooting
Common Issues
- Connection refused: Verify network connectivity and firewall settings
- Authentication failures: Check SSH key configuration
- Timeouts: Adjust CONNECTION_TIMEOUT value if needed
- Memory issues: Monitor task stack usage and buffer sizes
Diagnostic Features
- System diagnostics are enabled for development (consider disabling for production)
- Detailed error reporting through serial console
- Connection state monitoring and logging