anko icon indicating copy to clipboard operation
anko copied to clipboard

SSH library

Open k4ml opened this issue 8 years ago • 5 comments

I wonder if it possible to add ssh library. Currently making ssh connection and run remote command is too much boilerplate in Go - https://gist.github.com/erikdubbelboer/f62a109d8e8798a11eb89ed494491953.

If we can simplify this in anko, it can be a practical alternative for some scripting work in Go (anko).

k4ml avatar Apr 01 '17 02:04 k4ml

I try to add the ssh and ssh/agent library - https://github.com/k4ml/anko/commit/9f646360ab6152dc6490f192af8687638d6dde05

Now I'm stuck with this error on go build:-

# github.com/mattn/anko/builtins/ssh
builtins/ssh/ssh.go:13: cannot make type ssh.ClientConfig

I'm trying to make this anko script to work:-

var ssh, agent = import("ssh"), import("ssh/agent")
var ioutil, net, os = import("io/ioutil"), import("net"), import("os")

func privateKeyPath() {
    return os.Getenv("HOME") + "/.ssh/kamalkey.pem"
}

func parsePrivateKey(keyPath) {
    buff, _ = ioutil.ReadFile(keyPath)
    return ssh.ParsePrivateKey(buff)
}

func makeSshConfig(user) {
    socket = os.Getenv("SSH_AUTH_SOCK")
    conn, err = net.Dial("unix", socket)

    agentClient = agent.NewClient(conn)

    config = make(ssh.ClientConfig)
    config.Set("user", user)

    #config = make(ssh.ClientConfig{
    #    User: user,
    #    Auth: []ssh.AuthMethod{
    #        ssh.PublicKeysCallBack(agentClient.Signers),
    #    },
    #})

    return config, nil
}

func main() {
    config, err = makeSshConfig("kamal")

    client, err = ssh.Dial("tcp", "myserver:22", config)
}

main()

k4ml avatar Apr 01 '17 04:04 k4ml

please keep package namespaces as same as golang.

mattn avatar Apr 02 '17 14:04 mattn

Do you think this can be closed?

MichaelS11 avatar Mar 31 '18 06:03 MichaelS11

@mattn any thoughts?

MichaelS11 avatar Apr 08 '18 17:04 MichaelS11