1
0
Fork 0
mirror of https://github.com/eznix86/sshx.git synced 2026-07-25 21:09:16 +00:00
Idiomatic way of interacting with a remote machine
Find a file
2025-12-01 12:38:00 +04:00
constants.go feat: initial commit 2025-12-01 12:35:59 +04:00
doc.go feat: initial commit 2025-12-01 12:35:59 +04:00
go.mod feat: initial commit 2025-12-01 12:35:59 +04:00
go.sum feat: initial commit 2025-12-01 12:35:59 +04:00
keys.go feat: initial commit 2025-12-01 12:35:59 +04:00
LICENSE docs: add license 2025-12-01 12:38:00 +04:00
machine.go feat: initial commit 2025-12-01 12:35:59 +04:00
options.go feat: initial commit 2025-12-01 12:35:59 +04:00
README.md docs: add license 2025-12-01 12:38:00 +04:00
sftp.go feat: initial commit 2025-12-01 12:35:59 +04:00
template.go feat: initial commit 2025-12-01 12:35:59 +04:00
usergroup.go feat: initial commit 2025-12-01 12:35:59 +04:00
utils.go feat: initial commit 2025-12-01 12:35:59 +04:00

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.