High level scala SSH API for easy and fast operations on remote servers.
This API is JSCH based. Interfaces are stable. Many helper functions are provided to simplify unix operations ps, ls, cat, kill, find, ..., an other goal of this API is to create an unix abstraction layer (Linux, Aix, Solaris, Darwin, ...).
One of the main difference of this API with others is that it can work with persisted shell sessions. Many commands can then be sent to an already running and initialized shell session ! Thanks to this feature you can greatly speed up your SSH shell performances, from 70 cmd/s to more than 500 cmd/s ! There is no differences in API between persisted and not persisted shell sessions, that's the reason why the API looks very simple from scala point of view; when you execute a command in a shell persisted session you get directly the output of the command but not the return code. The return code will be accessible only indirectly using for example a "echo $?" command.
The current release doesn't provide full shell interaction with executed commands, you only send a command and get the result, but I'm currently working to provide full interactivity, to allow interaction with commands such as to provide data after the command is started (send a password once the prompt is visible, ...). This work is currently visible through SSHReact class and SSHReactTest test class.
In your build.sbt, add this (available in maven central) :
libraryDependencies += "fr.janalyse" %% "janalyse-ssh" % version
It requires a local user named "test" with password "testtest", remember that you can remove the password, if your public key has been added in authorized_keys file of the test user.
// ---------------------
//> using scala "3.3.1"
//> using dep "fr.janalyse::janalyse-ssh:1.1.0"
//> using lib "org.slf4j:slf4j-nop:2.0.9"
// ---------------------
jassh.SSH.once("127.0.0.1", "test", "testtest") { ssh =>
println(ssh.execute("""echo "Hello World from $(hostname)" """))
}
// ---------------------
//> using scala "3.3.1"
//> using dep "fr.janalyse::janalyse-ssh:1.1.0"
//> using lib "org.slf4j:slf4j-nop:2.0.9"
// ---------------------
jassh.SSH.shell("localhost", "test") { sh =>
import sh.*
println(s"initial directory is $pwd")
cd("/tmp")
println(s"now it is $pwd")
println(echo("Hello world !"))
}
This functions much the same as a regular SSH connection, but many of the unix like commands are not supported and the terminal behaves differently
import fr.janalyse.ssh._
val settings = SSHOptions(host = host, username=user, password = pass, prompt = Some(prompt), timeout = timeout)
val session = SSH(settings)
val shell = session.newPowerShell
println(shell.ls)
println(shell.pwd)
To turn on/off ssh root direct access or sftp ssh subsystem.
Subsystem sftp ... (add or remove comment)
PermitRootLogin yes or no (of course take care of security constraints)
AIX SSHD CONFIGURATION :
vi /system/products/openssh/conf/sshd_config
/etc/rc.d/rc2.d/S99sshd reload
LINUX SSHD CONFIGURATION
vi /etc/ssh/sshd_config
/etc/init.d/sshd reload
SOLARIS SSHD CONFIGURATION
vi /usr/local/etc/ssh/sshd_config
svcadm restart ssh
MAC OS X CONFIGURATION
sudo vi /etc/sshd_config
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist