Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dacr/jassh
High level scala SSH API for easy and fast operations on remote servers.
https://github.com/dacr/jassh
dsl jsch scala scala-ssh scala-ssh-library ssh ssh-client
Last synced: about 10 hours ago
JSON representation
High level scala SSH API for easy and fast operations on remote servers.
- Host: GitHub
- URL: https://github.com/dacr/jassh
- Owner: dacr
- License: apache-2.0
- Created: 2014-02-24T19:51:55.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-10-06T10:08:17.000Z (4 months ago)
- Last Synced: 2025-01-15T05:27:40.621Z (7 days ago)
- Topics: dsl, jsch, scala, scala-ssh, scala-ssh-library, ssh, ssh-client
- Language: Scala
- Homepage:
- Size: 323 KB
- Stars: 71
- Watchers: 13
- Forks: 25
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JASSH - the SCALA SSH API [![Build Status][travisImg]][travisLink] [![License][licenseImg]][licenseLink] [![Maven][mavenImg]][mavenLink] [![Scaladex][scaladexImg]][scaladexLink]
High level scala SSH API for easy and fast operations on remote servers.
This API is [JSCH](https://github.com/mwiede/jsch) based. Interfaces are stable. Many helper functions are provided to simplify unix operations [ps, ls, cat, kill, find, ...](https://javadoc.io/doc/fr.janalyse/janalyse-ssh_3/latest/api/fr/janalyse/ssh/AllOperations.html), 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
```
Latest `version`: [![Maven][mavenImg]][mavenLink] [![Scaladex][scaladexImg]][scaladexLink][**Scala docs**](https://javadoc.io/doc/fr.janalyse/janalyse-ssh_3)
[mavenImg]: https://img.shields.io/maven-central/v/fr.janalyse/janalyse-ssh_3.svg
[mavenImg2]: https://maven-badges.herokuapp.com/maven-central/fr.janalyse/janalyse-ssh_3/badge.svg
[mavenLink]: https://search.maven.org/#search%7Cga%7C1%7Cfr.janalyse.janalyse-ssh[scaladexImg]: https://index.scala-lang.org/dacr/jassh/janalyse-ssh/latest.svg
[scaladexLink]: https://index.scala-lang.org/dacr/jassh[licenseImg]: https://img.shields.io/github/license/dacr/jassh.svg
[licenseImg2]: https://img.shields.io/:license-apache2-blue.svg
[licenseLink]: LICENSE[codacyImg]: https://img.shields.io/codacy/a335d839f49646389d88d02c01e0d6f6.svg
[codacyImg2]: https://api.codacy.com/project/badge/grade/a335d839f49646389d88d02c01e0d6f6
[codacyLink]: https://www.codacy.com/app/dacr/jassh/dashboard[codecovImg]: https://img.shields.io/codecov/c/github/dacr/jassh/master.svg
[codecovImg2]: https://codecov.io/github/dacr/jassh/coverage.svg?branch=master
[codecovLink]: http://codecov.io/github/dacr/jassh?branch=master[travisImg]: https://img.shields.io/travis/dacr/jassh.svg
[travisImg2]: https://travis-ci.org/dacr/jassh.png?branch=master
[travisLink]:https://travis-ci.org/dacr/jassh----
## hello world script
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.```scala
// ---------------------
//> 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)" """))
}
```## Persisted shell session
```scala
// ---------------------
//> 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 !"))
}
```## Shell session to an SSH enabled PowerShell Server (windows)
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
```scala
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)
```## SSH Configuration notes
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
```