micheleriva / omgossh

😱 Connect and execute remote SSH commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

oh my gossh

Oh My GoSSH is a simple library for Golang which allows you to connect via ssh to any remote server using username and password.

Use at your own risk.

Usage

package main

import (
  "fmt"
  omgossh "github.com/micheleriva/omgossh"
)

const SSH_HOST     = os.Getenv("SSH_HOST")
const SSH_USERNAME = os.Getenv("SSH_USERNAME")
const SSH_PASSWORD = os.Getenv("SSH_PASSWORD")

func main() {

  conn, err := omgossh.Connect(SSH_HOST, SSH_USERNAME, SSH_PASSWORD)
  if err != nil {
    log.Fatal(err)
  }

  stdout, err := conn.Exec("cd /myDir", "ls -la")
  if err != nil {
    log.Fatal(err)
  }

  fmt.Println(stdout)
}
go run .

# Now we should see the result of "cd /myDir" and "ls -la" commands
drwxr-xr-x  7 root root  224 Sep 16 20:15 ./
drwxr-xr-x  8 root root  256 Sep 16 20:15 ../
-rw-r--r--  1 root root  691 Sep 16 20:15 README.md

License

GPLv3

About

😱 Connect and execute remote SSH commands

License:GNU Affero General Public License v3.0


Languages

Language:Go 100.0%