goph

package module
v2.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 18 Imported by: 0

README ΒΆ

Golang SSH Client.

Fast and easy golang ssh client module.

Goph is a lightweight Go SSH client focusing on simplicity!

Features ❘ Installation ❘ Get Started ❘ Usage Examples ❘ License

🀘  Features

  • Easy to use and simple API
  • Supports known hosts by default.
  • Supports connections with passwords.
  • Supports connections with private keys.
  • Supports connections with protected private keys with passphrase.
  • Supports multiple auth methods in a single connection.
  • Supports upload files from local to remote.
  • Supports download files from remote to local.
  • Supports connections with ssh agent.
  • Supports connections with custom signers.
  • Supports adding new hosts to known_hosts file.
  • Supports host key callback check from default known_hosts file.
  • Supports file operations like: Open, Create, Chmod... via SFTP.
  • Supports context.Context for command cancellation.
  • Supports SOCKS5 proxy for connecting through intermediaries.
  • Supports proxy jump for connecting through jump hosts.

πŸš€Β  Installation

go get github.com/melbahja/goph/v2

πŸ“„Β  Get Started

Run a command via ssh can be simple as this example:

package main

import (
	"log"
	"fmt"
	"github.com/melbahja/goph"
)

func main() {

	// Start new ssh connection with private key.
	client, err := goph.New("root", "192.1.1.3", goph.WithPassword("try_password_first"))
	if err != nil {
		log.Fatal(err)
	}

	// Defer closing the network connection.
	defer client.Close()

	// Execute your command.
	out, err := client.Run("ls /tmp/")

	if err != nil {
		log.Fatal(err)
	}

	// Get your output as []byte.
	fmt.Println(string(out))
}

Docs are available in Go Docs.

πŸ“šΒ  Usage Examples

Expand each group then expand individual examples.

πŸ”Β  Authentication Examples

Password Authentication
client, err := goph.New("root", "192.1.1.3",
	goph.WithPassword("your_password"),
)
Key File Authentication
client, err := goph.New("root", "192.1.1.3",
	goph.WithKeyFile("/home/user/.ssh/id_rsa", ""),
)
Protected Private Key (with Passphrase)
client, err := goph.New("root", "192.1.1.3",
	goph.WithKeyFile("/home/user/.ssh/id_rsa", "passphrase"),
)
Raw Private Key (from bytes)
privateKey, _ := os.ReadFile("/home/user/.ssh/id_rsa")
client, err := goph.New("root", "192.1.1.3",
	goph.WithKey(privateKey, "passphrase"),
)
SSH Agent (auto-detect)
if goph.HasAgent() {
	client, err := goph.New("root", "192.1.1.3",
		goph.WithDefaultAgent(),
	)
}
Custom Agent Socket Path
client, err := goph.New("root", "192.1.1.3",
	goph.WithAgentSocket("/run/user/1000/keyring/ssh"),
)
Custom Agent Connection (net.Conn)
conn, err := net.Dial("unix", "/custom/agent.sock")
if err != nil {
	log.Fatal(err)
}

client, err := goph.New("root", "192.1.1.3",
	goph.WithAgent(conn),
)
Keyboard-Interactive (password prompt)
client, err := goph.New("root", "192.1.1.3",
	goph.WithKeyboardInteractive(func(user, instruction, question string, echo bool) (string, error) {
		if strings.Contains(strings.ToLower(question), "password") {
			return "your_password", nil
		}
		return "", fmt.Errorf("unexpected prompt: %s", question)
	}),
)
Keyboard-Interactive OTP / 2FA
client, err := goph.New("root", "192.1.1.3",
	goph.WithKeyboardInteractive(func(user, instruction, question string, echo bool) (string, error) {
		if strings.Contains(strings.ToLower(question), "otp") ||
			strings.Contains(strings.ToLower(question), "verification code") {
			fmt.Print(question, " ")
			var code string
			fmt.Scanln(&code)
			return code, nil
		}
		return "", fmt.Errorf("unexpected prompt: %s", question)
	}),
)
Multiple Auth Methods
client, err := goph.New("root", "192.1.1.3",
	goph.WithPassword("try_password_first"),
	goph.WithKeyFile("/home/user/.ssh/id_rsa", "passphrase"),
	goph.WithDefaultAgent(),
)
Custom Signer (any ssh.Signer)
signer, err := ssh.NewSignerFromKey(myPrivateKey) // or from any source
if err != nil {
	log.Fatal(err)
}

