Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- "fmt"
- "golang.org/x/crypto/ssh"
- "os"
- )
- var (
- user = "lab_04_2018"
- password = "XBsdhd63sSD"
- host = "lab.posevin.com:22"
- )
- //var (
- // user = "lab_15_2018"
- // password = "SDJDFJFiud3"
- // host = "localhost:2015"
- //)
- func connectToHost() (*ssh.Client, error) {
- sshConfig := &ssh.ClientConfig{
- User: user,
- Auth: []ssh.AuthMethod{ssh.Password(password)},
- HostKeyCallback: ssh.InsecureIgnoreHostKey(),
- }
- client, err := ssh.Dial("tcp", host, sshConfig)
- if err != nil {
- return nil, err
- }
- return client, nil
- }
- func main() {
- client, err := connectToHost()
- if err != nil {
- panic(err)
- }
- defer client.Close()
- reader := bufio.NewReader(os.Stdin)
- for {
- session, err := client.NewSession()
- if err != nil {
- panic(err)
- }
- defer session.Close()
- cmd, _ := reader.ReadString('\n')
- if cmd == "exit\n" {
- break
- }
- out, err := session.Output(cmd)
- if err != nil {
- panic(err)
- }
- fmt.Print(string(out))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement