Documentation
Introduction
Open Source Release Policy
Export Compliance
Using BouncyCastle
Installing the API
Enabling Logging
Per-Connection Logging
Third Party Dependencies
Generating SSH Keys
Using BouncyCastle
Using SSH Public Keys in Java
Supporting ED25519/Curve25519
Supporting Compression
Integrating Licensing into Maven Builds
Open Source Release Policy
Export Compliance
Using BouncyCastle
Installing the API
Enabling Logging
Per-Connection Logging
Third Party Dependencies
Generating SSH Keys
Using BouncyCastle
Using SSH Public Keys in Java
Supporting ED25519/Curve25519
Supporting Compression
Integrating Licensing into Maven Builds
Client API
Quick Start
Creating an SSH Client
Public Key Authentication
Keyboard Interactive Authentication
Public Key Authentication with sshagent
Executing Single Commands
Executing Commands within a Shell
Transferring Files
Connecting through Proxies
Display the Authentication Banner
Using the SFTP Client
Port Forwarding
Creating an SSH Client
Public Key Authentication
Keyboard Interactive Authentication
Public Key Authentication with sshagent
Executing Single Commands
Executing Commands within a Shell
Transferring Files
Connecting through Proxies
Display the Authentication Banner
Using the SFTP Client
Port Forwarding
Working Examples
Server API
Creating an SSH Server
Configuring Listening Interfaces
Configuring Host Keys
Password Authentication
Public Key Authentication
Challenge-Response Authentication
Configuring Port Forwarding
Configuring SFTP
Supporting SCP
Implementing your own File System
Creating an Interactive Terminal
Proxy Protocol Support
Configuring Listening Interfaces
Configuring Host Keys
Password Authentication
Public Key Authentication
Challenge-Response Authentication
Configuring Port Forwarding
Configuring SFTP
Supporting SCP
Implementing your own File System
Creating an Interactive Terminal
Proxy Protocol Support
How to use SSH Public Keys in Java
Introduction
SSH uses public keys for host identification and user authentication. This page provides several examples in the form of snippets for how to use public keys in the Maverick Synergy Java SSH API.
Generating SSH Keys in Java
Generate an ED25519 Private Key:
SshKeyPair ed25519 = SshKeyPairGenerator.generateKeyPair(SshKeyPairGenerator.ED25519);
Generate an RSA Private Key:
SshKeyPair rsa = SshKeyPairGenerator.generateKeyPair(SshKeyPairGenerator.RSA, 4096);
Saving SSH Keys in Java
Saving a Private Key to file:
SshKeyUtils.createPrivateKeyFile(ed25519, "passphrase_text", new File(".ssh/id_ed25519"));
Code language: JavaScript (javascript)
Saving a Public Key to file:
SshKeyUtils.createPublicKeyFile(ed25519.getPublicKey(), "Generated by Maverick Synergy", new File(".ssh/id_ed25519.pub"));
Code language: JavaScript (javascript)
Loading SSH Keys in Java
Loading a Private Key from a file, passing the passphrase as a String:
SshKeyPair pair = SshKeyUtils.getPrivateKey(new File(".ssh/id_rsa"), "passphrase_text");
Code language: JavaScript (javascript)
Get the Public Key from the Private Key:
SshPublicKey pub = pair.getPublicKey();
Loading a Public Key from file:
SshPublicKey pub = SshKeyUtils.getPublicKey(new File(".ssh/id_rsa.pub"));
Code language: JavaScript (javascript)
Verifying SSH Keys in Java
Generate the SSH Key Fingerprint of a Public Key:
String fingerprint = SshKeyUtils.getFingerprint(pub);
Code language: JavaScript (javascript)
Generate the Bubblebabble fingerprint of a Public Key:
String bubblebabble = SshKeyUtils.getBubbleBabble(pub);
Code language: JavaScript (javascript)