Skip to content
eznix86Public

About

Idiomatic way of interacting with a remote machine

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

sshx

A SSH client library for Go with support for command execution, file uploads, and template rendering.

Features

  • Command execution: Execute command on a remote machines
  • File Uploads: Upload files with permissions and ownership control
  • Template Support: Render and upload Go templates to remote machines

Quick Start

package main

import (
    "log"
    "github.com/eznix86/sshx"
)

func main() {
    // Create a machine
    m := sshx.NewMachine("user@host:22")
    defer m.Close()

    // Run a command
    output, err := m.Run("uptime")
    if err != nil {
        log.Fatal(err)
    }
    log.Println(output)

    // Upload a file
    err = m.Upload("local.txt", "/remote/path.txt")
    if err != nil {
        log.Fatal(err)
    }
}

Configuration Options

Connection Options

  • WithTimeout(duration) - Set connection timeout
  • WithKnownHosts(path) - Set known_hosts file path
  • WithAutoKnownHosts() - Auto-load ~/.ssh/known_hosts

Authentication Options

  • WithAuth(method) - Use custom SSH auth method
  • WithKeyPath(path) - Load specific SSH key
  • WithDefaultKeys() - Load default keys from ~/.ssh/
  • WithAgent() - Use SSH agent

Usage

Upload with Metadata

err := m.UploadWithMeta("app.conf", "/etc/app.conf", sshx.FileMeta{
    Perm:  0644,
    Owner: "www-data",
    Group: "www-data",
})

Template Upload

data := struct {
    Port int
    Host string
}{Port: 8080, Host: "localhost"}

err := m.UploadTemplate("/etc/config.conf",
    sshx.WithTemplateString("Server={{.Host}}:{{.Port}}", data),
    sshx.WithPermission(0644),
    sshx.WithOwner("root", "root"),
)

Custom Authentication

m := sshx.NewMachine("host",
    sshx.WithKeyPath("/path/to/private/key"),
    sshx.WithKnownHosts("/custom/known_hosts"),
    sshx.WithTimeout(30*time.Second),
)

License

MIT License - see LICENSE file for details.

About

Idiomatic way of interacting with a remote machine

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

⌂ 换网址