A lightweight SSH honeypot/server implementation written in C using the libssh library. This project demonstrates low-level SSH server development for security research, network testing, and educational purposes.
- Native C implementation for performance
- Multi-threaded connection handling with pthreads
- Password-based authentication
- Interactive shell session support
- Custom command handling
- Non-blocking channel I/O
- Clean session management and cleanup
- GCC or compatible C compiler
- libssh development libraries
- pthread library (usually included with GCC)
- Linux/Unix environment (or WSL on Windows)
- Clone the repository:
git clone https://github.com/vibheksoni/libssh-c-example.git
cd libssh-c-example- Install libssh development libraries:
Ubuntu/Debian:
sudo apt-get install libssh-devFedora/RHEL:
sudo dnf install libssh-develmacOS:
brew install libssh- Generate SSH host key:
mkdir ssh_keys
ssh-keygen -t rsa -b 2048 -f ssh_keys/rsa.key -N ""Compile the project using GCC:
gcc -o ssh_server main.c ssh.c user.c -lssh -lpthreadOr use the provided Makefile if available:
makeRun the SSH server with host, key path, and port:
./ssh_server 0.0.0.0 ./ssh_keys/rsa.key 2222Connect using any SSH client:
ssh admin@localhost -p 2222Default credentials:
- Username:
admin - Password:
admin
libssh-c-example/
├── main.c # Entry point and argument parsing
├── ssh.c # SSH server configuration and connection handler
├── user.c # User authentication and session management
├── headers/
│ ├── ssh.h # SSH server function declarations
│ └── user.h # User session function declarations
└── ssh_keys/ # Directory for SSH host keys
└── rsa.key # RSA private key for the server
SshConfig(): Initialize server configurationSshInit(): Set up SSH bind optionsSshStart(): Start listening for connectionsSshConnectionHandler(): Accept and handle incoming connections
UserCreate(): Create new user sessionUserAuth(): Authenticate user credentialsUserSessionInit(): Initialize SSH session and channelClientHandler(): Main client interaction loopSshPrintf(): Write formatted output to SSH channelSshRead(): Read input from SSH channel
This is a honeypot/research tool intended for:
- Security research and testing
- Educational purposes
- Controlled lab environments
- Network security analysis
Do not expose this server to the public internet without proper security measures.
MIT License - See LICENSE file for details