Get up and running with libssh-node in 5 minutes.
Linux (Ubuntu/Debian):
sudo apt-get install libssh-devmacOS:
brew install libsshWindows:
vcpkg install libssh:x64-windowsyarn install# Build everything
yarn build
# Or build separately
yarn build:native # C++ native module
yarn build:ts # TypeScriptyarn testCreate test-connection.ts:
import { SSHSession } from './lib';
async function main() {
const session = new SSHSession({
host: 'example.com',
port: 22,
user: 'your-username',
autoDetectAgent: true
});
try {
console.log('Connecting...');
await session.connect();
console.log('Connected!');
console.log('Authenticating...');
await session.authenticate({ useAgent: true });
console.log('Authenticated!');
console.log('Success!');
await session.disconnect();
} catch (err) {
console.error('Error:', err);
process.exit(1);
}
}
main();Run it:
npx ts-node test-connection.tsCreate test-tunnel.ts:
import { SSHSession, SSHTunnel } from './lib';
async function main() {
const session = new SSHSession({
host: 'bastion.example.com',
user: 'your-username',
autoDetectAgent: true
});
try {
await session.connect();
await session.authenticate({ useAgent: true });
const tunnel = new SSHTunnel({
session,
localPort: 3307,
remoteHost: 'localhost',
remotePort: 3306
});
await tunnel.start();
console.log('Tunnel running on localhost:3307');
console.log('Press Ctrl+C to stop');
process.on('SIGINT', async () => {
await tunnel.stop();
await session.disconnect();
process.exit(0);
});
} catch (err) {
console.error('Error:', err);
process.exit(1);
}
}
main();Run it:
npx ts-node test-tunnel.tsRebuild for Electron:
yarn add --dev electron-rebuild
yarn electron-rebuild -v 31.0.0# Linux
sudo ldconfig
# macOS
export LDFLAGS="-L$(brew --prefix libssh)/lib"
export CPPFLAGS="-I$(brew --prefix libssh)/include"
yarn rebuild# Clean and rebuild
yarn clean
yarn rebuild# Check agent is running
echo $SSH_AUTH_SOCK
# Start agent if needed
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa- Read the full README.md
- Check out examples/ for more usage patterns
- Read the tunneling guide for database tunnels
- Read the agents guide for 1Password/YubiKey setup
- Check IMPLEMENTATION_STATUS.md for known issues
- See docs/building.md for detailed build instructions
- Report issues on GitHub