client, err := goph.New("root", "192.1.1.3",
	goph.WithSigner(signer),
)
Custom Auth Method (ssh.AuthMethod)
client, err := goph.New("root", "192.1.1.3",
	goph.WithAuth(ssh.Password("pass")),
	goph.WithAuth(ssh.PublicKeysCallback(myCustomCallback)),
)

πŸ“‘Β  Features Examples

Custom Port and Timeout
client, err := goph.New("root", "192.1.1.3",
	goph.WithPassword("pass"),
	goph.WithPort(2222),
	goph.WithTimeout(10*time.Second),
)
Known Hosts Verification (Default)
// Known hosts verification is ON by default via ~/.ssh/known_hosts
client, err := goph.New("root", "192.1.1.3",
	goph.WithPassword("pass"),
)

// Or specify a custom known_hosts file:
client, err := goph.New("root", "192.1.1.3",
	goph.WithPassword("pass"),
	goph.WithKnownHosts("/path/to/known_hosts"),
)
Disable Host Key Verification (Insecure)
client, err := goph.New("root", "192.1.1.3",
	goph.WithPassword("pass"),
	goph.WithInsecureIgnoreHostKey(),
)
Custom Host Key Callback
hostKeyCallback := func(hostname string, remote net.Addr, key ssh.PublicKey) error {
	// Check the key against a database or prompt the user
	return nil
}

client, err := goph.New("root", "192.1.1.3",
	goph.WithPassword("pass"),
	goph.WithHostKeyCallback(hostKeyCallback),
)
Banner Callback
client, err := goph.New("root", "192.1.1.3",
	goph.WithPassword("pass"),
	goph.WithBannerCallback(func(message string) error {
		log.Printf("SSH Banner: %s", message)
		return nil
	}),
)
Connect Through SOCKS5 Proxy
client, err := goph.New("root", "target-host",
	goph.WithPassword("pass"),
	goph.WithProxy("socks5://127.0.0.1:1080"),
)

// With proxy authentication:
client, err = goph.New("root", "target-host",
	goph.WithPassword("pass"),
	goph.WithProxy("socks5://proxyuser:proxypass@127.0.0.1:1080"),
)
Connect Through Jump Host (Bastion)
// First connect to the jump host
jump, err := goph.New("jumpuser", "bastion.example.com",
	goph.WithKeyFile("/home/user/.ssh/id_rsa", ""),
	goph.WithPort(2222),
)
if err != nil {
	log.Fatal(err)
}
defer jump.Close()

// Then tunnel through it to the target
client, err := goph.New("root", "internal-host",
	goph.WithKeyFile("/home/user/.ssh/id_rsa", ""),
	goph.WithJump(jump),
)
Proxy + Jump Host Together
// Put the proxy on the JUMP client, then pass the jump to the target
jump, err := goph.New("jumpuser", "bastion.example.com",
	goph.WithKeyFile("/home/user/.ssh/id_rsa", ""),
	goph.WithProxy("socks5://127.0.0.1:1080"),
)
if err != nil {
	log.Fatal(err)
}
defer jump.Close()

client, err := goph.New("root", "internal-host",
	goph.WithKeyFile("/home/user/.ssh/id_rsa", ""),
	goph.WithJump(jump),
)
Run a Command
out, err := client.Run("ls /tmp/")
if err != nil {
	log.Fatal(err)
}
fmt.Println(string(out))
Run with Timeout (Context)
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

// Sends SIGINT and returns error after 1 second
out, err := client.RunContext(ctx, "sleep 5")
Cancel from Another Goroutine
ctx, cancel := context.WithCancel(context.Background())
cmd, err := client.CommandContext(ctx, "sleep", "60")
if err != nil {
	log.Fatal(err)
}

// Cancel from another goroutine
go func() {
	time.Sleep(5 * time.Second)
	cancel()
}()

if err := cmd.Run(); err != nil {
	// context canceled
	fmt.Println("Command stopped:", err)
}
Custom Cancel Function (override SIGINT)
cmd, err := client.CommandContext(ctx, "sleep", "30")
if err != nil {
	log.Fatal(err)
}

// Send SIGKILL instead of the default SIGINT on cancellation
cmd.Cancel = func() error {
	return cmd.Signal(ssh.SIGKILL)
}

