# README
sshx
Tiny wrapper around golang.org/x/crypto/ssh that has better defaults. Returns an *golang.org/x/crypto/ssh.Client
that can be used elsewhere
The goal being it works exactly like if you did ssh user@host
on your machine.
Features
- Handles
~/.ssh/known_hosts
on OSX thanks to skeema/knownhosts. - Uses the active SSH agent on your machine if there is one, allowing you to seamlessly connect without providing a private key (and often the password needed to decrypt that private key).
- Adds
Run(ssh, cmd) (stdout, error)
andExec(ssh, cmd) error
commands. - Allocate an interactive shell with
sshx.Shell(sshClient, workDir)
Example
// Dial a server
client, err := sshx.Dial("vagrant", "127.0.0.1:2222")
if err != nil {
// handle error
}
defer client.Close()
// Run a command
stdout, err := sshx.Run(client, "ls -al")
if err != nil {
// handle error
}
Install
go get github.com/matthewmueller/sshx
Development
First, clone the repo:
git clone https://github.com/matthewmueller/sshx
cd sshx
Next, install dependencies:
go mod tidy
Finally, try running the tests:
go test ./...
License
MIT
# Functions
Configure creates a new *ClientConfig based on sensible defaults.
Dial creates a new ssh.Client with sensible defaults.
DialConfig creates a new ssh.Client with the provided ssh config.
Dial each signer until we find one that works.
Exec a command on the remote host, piping output to os.Stdout and os.Stderr.
Run a command on the remote host, piping stderr to os.Stderr and returning stdout.
No description provided by the author
Split a user@host[:port] string into user and host.
Test the remote host connection, returning the first signer that was successfully used to connect to the remote host.