Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Check] -distribute flag with ssh targets #34

Open
hahwul opened this issue Jul 24, 2021 · 4 comments
Open

[Check] -distribute flag with ssh targets #34

hahwul opened this issue Jul 24, 2021 · 4 comments

Comments

@hahwul
Copy link
Owner

hahwul commented Jul 24, 2021

SSIA

@hahwul
Copy link
Owner Author

hahwul commented Jul 25, 2021

Memo

ssh client

go get golang.org/x/crypto/ssh

package main

import (
	"fmt"
	"log"
	"os"

	"golang.org/x/crypto/ssh"
)

func main() {
	if len(os.Args) != 4 {
		log.Fatalf("Usage: %s <user> <host:port> <command>", os.Args[0])
	}

	client, session, err := connectToHost(os.Args[1], os.Args[2])
	if err != nil {
		panic(err)
	}
	out, err := session.CombinedOutput(os.Args[3])
	if err != nil {
		panic(err)
	}
	fmt.Println(string(out))
	client.Close()
}

func connectToHost(user, host string) (*ssh.Client, *ssh.Session, error) {
	var pass string
	fmt.Print("Password: ")
	fmt.Scanf("%s\n", &pass)

	sshConfig := &ssh.ClientConfig{
		User: user,
		Auth: []ssh.AuthMethod{ssh.Password(pass)},
	}
	sshConfig.HostKeyCallback = ssh.InsecureIgnoreHostKey()

	client, err := ssh.Dial("tcp", host, sshConfig)
	if err != nil {
		return nil, nil, err
	}

	session, err := client.NewSession()
	if err != nil {
		client.Close()
		return nil, nil, err
	}

	return client, session, nil
}
$  ./aaaaa username *******.hahwul.com:22 ls
Password: ********
1
1.go
1.html
1.html-orig.xml
1.txt
123
123.md
123.png
.......

ssh client (password / public key)

https://gist.github.com/HwDhyeon/4250215d5166bc0244df8978af2e7e71

@hahwul
Copy link
Owner Author

hahwul commented Jul 25, 2021

@hahwul
Copy link
Owner Author

hahwul commented Jul 25, 2021

type AuthMethod
func GSSAPIWithMICAuthMethod(gssAPIClient GSSAPIClient, target string) AuthMethod
func KeyboardInteractive(challenge KeyboardInteractiveChallenge) AuthMethod
func Password(secret string) AuthMethod
func PasswordCallback(prompt func() (secret string, err error)) AuthMethod
func PublicKeys(signers ...Signer) AuthMethod
func PublicKeysCallback(getSigners func() (signers []Signer, err error)) AuthMethod
func RetryableAuthMethod(auth AuthMethod, maxTries int) AuthMethod

type Session
func (s *Session) Close() error
func (s *Session) CombinedOutput(cmd string) ([]byte, error)
func (s *Session) Output(cmd string) ([]byte, error)
func (s *Session) RequestPty(term string, h, w int, termmodes TerminalModes) error
func (s *Session) RequestSubsystem(subsystem string) error
func (s *Session) Run(cmd string) error
func (s *Session) SendRequest(name string, wantReply bool, payload []byte) (bool, error)
func (s *Session) Setenv(name, value string) error
func (s *Session) Shell() error
func (s *Session) Signal(sig Signal) error
func (s *Session) Start(cmd string) error
func (s *Session) StderrPipe() (io.Reader, error)
func (s *Session) StdinPipe() (io.WriteCloser, error)
func (s *Session) StdoutPipe() (io.Reader, error)
func (s *Session) Wait() error
func (s *Session) WindowChange(h, w int) error

@hahwul
Copy link
Owner Author

hahwul commented Jul 25, 2021

@hahwul hahwul modified the milestone: v1.1.0 Oct 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant