GithubHelp home page GithubHelp logo

go-sshclient's People

Contributors

0x5459 avatar echtwerner avatar erdelmaero avatar helloyi avatar kevinms avatar pieterclaerhout avatar sz-po avatar yxxhero avatar zwczou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-sshclient's Issues

Typo in TerminalConfig struct

There's a typo in the following code, it should be "Height" instead of "Hight"

type TerminalConfig struct {
	Term   string
	Hight  int
	Weight int
	Modes  ssh.TerminalModes
}

Whether you can add the option to set a timeout when creating an ssh connection?

I was new and didn't know how to submit my code to the repository and create a Pull request.

I have tried to submit, but the error told me that I did not have permission.

The code I want to change is as follows:

// The timeout period parameter is added
func DialWithPasswd(addr, user, passwd string, timeout time.Duration) (*Client, error) {
	config := &ssh.ClientConfig{
		User: user,
		Auth: []ssh.AuthMethod{
			ssh.Password(passwd),
		},
		HostKeyCallback: ssh.HostKeyCallback(func(hostname string, remote net.Addr, key ssh.PublicKey) error { return nil }),
		Timeout:         timeout,       // The timeout period parameter is added
	}

	return Dial("tcp", addr, config)
}

// DialWithKey starts a client connection to the given SSH server with key authmethod.
// The timeout period parameter is added
func DialWithKey(addr, user, keyfile string, timeout time.Duration) (*Client, error) {
	key, err := ioutil.ReadFile(keyfile)
	if err != nil {
		return nil, err
	}

	signer, err := ssh.ParsePrivateKey(key)
	if err != nil {
		return nil, err
	}

	config := &ssh.ClientConfig{
		User: user,
		Auth: []ssh.AuthMethod{
			ssh.PublicKeys(signer),
		},
		HostKeyCallback: ssh.HostKeyCallback(func(hostname string, remote net.Addr, key ssh.PublicKey) error { return nil }),
		Timeout:         timeout,       // The timeout period parameter is added
	}

	return Dial("tcp", addr, config)
}

The other two functions I'd like to add are Runshell(when executing a Runshell function, the command is executed directly after cmd is passed in, which I prefer to do) and CheckConnection(assuming I have a list of ip addresses). I want to check that the ssh connection can be established before executing a series of commands on these IP addresses. If not, skip this ip address.)

code:

type ClinetInfo struct {
	Ip         string
	Port       string
	Username   string
	PrikeyFile string
}

func Runshell(cli ClinetInfo, cmd string) (stdout, stderr bytes.Buffer) {
	addr := fmt.Sprintf("%v:%v", cli.Ip, cli.Port)
	client, err := DialWithKey(addr, cli.Username, cli.PrikeyFile, time.Second*3)
	defer client.Close()
	utils.CheckErr(err)

	client.Cmd(cmd).SetStdio(&stdout, &stderr).Run()
	return stdout, stderr
}

func CheckConnection(cli ClinetInfo) (ok bool, err error) {
	ok = true
	addr := fmt.Sprintf("%v:%v", cli.Ip, cli.Port)

	client, err := DialWithKey(addr, cli.Username, cli.PrikeyFile, time.Second*3)

	if err != nil {
		ok = false
	} else {
		client.Close()
	}
	return
}

Add proxy support

It would be nice if this project supported proxy servers.
For example, if you're connecting through a bastion or a jump box, to have that as an option.
Something like,

sshclient.DialWithProxy("host:port", "username", "pkey", "proxyhost:port", "proxy-username", "proxy-pkey")

or something like that.

Support for diffie-hellman-group1-sha1 and Ciphers aes128-cbc and others

I'm trying to connect to an ssh server with an insecure connection, I can even configure some things but it always gives me an error [no password].

No SSH Config

image

Error:

2024/01/03 08:54:21 ssh: handshake failed: ssh: no common algorithm for key exch
ange; client offered: [curve25519-sha256 [email protected] ecdh-sha2-
nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 diffie-hellman-group14-sha256 dif
fie-hellman-group14-sha1 ext-info-c [email protected]], server offere
d: [diffie-hellman-group1-sha1]

With SSH Config

image

Error:

2024/01/03 08:52:58 ssh: handshake failed: ssh: unable to authenticate, attempte
d methods [none password], no supported methods remain

It is impossible to get v2.0.0 version

When using go get -u github.com/helloyi/go-sshclient, it always return v1.1.1 version, According to semantic version spec if major version greater than v1, it should append to go module name,So module github.com/helloyi/go-sshclient should change to module github.com/helloyi/go-sshclient/v2 in v2.x.

Add license

Hi

Can you add license file to this one (example MIT) so I can use this code as part of my other projects?

Thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.