Documentation ¶
Overview ¶
Package ssh implements the SSH transport protocol.
Index ¶
- Constants
- Variables
- func NewClient(config *ssh.ClientConfig) transport.Transport
- func NewKnownHostsCallback(files ...string) (ssh.HostKeyCallback, error)
- func SetConfigHostKeyFields(cfg *ssh.ClientConfig, hostWithPort string) (*ssh.ClientConfig, error)
- type AuthMethod
- type HostKeyCallbackHelper
- type KeyboardInteractive
- type Password
- type PasswordCallback
- type PublicKeys
- type PublicKeysCallback
Constants ¶
const ( KeyboardInteractiveName = "ssh-keyboard-interactive" PasswordName = "ssh-password" PasswordCallbackName = "ssh-password-callback" PublicKeysName = "ssh-public-keys" PublicKeysCallbackName = "ssh-public-key-callback" )
The names of the AuthMethod implementations. To be returned by the Name() method. Most git servers only allow PublicKeysName and PublicKeysCallbackName.
const DefaultPort = 22
const DefaultUsername = "git"
Variables ¶
var DefaultAuthBuilder = func(user string) (AuthMethod, error) { return NewSSHAgentAuth(user) }
DefaultAuthBuilder is the function used to create a default AuthMethod, when the user doesn't provide any.
var DefaultClient = NewClient(nil)
DefaultClient is the default SSH client.
var DefaultSSHConfig sshConfig = ssh_config.DefaultUserSettings
DefaultSSHConfig is the reader used to access parameters stored in the system's ssh_config files. If nil all the ssh_config are ignored.
Functions ¶
func NewClient ¶
func NewClient(config *ssh.ClientConfig) transport.Transport
NewClient creates a new SSH client with an optional *ssh.ClientConfig.
func NewKnownHostsCallback ¶
func NewKnownHostsCallback(files ...string) (ssh.HostKeyCallback, error)
NewKnownHostsCallback returns ssh.HostKeyCallback based on a file based on a known_hosts file. http://man.openbsd.org/sshd#SSH_KNOWN_HOSTS_FILE_FORMAT
If list of files is empty, then it will be read from the SSH_KNOWN_HOSTS environment variable, example:
/home/foo/custom_known_hosts_file:/etc/custom_known/hosts_file
If SSH_KNOWN_HOSTS is not set the following file locations will be used:
~/.ssh/known_hosts /etc/ssh/ssh_known_hosts
func SetConfigHostKeyFields ¶
func SetConfigHostKeyFields(cfg *ssh.ClientConfig, hostWithPort string) (*ssh.ClientConfig, error)
SetConfigHostKeyFields sets cfg.HostKeyCallback and cfg.HostKeyAlgorithms based on OpenSSH known_hosts. cfg is modified in-place. hostWithPort must be supplied, since the algorithms will be set based on the known host keys for that specific host. Otherwise, golang.org/x/crypto/ssh can return an error upon connecting to a host whose *first* key is not known, even though other keys (of different types) are known and match properly. For background see https://github.com/go-git/go-git/issues/411 as well as https://github.com/golang/go/issues/29286 for root cause.
Types ¶
type AuthMethod ¶
type AuthMethod interface { transport.AuthMethod // ClientConfig should return a valid ssh.ClientConfig to be used to create // a connection to the SSH server. ClientConfig() (*ssh.ClientConfig, error) }
AuthMethod is the interface all auth methods for the ssh client must implement. The clientConfig method returns the ssh client configuration needed to establish an ssh connection.
type HostKeyCallbackHelper ¶
type HostKeyCallbackHelper struct { // HostKeyCallback is the function type used for verifying server keys. // If nil default callback will be create using NewKnownHostsCallback // without argument. HostKeyCallback ssh.HostKeyCallback }
HostKeyCallbackHelper is a helper that provides common functionality to configure HostKeyCallback into a ssh.ClientConfig. Deprecated in favor of SetConfigHostKeyFields (see common.go) which provides a mechanism for also setting ClientConfig.HostKeyAlgorithms for a specific host.
func (*HostKeyCallbackHelper) SetHostKeyCallback ¶
func (m *HostKeyCallbackHelper) SetHostKeyCallback(cfg *ssh.ClientConfig) (*ssh.ClientConfig, error)
SetHostKeyCallback sets the field HostKeyCallback in the given cfg. If HostKeyCallback is empty a default callback is created using NewKnownHostsCallback.
type KeyboardInteractive ¶
type KeyboardInteractive struct { User string Challenge ssh.KeyboardInteractiveChallenge }
KeyboardInteractive implements AuthMethod by using a prompt/response sequence controlled by the server.
func (*KeyboardInteractive) ClientConfig ¶
func (a *KeyboardInteractive) ClientConfig() (*ssh.ClientConfig, error)
func (*KeyboardInteractive) Name ¶
func (a *KeyboardInteractive) Name() string
func (*KeyboardInteractive) String ¶
func (a *KeyboardInteractive) String() string
type Password ¶
Password implements AuthMethod by using the given password.
func (*Password) ClientConfig ¶
func (a *Password) ClientConfig() (*ssh.ClientConfig, error)
type PasswordCallback ¶
PasswordCallback implements AuthMethod by using a callback to fetch the password.
func (*PasswordCallback) ClientConfig ¶
func (a *PasswordCallback) ClientConfig() (*ssh.ClientConfig, error)
func (*PasswordCallback) Name ¶
func (a *PasswordCallback) Name() string
func (*PasswordCallback) String ¶
func (a *PasswordCallback) String() string
type PublicKeys ¶
PublicKeys implements AuthMethod by using the given key pairs.
func NewPublicKeys ¶
func NewPublicKeys(user string, pemBytes []byte, password string) (*PublicKeys, error)
NewPublicKeys returns a PublicKeys from a PEM encoded private key. An encryption password should be given if the pemBytes contains a password encrypted PEM block otherwise password should be empty. It supports RSA (PKCS#1), PKCS#8, DSA (OpenSSL), and ECDSA private keys.
func NewPublicKeysFromFile ¶
func NewPublicKeysFromFile(user, pemFile, password string) (*PublicKeys, error)
NewPublicKeysFromFile returns a PublicKeys from a file containing a PEM encoded private key. An encryption password should be given if the pemBytes contains a password encrypted PEM block otherwise password should be empty.
func (*PublicKeys) ClientConfig ¶
func (a *PublicKeys) ClientConfig() (*ssh.ClientConfig, error)
func (*PublicKeys) Name ¶
func (a *PublicKeys) Name() string
func (*PublicKeys) String ¶
func (a *PublicKeys) String() string
type PublicKeysCallback ¶
PublicKeysCallback implements AuthMethod by asking a ssh.agent.Agent to act as a signer.
func NewSSHAgentAuth ¶
func NewSSHAgentAuth(u string) (*PublicKeysCallback, error)
NewSSHAgentAuth returns a PublicKeysCallback based on a SSH agent, it opens a pipe with the SSH agent and uses the pipe as the implementer of the public key callback function.
func (*PublicKeysCallback) ClientConfig ¶
func (a *PublicKeysCallback) ClientConfig() (*ssh.ClientConfig, error)
func (*PublicKeysCallback) Name ¶
func (a *PublicKeysCallback) Name() string
func (*PublicKeysCallback) String ¶
func (a *PublicKeysCallback) String() string