if err := cmd.Run(); err != nil {
	log.Fatal(err)
}
Using Cmd for Fine Control
cmd, err := client.Command("ls", "-alh", "/tmp")
if err != nil {
	log.Fatal(err)
}

// Set env vars (server must accept them)
cmd.Env = []string{"MY_VAR=MYVALUE"}

// Run (CombinedOutput, Output, Start, Wait also available)
err = cmd.Run()

// With context:
cmd, err = client.CommandContext(ctx, "ls", "-alh", "/tmp")
Upload File
err := client.Upload("/path/to/local/file", "/path/to/remote/file")
Download File
err := client.Download("/path/to/remote/file", "/path/to/local/file")
SFTP File Operations
sftp, err := client.NewSftp()
if err != nil {
	log.Fatal(err)
}
defer sftp.Close()

// Create a file
file, err := sftp.Create("/tmp/remote_file")
if err != nil {
	log.Fatal(err)
}
defer file.Close()

file.Write([]byte("Hello world"))

// Open existing file
f, _ := sftp.Open("/etc/hostname")
// ... read from f

// Other methods: MkdirAll, Remove, Rename, ReadDir, Stat, etc.
Execute a Script (streaming from io.Reader)
// Execute a script from any io.Reader (e.g. a string, a file handle, an HTTP body)
cmd, err := client.Script(ctx, strings.NewReader("echo hello"))
if err != nil {
	log.Fatal(err)
}
out, err := cmd.CombinedOutput()
Execute a Script File
// Read a local script file into memory and execute it on the remote host
cmd, err := client.ScriptFile(ctx, "/path/to/local/script.sh")
if err != nil {
	log.Fatal(err)
}

// Override the interpreter for a PHP script:
cmd, err = client.ScriptFile(ctx, "/path/to/script.php", goph.WithPath("/usr/bin/php"))

// Override the shell path (default: /bin/sh)
cmd, err = client.ScriptFile(ctx, "/path/to/local/script.sh", goph.WithPath("/bin/zsh"))
Override Config Before Dial
client, err := goph.New("root", "192.1.1.3",
	goph.WithPassword("pass"),
	goph.WithConfig(func(config *ssh.ClientConfig) error {
		config.Timeout = 30 * time.Second
		config.ClientVersion = "SSH-2.0-MyApp"
		return nil
	}),
)
Low-Level: Custom ssh.ClientConfig (Dial)
c := &goph.Client{
	User: "root",
	Addr: "192.1.1.3",
	Port: 22,
}

config := &ssh.ClientConfig{
	Auth:            []ssh.AuthMethod{ssh.Password("pass")},
	HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}

if err := goph.Dial(c, config); err != nil {
	log.Fatal(err)
}
defer c.Close()
Reusable Dialer (Multiple Connections)
d := goph.NewDialer(
	goph.WithKeyFile("/home/user/.ssh/id_rsa", ""),
	goph.WithPort(2222),
)

client1, _ := d.New("root", "host1")
client2, _ := d.New("root", "host2", goph.WithPassword("fallback"))

πŸ› οΈΒ  Utils and Helpers

Check if Host is Known
found, err := goph.CheckKnownHost("myhost", remoteAddr, publicKey, "")
if err != nil {
	// key mismatch! possible MITM attack!
	log.Fatal(err)
}
if !found {
	// host is new, ask user to trust it
}
Add Host to Known Hosts
err := goph.AddKnownHost("myhost", remoteAddr, publicKey, "")
Parse Private Key File
signer, err := goph.ParseKeyFile("/home/user/.ssh/id_rsa", "passphrase")
if err != nil {
	log.Fatal(err)
}

client, err := goph.New("root", "192.1.1.3",
	goph.WithSigner(signer),
)
Parse Raw Key (from bytes)
keyBytes, _ := os.ReadFile("/home/user/.ssh/id_rsa")
signer, err := goph.ParseKey(keyBytes, "passphrase")
if err != nil {
	log.Fatal(err)
}

client, err := goph.New("root", "192.1.1.3",
	goph.WithSigner(signer),
)
Check SSH Agent Availability
if goph.HasAgent() {
	fmt.Println("SSH agent is available at", os.Getenv("SSH_AUTH_SOCK"))
} else {
	fmt.Println("SSH agent not running or SSH_AUTH_SOCK not set")
}
Default Known Hosts Path and Ensure
path, err := goph.DefaultKnownHostsPath()
if err != nil {
	log.Fatal(err)
}
fmt.Println("Known hosts file:", path)

