Skip to content

Commit

Permalink
修改ssh连接
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYZhou committed Jan 3, 2023
1 parent ddee0ca commit 64b87e5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"go.inferGopath": false
}
2 changes: 1 addition & 1 deletion command/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
第一个参数是执行的目录,第二个参数是命令
*/
func Run(content string,direct string) {
func Run(content string, direct string) {
param := strings.Split(direct, " ")
cmd := exec.Command(param[0], param[1:]...)
cmd.Dir = content
Expand Down
2 changes: 1 addition & 1 deletion file/index.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package file

import(
import (
"os"
"path"
"strings"
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module github.com/MrYZhou/outil
module github.com/MrYZhou/outil

go 1.19
go 1.19

require golang.org/x/crypto v0.4.0

require golang.org/x/sys v0.3.0 // indirect
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8=
golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
30 changes: 7 additions & 23 deletions ssh/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ssh

import (
"net"
"os"

"golang.org/x/crypto/ssh"
)
Expand All @@ -11,7 +10,7 @@ import (
type Cli struct {
user string
password string
addr string
host string
client *ssh.Client
LastResult string
}
Expand All @@ -23,7 +22,7 @@ func (c *Cli) Connect() (*Cli, error) {
config.User = c.user
config.Auth = []ssh.AuthMethod{ssh.Password(c.password)}
config.HostKeyCallback = func(hostname string, remote net.Addr, key ssh.PublicKey) error { return nil }
client, err := ssh.Dial("tcp", c.addr, config)
client, err := ssh.Dial("tcp", c.host, config)
if nil != err {
return c, err
}
Expand All @@ -50,30 +49,15 @@ func (c Cli) Run(shell string) (string, error) {
return c.LastResult, err
}

func Server() Cli {
addr := os.Getenv("addr")
user := os.Getenv("user")
password := os.Getenv("password")
func Server(host string, user string, password string) Cli {

cli := Cli{
addr: addr,
user: user,
password:password,
host: host,
user: user,
password: password,
}
c, _ := cli.Connect()

defer c.client.Close()
return cli
}

// func Server(addr string,user string, password string) Cli {

// cli := Cli{
// addr: addr,
// user: user,
// password:password,
// }
// c, _ := cli.Connect()

// defer c.client.Close()
// return cli
// }

0 comments on commit 64b87e5

Please sign in to comment.