hypersleep / easyssh Goto Github PK
View Code? Open in Web Editor NEWunmaintained
unmaintained
hi,
1.) how can you set the server destination directory to /home when running err := ssh.Scp("/home/core/zipkin.rb")
... i login with root and the file gets placed into /root ...
2.)
i tried to run the following test, do you now what goes wrong?
my app on the server expects 1 parameter. it works fine when i run response, err := ssh.Run("cd /home; ./app 1")
but why does it fails with no parameter passed? ...see below
package main
import (
"fmt"
"github.com/hypersleep/easyssh"
)
func main() {
// Create MakeConfig instance with remote username, server address and path to private key.
ssh := &easyssh.MakeConfig{
User: "xxx",
Server: "xxx",
// Optional key or Password without either we try to contact your agent SOCKET
//Key: "/.ssh/id_rsa",
Password: "xxx",
Port: "22",
}
// Call Run method with command you want to run on remote server.
response, err := ssh.Run("cd /home; ./app")
// Handle errors
if err != nil {
panic("Can't run remote command: " + err.Error())
} else {
fmt.Println(response)
}
}
./main
panic: Can't run remote command: Process exited with: 1. Reason was: ()
goroutine 1 [running]:
runtime.panic(0x561dc0, 0xc21000ae70)
/usr/lib/go/src/pkg/runtime/panic.c:266 +0xb6
main.main()
/home/redpitaya/golang_test/main.go:53 +0x15b
goroutine 3 [syscall]:
runtime.goexit()
/usr/lib/go/src/pkg/runtime/proc.c:1394
goroutine 4 [IO wait]:
net.runtime_pollWait(0x7fa608d4d238, 0x72, 0x0)
/usr/lib/go/src/pkg/runtime/netpoll.goc:116 +0x6a
net.(_pollDesc).Wait(0xc210058290, 0x72, 0x7fa608d4c0e8, 0xb)
/usr/lib/go/src/pkg/net/fd_poll_runtime.go:81 +0x34
net.(_pollDesc).WaitRead(0xc210058290, 0xb, 0x7fa608d4c0e8)
/usr/lib/go/src/pkg/net/fd_poll_runtime.go:86 +0x30
net.(_netFD).Read(0xc210058230, 0xc210070000, 0x1000, 0x1000, 0x0, ...)
/usr/lib/go/src/pkg/net/fd_unix.go:204 +0x2a0
net.(_conn).Read(0xc2100000b0, 0xc210070000, 0x1000, 0x1000, 0xbcc449b49674fe54, ...)
/usr/lib/go/src/pkg/net/net.go:122 +0xc5
bufio.(_Reader).fill(0xc2100380c0)
/usr/lib/go/src/pkg/bufio/bufio.go:91 +0x110
bufio.(_Reader).Read(0xc2100380c0, 0xc21005ae20, 0x5, 0x5, 0x5, ...)
/usr/lib/go/src/pkg/bufio/bufio.go:159 +0x1a4
io.ReadAtLeast(0x7fa608d4d7c8, 0xc2100380c0, 0xc21005ae20, 0x5, 0x5, ...)
/usr/lib/go/src/pkg/io/io.go:288 +0xf6
io.ReadFull(0x7fa608d4d7c8, 0xc2100380c0, 0xc21005ae20, 0x5, 0x5, ...)
/usr/lib/go/src/pkg/io/io.go:306 +0x71
golang.org/x/crypto/ssh.(_streamPacketCipher).readPacket(0xc21005ae00, 0xc20000000d, 0x7fa608d4d7c8, 0xc2100380c0, 0x5, ...)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/cipher.go:142 +0xa4
golang.org/x/crypto/ssh.(_connectionState).readPacket(0xc2100597e0, 0xc2100380c0, 0x4044d9, 0xc210072050, 0xc210072148, ...)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/transport.go:111 +0x74
golang.org/x/crypto/ssh.(_transport).readPacket(0xc2100597e0, 0xc2100002b8, 0x5, 0x0, 0x0, ...)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/transport.go:107 +0x3a
golang.org/x/crypto/ssh.(_handshakeTransport).readOnePacket(0xc21005c0f0, 0xc210072000, 0xc2100002b8, 0x5, 0x5, ...)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/handshake.go:153 +0x97
golang.org/x/crypto/ssh.(*handshakeTransport).readLoop(0xc21005c0f0)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/handshake.go:133 +0x27
created by golang.org/x/crypto/ssh.newClientTransport
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/handshake.go:101 +0x100
goroutine 5 [chan receive]:
golang.org/x/crypto/ssh.(_handshakeTransport).readPacket(0xc21005c0f0, 0xc2100002b8, 0x5, 0x5, 0x0, ...)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/handshake.go:124 +0x34
golang.org/x/crypto/ssh.(_mux).onePacket(0xc2100581c0, 0x0, 0x0)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/mux.go:224 +0x3a
golang.org/x/crypto/ssh.(*mux).loop(0xc2100581c0)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/mux.go:199 +0x3e
created by golang.org/x/crypto/ssh.newMux
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/mux.go:128 +0xf3
goroutine 6 [chan receive]:
golang.org/x/crypto/ssh.(*Client).handleGlobalRequests(0xc210085b80, 0xc21004d700)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/client.go:137 +0x3a
created by golang.org/x/crypto/ssh.NewClient
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/client.go:54 +0xbb
goroutine 7 [chan receive]:
golang.org/x/crypto/ssh.(*Client).handleChannelOpens(0xc210085b80, 0xc210088000)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/client.go:146 +0x45
created by golang.org/x/crypto/ssh.NewClient
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/client.go:55 +0xdf
goroutine 8 [semacquire]:
sync.runtime_Syncsemacquire(0xc210085b50)
/usr/lib/go/src/pkg/runtime/sema.goc:257 +0xca
sync.(_Cond).Wait(0xc210085b40)
/usr/lib/go/src/pkg/sync/cond.go:62 +0x89
golang.org/x/crypto/ssh.(_mux).Wait(0xc2100581c0, 0x0, 0x0)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/mux.go:110 +0x8d
golang.org/x/crypto/ssh.func·004()
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/client.go:57 +0x37
created by golang.org/x/crypto/ssh.NewClient
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/client.go:59 +0x10c
goroutine 9 [chan receive]:
golang.org/x/crypto/ssh.(*forwardList).handleChannels(0xc210085b90, 0xc210088160)
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/tcpip.go:178 +0x4b
created by golang.org/x/crypto/ssh.NewClient
/home/redpitaya/golang/src/golang.org/x/crypto/ssh/client.go:60 +0x15e
We had to change a lot of code because the recent change to Run
. Is the API of easyssh considered stable, or should we change to a different package to prevent issues like these in the future?
Could you consider adding version branches and use something like gopkg.in to provide a stable package while allowing you to make breaking changes?
Hi
If an SSH key is encrypted, you get a nasty error message:
panic: Can't run remote command: asn1: structure error: tags don't match (16 vs {class:3 tag:14 length:112 isCompound:false}) {optional:false explicit:false application:false defaultValue:<nil> tag:<nil> stringType:0 set:false omitEmpty:false} pkcs1PrivateKey @2
Have you ever got around this problem?
Thanks
Alex
when i use Run to do something, after thati find a lot of tcp connect and not close.
i see the source code, like this:
func (ssh_conf *MakeConfig) Run(command string) (string, error) {
.....
defer func() {
session.Close()
} ()
...
}
the session is closed, but the tcp connect is not closed.
Using the example shown in https://github.com/hypersleep/easyssh/blob/master/example/run.go but leaving out the Key parameter on line 15 (ensuring it tries to contact the agent SOCKET), I get:
panic: Can't run remote command: read /Users/steven: is a directory
goroutine 1 [running]:
panic(0x1f5680, 0xc82000a940)
/usr/local/opt/go/libexec/src/runtime/panic.go:481 +0x3e6
gitlab.openminds.be/openminds/gom-awesome/modules/whereis.Whereis()
/Users/steven/Code/Zhann/go/src/gitlab.openminds.be/openminds/gom-awesome/modules/whereis/whereis.go:17 +0x1a3
main.main()
/Users/steven/Code/Zhann/go/src/gitlab.openminds.be/openminds/gom-awesome/gom.go:11 +0xd1
I can't seem to wrap my head around why. It's not possible for me to set the Key parameter, because then I bump into #3, I'm hoping to work around this by using the agent SOCKET.
Someone forked this repo and has it in a semi-maintained state. https://github.com/jniltinho/easyssh
This repo did not work for me when I tried, but I used @jniltinho's fork and it did work. This repo seems to be unmaintained at the moment.
When I use like outStr, err := ssh.Run(),whether execute Run() successfully or not,
the value of err is always 0. How can I get the exact return value of the ssh.Run() command.
Thank you!
I'd like to execute a long-running command on a remote server and stream the input back to the host. Is this possible with the Golang crypto/ssh library, as far as you know? If so, could it be implemented here as an io.Reader, or some other form of async reader?
This looks to be a very useful package, however I think usage examples and code documentation should support standard go documentation formats.
Since we added support for streaming output via a channel in #12, we should add an example so it is easy to use!
Is it possible to add also sudo functionality ?
I just added a panic as the last line of the example code provided and got the following...looks like there might be a few goroutines hanging around - is there any way we can close them out before existing main?
panic: Test
goroutine 1 [running]:
main.main()
/Users/rghosh/Go/src/dummy/ssh.go:27 +0x2c5
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1696 +0x1
goroutine 5 [IO wait]:
net.runtime_pollWait(0x4b05f8, 0x72, 0xc82000a190)
/usr/local/go/src/runtime/netpoll.go:157 +0x60
net.(_pollDesc).Wait(0xc8200b0300, 0x72, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:73 +0x3a
net.(_pollDesc).WaitRead(0xc8200b0300, 0x0, 0x0)
/usr/local/go/src/net/fd_poll_runtime.go:78 +0x36
net.(_netFD).Read(0xc8200b02a0, 0xc820019000, 0x1000, 0x1000, 0x0, 0x4ab050, 0xc82000a190)
/usr/local/go/src/net/fd_unix.go:232 +0x23a
net.(_conn).Read(0xc820030030, 0xc820019000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
/usr/local/go/src/net/net.go:172 +0xe4
bufio.(_Reader).fill(0xc8200b3620)
/usr/local/go/src/bufio/bufio.go:97 +0x1e9
bufio.(_Reader).Read(0xc8200b3620, 0xc8200dc1a0, 0x5, 0x5, 0x14, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:207 +0x260
io.ReadAtLeast(0x4b0890, 0xc8200b3620, 0xc8200dc1a0, 0x5, 0x5, 0x5, 0x0, 0x0, 0x0)
/usr/local/go/src/io/io.go:298 +0xe6
io.ReadFull(0x4b0890, 0xc8200b3620, 0xc8200dc1a0, 0x5, 0x5, 0xc8200da950, 0x0, 0x0)
/usr/local/go/src/io/io.go:316 +0x62
golang.org/x/crypto/ssh.(_streamPacketCipher).readPacket(0xc8200dc180, 0xc80000000e, 0x4b0890, 0xc8200b3620, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/cipher.go:142 +0xc1
golang.org/x/crypto/ssh.(_connectionState).readPacket(0xc820080900, 0xc8200b3620, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/transport.go:111 +0xce
golang.org/x/crypto/ssh.(_transport).readPacket(0xc820080900, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/transport.go:107 +0x55
golang.org/x/crypto/ssh.(_handshakeTransport).readOnePacket(0xc820080a20, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/handshake.go:173 +0xe7
golang.org/x/crypto/ssh.(*handshakeTransport).readLoop(0xc820080a20)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/handshake.go:145 +0x25
created by golang.org/x/crypto/ssh.newClientTransport
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/handshake.go:113 +0x37d
goroutine 18 [chan receive]:
golang.org/x/crypto/ssh.(_handshakeTransport).readPacket(0xc820080a20, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/handshake.go:136 +0x6d
golang.org/x/crypto/ssh.(_mux).onePacket(0xc82021acb0, 0x0, 0x0)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/mux.go:224 +0x5e
golang.org/x/crypto/ssh.(*mux).loop(0xc82021acb0)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/mux.go:199 +0x42
created by golang.org/x/crypto/ssh.newMux
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/mux.go:128 +0x20d
goroutine 19 [chan receive]:
golang.org/x/crypto/ssh.(*Client).handleGlobalRequests(0xc82022e0c0, 0xc820230060)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/client.go:137 +0x4a
created by golang.org/x/crypto/ssh.NewClient
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/client.go:54 +0xe4
goroutine 20 [chan receive]:
golang.org/x/crypto/ssh.(*Client).handleChannelOpens(0xc82022e0c0, 0xc82021df80)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/client.go:146 +0x6e
created by golang.org/x/crypto/ssh.NewClient
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/client.go:55 +0x110
goroutine 21 [semacquire]:
sync.runtime_Syncsemacquire(0xc82022e090)
/usr/local/go/src/runtime/sema.go:237 +0x201
sync.(_Cond).Wait(0xc82022e080)
/usr/local/go/src/sync/cond.go:62 +0x9b
golang.org/x/crypto/ssh.(_mux).Wait(0xc82021acb0, 0x0, 0x0)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/mux.go:110 +0xb8
golang.org/x/crypto/ssh.NewClient.func1(0xc82022e0c0)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/client.go:57 +0x39
created by golang.org/x/crypto/ssh.NewClient
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/client.go:59 +0x132
goroutine 22 [chan receive]:
golang.org/x/crypto/ssh.(*forwardList).handleChannels(0xc82022e0d0, 0xc8202300c0)
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/tcpip.go:178 +0x6e
created by golang.org/x/crypto/ssh.NewClient
/Users/rghosh/Go/src/golang.org/x/crypto/ssh/client.go:60 +0x18f
exit status 2
As per golang/go#6376, easyssh.go#L39 will fail when cross-compiling. There is another fork of easyssh which does this slightly differently.
I can make a PR to adopt this but I am concerned for projects relying the homeDir functionality. Any suggestions?
Could you clarify the license for your code?
You could use a BSD-style license, similar to the Go language license https://golang.org/LICENSE.
Any chance you could version a release of this package? Would like to use gopkg.in to retrieve but there aren't any releases atm.
panic: Can't run remote command: ssh: must specify HostKeyCallback
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.