![Jeff Lindsay](/assets/img/avatar_default.png)
* context: fixed documentation to be more specific about ContextKeyConn being the key for a gossh.ServerConn
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
* server: fixes handler setup, changed to interface based handlers, added global request handler map
* tcpip: working remote forwarding
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
* context: docs typo
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
* session: always reply to unblock clients trying something
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
* tcpip: stop listening when ssh clients disconnect
Signed-off-by: Jeff Lindsay <progrium@gmail.com>
* Remote forwarding (#87)
* Update generateSigner key size to 2048 (#62)
Fixes #58
* Add syntax highlighting to readme (#67)
* small api updates (#69)
These updates make it easier to implement and pass custom Session and
Context implementations
No compatibilty breaking, all tests pass
* Move channelHandlers to avoid data race (#59)
* Update tests to work with go 1.10+ (#73)
Fixes #72
* Update shutdown to use a WaitGroup rather than sleeping (#74)
* Fix race condition in TestServerClose (#75)
In test server close, 3 things need to happen in order:
- Client session start
- Server.Close
- Client session exit (With io.EOF)
This fix ensures the client won't do anything until after the call to
close which ensure's we'll get io.EOF rather than a different error.
* Update circleci config to test multiple go versions
* Update CircleCI config to test 1.9 and the latest
The x/crypto/ssh library dropped support go < 1.9 as that's the first
version to have the math/bits library.
83c378c48d
* Wait for connections to finish when shutting down
PR #74 introduced a WaitGroup for listeners, but it doesn't wait for
open connections before closing the server. This patch waits until all
conns are closed before returning from Shutdown.
* Support port forwarding of literal IPv6 addresses (#85)
* Support port forwarding of literal IPv6 addresses
To disambiguate between colons as host:port separators and as IPv6 address separators, literal IPv6 addresses use square brackets around the address (https://en.wikipedia.org/wiki/IPv6_address#Literal_IPv6_addresses_in_network_resource_identifiers). So host ::1, port 22 is written as [::1]:22, and therefore a simple concatenation of host, colon, and port doesn't work. Fortunately net.JoinHostPort already implements this functionality, so with a bit of type gymnastics we can generate dest in an IPv6-safe way.
* Support port forwarding of literal IPv6 addresses
To disambiguate between colons as host:port separators and as IPv6 address separators, literal IPv6 addresses use square brackets around the address (https://en.wikipedia.org/wiki/IPv6_address#Literal_IPv6_addresses_in_network_resource_identifiers). So host ::1, port 22 is written as [::1]:22, and therefore a simple concatenation of host, colon, and port doesn't work. Fortunately net.JoinHostPort already implements this functionality, so with a bit of type gymnastics we can generate dest in an IPv6-safe way.
* Reverse port forwarding callback added
* garbage removed
46 lines
1.7 KiB
Go
46 lines
1.7 KiB
Go
/*
|
|
Package ssh wraps the crypto/ssh package with a higher-level API for building
|
|
SSH servers. The goal of the API was to make it as simple as using net/http, so
|
|
the API is very similar.
|
|
|
|
You should be able to build any SSH server using only this package, which wraps
|
|
relevant types and some functions from crypto/ssh. However, you still need to
|
|
use crypto/ssh for building SSH clients.
|
|
|
|
ListenAndServe starts an SSH server with a given address, handler, and options. The
|
|
handler is usually nil, which means to use DefaultHandler. Handle sets DefaultHandler:
|
|
|
|
ssh.Handle(func(s ssh.Session) {
|
|
io.WriteString(s, "Hello world\n")
|
|
})
|
|
|
|
log.Fatal(ssh.ListenAndServe(":2222", nil))
|
|
|
|
If you don't specify a host key, it will generate one every time. This is convenient
|
|
except you'll have to deal with clients being confused that the host key is different.
|
|
It's a better idea to generate or point to an existing key on your system:
|
|
|
|
log.Fatal(ssh.ListenAndServe(":2222", nil, ssh.HostKeyFile("/Users/progrium/.ssh/id_rsa")))
|
|
|
|
Although all options have functional option helpers, another way to control the
|
|
server's behavior is by creating a custom Server:
|
|
|
|
s := &ssh.Server{
|
|
Addr: ":2222",
|
|
Handler: sessionHandler,
|
|
PublicKeyHandler: authHandler,
|
|
}
|
|
s.AddHostKey(hostKeySigner)
|
|
|
|
log.Fatal(s.ListenAndServe())
|
|
|
|
This package automatically handles basic SSH requests like setting environment
|
|
variables, requesting PTY, and changing window size. These requests are
|
|
processed, responded to, and any relevant state is updated. This state is then
|
|
exposed to you via the Session interface.
|
|
|
|
The one big feature missing from the Session abstraction is signals. This was
|
|
started, but not completed. Pull Requests welcome!
|
|
*/
|
|
package ssh
|