Setting up the Project
We recommend using Maven to manage your Java dependencies. Instrutions and an example pom.xml are available in our article:
Executing Remote Commands
A common requirement of using a Java SSH API is to execute commands on remote servers. As an end-user, SSH has two separate mechanisms that can acheive this; you can start an interactive shell and type commands by just connecting to the server i.e. ssh root@hostname
, or you can execute the ssh command appending the command you want to execute to the command line i.e. ssh root@hostname ls -l
Executing Single Commands
Executing Interactive Commands within a Remote Shell
It is often required that a command be executed under a privileged account using the Sudo command. This could prompt the user for their password, which presents a problem for many developers as the shell is just a stream of bytes and examining the command output for this can be problematic. Maverick Synergy has solved this problem with its ExpectShell implementation.
Executing Interactive Commands with Sudo
File Transfer
Transferring Files by SFTP
Copy a Directory using SCP
Comparing the Contents of a Remote File against a Local File
Port Forwarding
Using Keys
How to use SSH Public Keys
Creating a Certificate Authority and Authenticating with OpenSSH Certificates
Jump Hosts
Connecting the Client through a Jump Host
Looking for something different?
If you can’t see an example that fit’s your use case, get in touch with us and we’ll be happy to help.