SSH Minimal Client Example
Overview
This NetBurner application demonstrates a minimal SSH client implementation that connects to an SSH server and reads data continuously until the connection is closed. The client establishes an encrypted SSH connection and can be used as a foundation for building more complex SSH-based applications.
Features
- Establishes SSH connection to a remote server
- User authentication with password
- Continuous data reading from SSH server
- Automatic reconnection on connection failure
- Built-in diagnostics and logging
- Certificate and key generation support
Configuration
Server Settings
The application is configured to connect to an SSH server using the following constants in main.cpp:
#define SSH_SERVER_NAME "10.1.1.131"
#define SSH_REMOTE_PORT 22
#define CONNECTION_TIMEOUT 120
Authentication
The application uses password-based authentication with these default credentials:
- Username: "guest" (specified in SshConnect call)
- Password: "TestPassword" (set in ClientUserAuth function)
Hardware Requirements
- NetBurner device with network connectivity
- Active network connection (DHCP or static IP)
- USB or Serial connection for monitoring
Setup Instructions
- Configure Target Server
- Update
SSH_SERVER_NAME with your SSH server's IP address
- Ensure the SSH server is running and accessible on port 22
- Verify firewall settings allow SSH connections
- Compile and Deploy
- Compile the application using NetBurner development tools
- Load the compiled firmware onto your NetBurner device
- Monitor Operation
- Connect to the device using MTTTY via USB or Serial port
- View connection status and received data in the terminal
Code Structure
Main Components
- UserMain(): Primary application entry point
- Initializes system components
- Configures SSH client settings
- Manages connection loop
- ClientUserAuth(): Authentication callback
- Called when server requests user credentials
- Returns username and password for authentication
Key Functions
Operation Flow
- System initialization and network setup
- SSH subsystem initialization
- Connection attempt to configured server
- User authentication when prompted
- Continuous data reading loop
- Connection monitoring and automatic reconnection
Buffer Configuration
The application uses a 4KB receive buffer:
#define RX_BUFSIZE (4096)
char RXBuffer[RX_BUFSIZE];
Task Stack
SSH operations use an extended stack size:
#define SSHSERVER_TASK_STACK_SIZE (USER_TASK_STK_SIZE * 4)
Troubleshooting
Common Issues
- Connection Failed: Verify server IP address and network connectivity
- Authentication Failed: Check username/password credentials
- Network Timeout: Ensure DHCP is working or configure static IP
- Certificate Errors: Verify certificate generation is enabled
Debug Output
The application provides detailed logging including:
- SSH initialization status
- Connection attempts and results
- Data received from server
- Connection closure notifications
Customization
Modifying Authentication
Update the ClientUserAuth() function to implement different authentication methods:
{
passwordPtr = "YourPassword";
return 1;
}
Lightweight alternative to C++ CString class.
Definition nbstring.h:118
Adding Data Processing
Extend the data reading loop in UserMain() to process received data:
if (n != 0)
{
printf("Read %d bytes: %s\n", n, RXBuffer);
}
Dependencies
Notes
- The application includes system diagnostics which should be disabled for production use
- Automatic certificate creation is enabled for SSL/TLS support
- The client will continuously attempt to reconnect if the connection is lost
- All received data is null-terminated and printed to the console