// EnsureKnownHosts returns a callback and creates the file (and ~/.ssh/)
// if it does not exist yet β€” useful when writing first-time tools.
cb, err := goph.EnsureKnownHosts(filepath.Join(os.Getenv("HOME"), ".ssh", "my_hosts"))
if err != nil {
	log.Fatal(err)
}

client, err := goph.New("root", "192.1.1.3",
	goph.WithPassword("pass"),
	goph.WithHostKeyCallback(cb),
)

πŸ›‘οΈΒ  Security Notes

  • Known-hosts verification is enabled by default. Do not use goph.WithInsecureIgnoreHostKey() in production; it makes you vulnerable to MITM attacks.
  • A missing ~/.ssh/known_hosts file is created automatically as an empty file, but unknown host keys are still rejected until you explicitly trust them.
  • Command arguments are not shell-escaped. Cmd.String() returns raw Path and Args. Never pass untrusted input directly into commands; sanitize or use fixed argument lists.
  • Prompt the user before calling goph.AddKnownHost. A mismatched key from goph.CheckKnownHost should be treated as a potential MITM attack.

❓  FAQ

Expand each question to see the answer.

Why is there no Dir field like os/exec.Cmd?

SSH exec requests do not support setting a working directory in the protocol. The server runs the command in the user's default shell context (typically their home directory). To run a command in a specific directory, prefix it:

out, err := client.Run("cd /var/log && ls -la")
How do I run sudo commands?

Either connect as root, or use sudo -S and feed the password through stdin. Be aware that sudo may require a TTY, which goph does not provide by default:

cmd, err := client.Command("sudo", "-S", "systemctl", "restart", "nginx")
if err != nil {
	log.Fatal(err)
}

cmd.Stdin = strings.NewReader("your_sudo_password\n")
out, err := cmd.CombinedOutput()
Does goph work on Windows?

Yes. goph is pure Go and works on Windows, Linux, and macOS. For Windows-specific key providers (CNG/CAPI, Pageant, named-pipe OpenSSH agent), build or obtain an ssh.Signer and use WithSigner:

signer, err := ssh.NewSignerFromKey(myPrivateKey)
client, err := goph.New("user", "host", goph.WithSigner(signer))

🀝  Missing a Feature?

Feel free to open a new issue, or contact me.

πŸ“˜Β  License

Goph is provided under the MIT License.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const DefaultClientVersion = "SSH-2.0-Goph"

DefaultClientVersion is the SSH client version sent during handshake.

Variables ΒΆ

This section is empty.

Functions ΒΆ

func AddKnownHost ΒΆ

func AddKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (err error)

AddKnownHost add a a host to known hosts file.

func CheckKnownHost ΒΆ

func CheckKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (found bool, err error)

CheckKnownHost checks is host in known hosts file. it returns is the host found in known_hosts file and error, if the host found in known_hosts file and error not nil that means public key mismatch, maybe MAN IN THE MIDDLE ATTACK! you should not handshake.

func DefaultKnownHosts ΒΆ

func DefaultKnownHosts() (ssh.HostKeyCallback, error)

DefaultKnownHosts returns a host key callback from the default known hosts path. It ensures an empty known_hosts file exists, so first-time users get a "host not found" result instead of a file read error.

func DefaultKnownHostsPath ΒΆ

func DefaultKnownHostsPath() (string, error)

DefaultKnownHostsPath returns default user knows hosts file.

func Dial ΒΆ

func Dial(c *Client, config *ssh.ClientConfig) error

Dial establishes the SSH connection described by c and config. It honors c.User, c.ProxyURL, c.Jump, and c.Port, and applies the default known hosts callback if HostKeyCallback is nil.

If config.User is empty, it is set from c.User. If c.User is also empty, the current OS user is used, matching OpenSSH default behavior.

func EnsureKnownHosts ΒΆ

func EnsureKnownHosts(file string) (ssh.HostKeyCallback, error)

EnsureKnownHosts returns a host key callback from a custom known hosts path, Creating the file (and its parent directory) if it does not exist.

func HasAgent ΒΆ

func HasAgent() bool

HasAgent checks if ssh agent exists via the SSH_AUTH_SOCK env variable.

func KnownHosts ΒΆ

