0.3.6 • Published 8 days ago

hivessh v0.3.6

Weekly downloads
-
License
MIT
Repository
github
Last release
8 days ago

HiveSsh (Beta)

CI/CD MIT typescript npm github

npm.io npm.io npm.io npm.io npm.io

Table of Contents

About

HiveSsh simplifies SSH2 connections via promise-based task execution on Linux servers with built-in server utilities and powerful command execution functions.

HiveSsh is a library designed to streamline SSH2 connections and task execution on Linux servers. It provides user-friendly promise-based functions for efficient server operations without the need for a client application.

Beta info

This software is yet not fully developed and will change over time. If a version is intended to be used in another release, it is recommended to pin the dependency to a version to prevent beta breaking changes.

Feel free to test the software and submit suggestions for improvements or problems.

Key Features

HiveSsh offers the following key features:

  • All-Distributions: SSH2 and SFTP operations for all Linux servers
  • Promisified: Promise-based functions for ease of use

  • AbstractPackageManager: Built-in abstract package manager with support for apt, dnf, and yum, with additional configurability

  • Exec: Command execution utilities for event or promise-based error handling and output parsing, filtering, and mapping

Requirements

HiveSsh requires the following server environments:

  • SSH2 server
  • SFTP support
  • Linux distribution

Getting started

npm i hivessh
import { SshHost } from "hivelib"
// or import SshHost from "hivelib" (SshHost is also the default export)

//connect
const myHost = await SshHost.connect({
    host: "127.0.0.1",
    //port: 22, (default 22)
    //user: "root", (default root)

    //password: "123456789",
    // or
    //privateKey: "..."
    // or
    //privateKeyPath:"/home/user/.ssh/id_rsa",
    //passphrase: "123456789"
})

Here are some using examples:

Promisified

Execute and assets

After connecting an SshHost, you can use the promisified execution (and other asset features) directly on the SshHost instance.

// check files in user home dir
const homeDirFiles = await myHost.exec("ls -al")
console.log("Home dir files:\n", homeDirFiles.out)

Get the hosts public ip address:

// check if curl command exists
const curlExists = await myHost.exists("curl ifconfig.me")
if(!curlExists){
  myHost.close()
  throw new Error("Curl is not installed on: " + myHost.settings.id)
}

const myIp = await myHost.exec("curl ifconfig.me")
console.log("Host public ip: " + myIp.out)
//other sources: `api.ipify.org`, `ipinfo.io/ip` or `ipecho.net/plain`

You can also execute commands on absolut path:

const homeDirFiles = await myHost.exec(
  "ls -al",
  { pwd: "/etc" }
)
console.log("Etc files: ", homeDirFiles.out)

Also a git example:

// check if git command exists
const gitExist = await myHost.exists("git")
if(!curlExists){
  myHost.close()
  throw new Error("Git is not installed on: " + myHost.settings.id)
}

// get git status
const gitStatus = await myHost.exec(
  "git status",
  {
    pwd: "/home/tester/myrepo"
  }
)

console.log("Git status:\n", gitStatus.out)

Sftp

You can also use the promisified SFTP features via SshHost.sftp.

const myBinary: Buffer = await myHost.sftp.readFile("/home/tester/my-binary")

const exampleConfig: string = await myHost.sftp.readFile("/etc/example/config.yml", "utf8")

AbstractPackageManager

With the abstract package manager (apm) you can use apt, dnf, yum or a custom implemented package manager via one interface. The apm features are limited and general, but you can update your system and install, delete and list your packages.

// upgrade all packages using the abstract package manager
const apm = await myHost.getApm()
await apm.updateCache()
await apm.upgradeAll()

// install a package using the abstract package manager
await apm.install("git")

Exec Session

Sessions are available so that the PWD (process working directory) and environment do not have to be specified for every single command. These sessions store that persistent settings across multiple executions and can even resolve relative paths.

const session = host.session("/etc/example")

session.exec("ls -al") // is executed at /etc/example
session.exec("./myApp") // is using MY_APP_ENV_VAR

Technologies

HiveSsh is built using the following technologies:

Contributing

Contributions to HiveSsh are welcome!
Interested users can refer to the guidelines provided in the CONTRIBUTING.md file to contribute to the project and help improve its functionality and features.

License

HiveSsh is licensed under the MIT license, providing users with flexibility and freedom to use and modify the software according to their needs.

Disclaimer

HiveSsh is provided without warranties.
Users are advised to review the accompanying license for more information on the terms of use and limitations of liability.

0.2.1

12 days ago

0.3.6

8 days ago

0.3.5

10 days ago

0.3.2

11 days ago

0.1.4

12 days ago

0.3.1

11 days ago

0.2.2

12 days ago

0.3.4

10 days ago

0.3.3

11 days ago

0.1.5

12 days ago

0.1.3

14 days ago

0.1.2

14 days ago

0.1.1

14 days ago

0.0.1

14 days ago