A port of libssh2-1.11.1 for ESP32 platforms with dual framework support. This library works seamlessly with both Arduino/PlatformIO and ESP-IDF frameworks, automatically detecting the build environment and adapting accordingly.
- β Dual Framework Support: Arduino/PlatformIO and ESP-IDF
- β Automatic Framework Detection: No manual configuration needed
- β Unified API: Same code works in both frameworks
- β Complete SSH Functionality: All libssh2 features available
- β mbedTLS Backend: Secure cryptography with ESP32's built-in mbedTLS
- β Easy Integration: Simple include and use
- β Comprehensive Examples: Working examples for both frameworks
Perfect for Arduino IDE users and PlatformIO projects. Simply add as a library dependency.
Native ESP-IDF component support for professional development environments.
- PlatformIO: Add to your
platformio.ini:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
https://github.com/playmiel/libssh2_esp.git- Arduino IDE: Install via Library Manager or download as ZIP.
- As ESP-IDF managed component:
idf.py add-dependency playmiel/libssh2_esp- As git submodule:
# In your project's components/ directory
git submodule add https://github.com/playmiel/libssh2_esp.git
git submodule update --init --recursive#include <libssh2_esp.h>
void setup() { // or app_main() for ESP-IDF
// Initialize libssh2_esp
libssh2_esp_init();
// Framework is automatically detected
printf("Framework: %s\n", libssh2_esp_get_framework());
// Connect to SSH server
int sock = libssh2_esp_socket_connect("example.com", 22);
// Use standard libssh2 API
LIBSSH2_SESSION *session = libssh2_session_init();
libssh2_session_handshake(session, sock);
// ... rest of SSH operations
// Cleanup
libssh2_esp_cleanup();
}The library automatically adapts to your framework:
- Arduino: Uses
Serial.printf()for logging,WiFifor network - ESP-IDF: Uses
ESP_LOGI()for logging, native ESP-IDF networking
- Location:
examples/arduino/ - Features: WiFi connection, SSH authentication, command execution
- Build:
pio run -e esp32dev
- Location:
examples/espidf/ - Features: Native ESP-IDF WiFi, FreeRTOS tasks, SSH operations
- Build:
idf.py build
- Location:
examples/ssh2_exec/ - Features: Original example from upstream project
Configuration is automatic. Optional build flags:
build_flags =
-DLIBSSH2_MBEDTLS ; Use mbedTLS (default)
-DLIBSSH2_NO_ZLIB ; Disable compression
-DHAVE_LIBSSH2_H ; Enable libssh2 featuresConfigure via menuconfig:
idf.py menuconfig
# Navigate to: Component config > libssh2Options available:
- Cryptography engine: mbedTLS (recommended)
- Debug logging: Enable/disable debug output
- Compression: Enable/disable zlib compression
The library automatically detects your framework:
// Check current framework
const char* framework = libssh2_esp_get_framework();
// Returns: "Arduino" or "ESP-IDF"
// Framework-specific code (if needed)
#ifdef LIBSSH2_ESP_ARDUINO
// Arduino-specific code
#elif defined(LIBSSH2_ESP_IDF)
// ESP-IDF specific code
#endifint libssh2_esp_init(void)- Initialize libraryvoid libssh2_esp_cleanup(void)- Cleanup resourcesconst char* libssh2_esp_get_framework(void)- Get framework name
int libssh2_esp_socket_connect(const char* hostname, int port)- Create connectionvoid libssh2_esp_socket_close(int sock)- Close connection
All standard libssh2 functions are available. See libssh2 documentation.
- ESP32 Arduino Core 2.0+
- PlatformIO Core 6.0+ (for PlatformIO)
- ESP-IDF 4.4+
- CMake 3.16+
- Compilation errors: Ensure you have the correct framework version
- Network issues: Check WiFi credentials in examples
- SSH authentication: Verify server credentials and key formats
Enable debug logging to troubleshoot issues:
Arduino:
// Debug output goes to Serial
Serial.setDebugOutput(true);ESP-IDF:
# Enable debug logging in menuconfig
idf.py menuconfig
# Component config > Log output > Default log verbosity > DebugContributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Test with both Arduino and ESP-IDF
- Submit a pull request
Released under BSD-3-Clause license.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: Wiki