func KnownHosts(file string) (ssh.HostKeyCallback, error)

KnownHosts returns a host key callback from a custom known hosts path. The file must already exist; if it is or may be missing, use EnsureKnownHosts.

func ParseKey ΒΆ

func ParseKey(privateKey []byte, passphrase string) (signer ssh.Signer, err error)

ParseKey returns an ssh.Signer from raw PEM encoded private key bytes.

func ParseKeyFile ΒΆ

func ParseKeyFile(prvFile string, passphrase string) (ssh.Signer, error)

ParseKeyFile returns an ssh.Signer from a private key file.

Types ΒΆ

type Client ΒΆ

type Client struct {
	*ssh.Client

	User     string
	Addr     string
	Port     uint
	ProxyURL string
	Jump     *Client
}

Client represents a Goph SSH client.

func New ΒΆ

func New(user, addr string, opts ...Option) (*Client, error)

New starts a new SSH connection. By default it uses the default known_hosts file for host key verification, port 22, and a 20 second timeout. Override with With* options.

func (*Client) Close ΒΆ

func (c *Client) Close() error

Close closes the SSH connection.

func (*Client) Command ΒΆ

func (c *Client) Command(name string, args ...string) (*Cmd, error)

Command returns new Cmd and error if any.

func (*Client) CommandContext ΒΆ

func (c *Client) CommandContext(ctx context.Context, name string, args ...string) (*Cmd, error)

CommandContext returns new Cmd with context and error, if any.

func (*Client) Download ΒΆ

func (c *Client) Download(remotePath string, localPath string) (err error)

Download file from remote server.

func (*Client) NewSftp ΒΆ

func (c *Client) NewSftp(opts ...sftp.ClientOption) (*sftp.Client, error)

NewSftp returns a new SFTP client.

func (*Client) Run ΒΆ

func (c *Client) Run(cmd string) ([]byte, error)

Run starts a new SSH session and runs the cmd, it returns CombinedOutput and err if any.

func (*Client) RunContext ΒΆ

func (c *Client) RunContext(ctx context.Context, name string) ([]byte, error)

RunContext starts a new SSH session with context and runs the cmd.

func (*Client) Script ΒΆ

func (c *Client) Script(ctx context.Context, r io.Reader, opts ...CmdOption) (cmd *Cmd, err error)

Script runs a script from an io.Reader on the remote host via /bin/sh you can override (with WithPath).

func (*Client) ScriptFile ΒΆ

func (c *Client) ScriptFile(ctx context.Context, localPath string, opts ...CmdOption) (*Cmd, error)

ScriptFile reads the local script file into memory and executes it on the remote. Warning: the entire file is loaded into memory. Use Script with an io.Reader directly for large files.

func (*Client) Upload ΒΆ

func (c *Client) Upload(localPath string, remotePath string) (err error)

Upload a local file to the remote server.

type Cmd ΒΆ

type Cmd struct {

	// SSH session.
	*ssh.Session

	// Path to command executable filename
	Path string

	// Command args.
	Args []string

	// Session env vars.
	Env []string

	// Cancel is called when Context is done.
	// If non-nil, it replaces the default ssh.SIGINT signal.
	// If nil, ssh.SIGINT is sent on cancellation.
	Cancel func() error
	// contains filtered or unexported fields
}

Cmd it's like os/exec.Cmd but for ssh session.

func (*Cmd) CombinedOutput ΒΆ

func (c *Cmd) CombinedOutput() ([]byte, error)

CombinedOutput runs cmd on the remote host and returns its combined stdout and stderr.

func (*Cmd) Output ΒΆ

func (c *Cmd) Output() ([]byte, error)

Output runs cmd on the remote host and returns its stdout.

func (*Cmd) Run ΒΆ

func (c *Cmd) Run() (err error)

Run runs cmd on the remote host.

func (*Cmd) Start ΒΆ

func (c *Cmd) Start() (err error)

Start runs the command on the remote host.

func (*Cmd) String ΒΆ

func (c *Cmd) String() string

String returns the command line string.

WARNING: Path and Args are joined as is without any shell escaping. If Path or Args contain untrusted input, remote command injection is possible. Sanitize or shell quote untrusted values yourself before building the Cmd, or use a shell quoting helper from your application.

type CmdOption ΒΆ

type CmdOption func(*Cmd)

CmdOption configures a Cmd after creation.

func WithPath ΒΆ

func WithPath(path string) CmdOption

WithPath sets the command executable path (default for Script: "/bin/sh").

func WithStderr ΒΆ

func WithStderr(w io.Writer) CmdOption

WithStderr sets the remote command's stderr writer.

func WithStdout ΒΆ

func WithStdout(w io.Writer) CmdOption

WithStdout sets the remote command's stdout writer.

type Dialer ΒΆ

type Dialer struct {
	// contains filtered or unexported fields
}

Dialer holds reusable connection options for establishing SSH connections.

d := goph.NewDialer(goph.WithKeyFile("id_rsa", ""))
c1, _ := d.New("root", "host1")
c2, _ := d.New("root", "host2", goph.WithPort(2222))

func NewDialer ΒΆ

func NewDialer(opts ...Option) *Dialer

NewDialer creates a Dialer with the given options.

func (Dialer) New ΒΆ

func (d Dialer) New(user, addr string, opts ...Option) (*Client, error)

New establishes an SSH connection using the Dialer options merged with per call options. Per call options take precedence (applied after).

type Option ΒΆ

type Option func(*Client, *ssh.ClientConfig) error

Option is a functional option for configuring a Client.

func WithAgent ΒΆ

func WithAgent(conn net.Conn) Option

WithAgent sets SSH agent authentication from an existing agent net.Conn. The conn must be connected to an SSH agent (Unix socket, Windows pipe, etc.). Silently skips if conn is nil.

func WithAgentSocket ΒΆ

func WithAgentSocket(socket string) Option

WithAgentSocket sets SSH agent authentication from a Unix socket path. Silently skips if the agent socket is unavailable. The socket is dialed lazily during the SSH handshake, so this option is safe to apply multiple times (e.g. for connection key calculation).

func WithAuth ΒΆ

func WithAuth(method ssh.AuthMethod) Option

WithAuth appends a custom ssh.AuthMethod.

func WithBannerCallback ΒΆ

func WithBannerCallback(cb ssh.BannerCallback) Option

WithBannerCallback sets a banner callback.

func WithConfig ΒΆ

func WithConfig(fn func(*ssh.ClientConfig) error) Option

WithConfig applies a callback to the underlying *ssh.ClientConfig before dial.

func WithDefaultAgent ΒΆ

func WithDefaultAgent() Option

WithDefaultAgent sets SSH agent authentication using the SSH_AUTH_SOCK environment variable.

func WithHostKeyCallback ΒΆ

func WithHostKeyCallback(cb ssh.HostKeyCallback) Option

WithHostKeyCallback sets a custom host key callback.

func WithInsecureIgnoreHostKey ΒΆ

func WithInsecureIgnoreHostKey() Option

WithInsecureIgnoreHostKey disables host key verification.

func WithJump ΒΆ

func WithJump(jumpClient *Client) Option

WithJump sets a pre connected jump client to tunnel through.

func WithKey ΒΆ

func WithKey(pemBytes []byte, passphrase string) Option

WithKey sets public key authentication from raw PEM encoded key bytes.

func WithKeyFile ΒΆ

func WithKeyFile(keyFile string, passphrase string) Option

WithKeyFile sets public key authentication from a private key file.

func WithKeyboardInteractive ΒΆ

func WithKeyboardInteractive(handler func(user, instruction, question string, echo bool) (string, error)) Option

WithKeyboardInteractive sets keyboard interactive authentication using a user provided handler, the handler is called once for each prompt the server sends, and returns the answer or an error.

func WithKnownHosts ΒΆ

func WithKnownHosts(path string) Option

WithKnownHosts uses the known hosts file for host key verification.

func WithPassword ΒΆ

func WithPassword(password string) Option

WithPassword sets password authentication.

func WithPort ΒΆ

func WithPort(port uint) Option

WithPort sets the SSH port.

func WithProxy ΒΆ

func WithProxy(socks5URL string) Option

WithProxy routes the SSH connection through a SOCKS5 proxy. eg like socks5://127.0.0.1:1080

func WithSigner ΒΆ

func WithSigner(signer ssh.Signer) Option

WithSigner appends public key authentication from an ssh.Signer.

func WithTimeout ΒΆ

func WithTimeout(d time.Duration) Option

WithTimeout sets the connection timeout.

Directories ΒΆ

Path Synopsis
examples
goph command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL