Top Related Projects
Portable OpenSSH
The leading native Python SSHv2 protocol library.
[mirror] Go supplementary cryptography libraries
Win32 port of OpenSSH
the SSH library
Quick Overview
Gliderlabs/ssh is a Go library that provides an alternative SSH server implementation. It offers a high-level API for building SSH servers, making it easier to create custom SSH services without dealing with low-level details of the SSH protocol.
Pros
- Simplified API for building SSH servers in Go
- Flexible and customizable, allowing for easy implementation of custom authentication and command handling
- Well-documented with clear examples and use cases
- Actively maintained with regular updates and improvements
Cons
- Limited to Go programming language
- May not be suitable for projects requiring full control over low-level SSH protocol details
- Potential learning curve for developers not familiar with Go or SSH concepts
Code Examples
- Basic SSH server setup:
package main
import (
"fmt"
"io"
"log"
"github.com/gliderlabs/ssh"
)
func main() {
ssh.Handle(func(s ssh.Session) {
io.WriteString(s, fmt.Sprintf("Hello %s\n", s.User()))
})
log.Fatal(ssh.ListenAndServe(":2222", nil))
}
- Custom authentication:
ssh.Server{
Addr: ":2222",
PasswordHandler: func(ctx ssh.Context, password string) bool {
return password == "secret"
},
}.ListenAndServe()
- Handling SSH commands:
ssh.Handle(func(s ssh.Session) {
cmd := s.Command()
if len(cmd) == 0 {
fmt.Fprintf(s, "No command specified\n")
return
}
fmt.Fprintf(s, "You ran: %s\n", cmd[0])
})
Getting Started
To use gliderlabs/ssh in your Go project:
-
Install the library:
go get github.com/gliderlabs/ssh
-
Import the library in your Go code:
import "github.com/gliderlabs/ssh"
-
Create a basic SSH server:
func main() { ssh.Handle(func(s ssh.Session) { io.WriteString(s, "Welcome to my SSH server\n") }) log.Fatal(ssh.ListenAndServe(":2222", nil)) }
-
Run your Go program and connect to the SSH server using an SSH client:
ssh localhost -p 2222
Competitor Comparisons
Portable OpenSSH
Pros of openssh-portable
- Comprehensive and battle-tested SSH implementation
- Supports a wide range of SSH features and protocols
- Extensively audited for security vulnerabilities
Cons of openssh-portable
- Large codebase with complex architecture
- Steeper learning curve for integration into custom applications
- Requires more system resources due to its full-featured nature
Code Comparison
openssh-portable (server setup):
int
main(int ac, char **av)
{
/* Initialize the SSH server */
ssh_init();
/* Configure and start the server */
ssh_bind = ssh_bind_new();
ssh_bind_options_set(ssh_bind, SSH_BIND_OPTIONS_BINDADDR, "0.0.0.0");
ssh_bind_listen(ssh_bind);
}
ssh (server setup):
func main() {
ssh.Handle(func(s ssh.Session) {
io.WriteString(s, "Welcome to my SSH server\n")
})
log.Fatal(ssh.ListenAndServe(":2222", nil))
}
The openssh-portable example shows a more low-level C implementation with explicit initialization and configuration steps. The ssh example demonstrates a higher-level Go implementation with a simpler API, focusing on handling SSH sessions directly.
The leading native Python SSHv2 protocol library.
Pros of Paramiko
- More comprehensive SSH implementation with support for various authentication methods and SSH operations
- Extensive documentation and a large, active community
- Cross-platform compatibility (Windows, macOS, Linux)
Cons of Paramiko
- Heavier and more complex library, which may be overkill for simple SSH tasks
- Slower performance compared to gliderlabs/ssh for basic SSH server implementations
Code Comparison
Paramiko (client connection):
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('hostname', username='user', password='pass')
stdin, stdout, stderr = client.exec_command('ls -l')
print(stdout.read().decode())
gliderlabs/ssh (server implementation):
ssh.Handle(func(s ssh.Session) {
io.WriteString(s, fmt.Sprintf("Hello %s\n", s.User()))
})
log.Fatal(ssh.ListenAndServe(":2222", nil))
gliderlabs/ssh focuses on simplicity and ease of use for SSH server implementations, while Paramiko offers a more comprehensive SSH toolkit for both client and server operations. The choice between the two depends on the specific requirements of your project and the level of SSH functionality needed.
[mirror] Go supplementary cryptography libraries
Pros of crypto
- More comprehensive cryptographic functionality
- Part of the official Go project, ensuring long-term maintenance
- Extensive documentation and community support
Cons of crypto
- Higher complexity for simple SSH implementations
- Requires more setup and configuration for basic SSH tasks
- Less focused on SSH-specific features
Code Comparison
crypto:
config := &ssh.ServerConfig{
PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
if c.User() == "user" && string(pass) == "password" {
return nil, nil
}
return nil, fmt.Errorf("password rejected for %q", c.User())
},
}
ssh:
ssh.Handle(func(s ssh.Session) {
io.WriteString(s, fmt.Sprintf("Hello %s\n", s.User()))
})
ssh.ListenAndServe(":2222", nil)
Summary
crypto provides a more comprehensive cryptographic toolkit, while ssh focuses on simplifying SSH server implementation. crypto offers broader functionality but requires more setup for basic SSH tasks. ssh provides a more straightforward API for creating SSH servers but may lack some advanced features found in crypto. The choice between the two depends on the specific requirements of your project and the level of control you need over the SSH implementation.
Win32 port of OpenSSH
Pros of Win32-OpenSSH
- Full Windows integration and native support
- Comprehensive SSH functionality, including SFTP and SCP
- Actively maintained by Microsoft, ensuring long-term support
Cons of Win32-OpenSSH
- Larger codebase and more complex implementation
- Primarily focused on Windows, limiting cross-platform compatibility
- Steeper learning curve for customization and integration
Code Comparison
Win32-OpenSSH (C):
int main(int argc, char **argv) {
/* Initialize OpenSSH */
ssh_init();
/* Main SSH server loop */
ssh_server_loop();
return 0;
}
ssh (Go):
func main() {
ssh.Handle(func(s ssh.Session) {
io.WriteString(s, "Welcome to the SSH server!\n")
})
log.Fatal(ssh.ListenAndServe(":2222", nil))
}
Summary
Win32-OpenSSH provides a comprehensive SSH solution for Windows environments, offering full integration and native support. It includes a wide range of SSH functionalities and is actively maintained by Microsoft. However, it has a larger codebase and is primarily focused on Windows.
ssh, on the other hand, is a lightweight Go library for building SSH servers. It offers simplicity and ease of use, making it ideal for custom SSH server implementations. While it may not have all the features of Win32-OpenSSH, it provides greater flexibility and cross-platform compatibility.
The code comparison highlights the difference in complexity and approach between the two projects, with Win32-OpenSSH using a more traditional C implementation and ssh utilizing Go's simplicity and concurrency features.
the SSH library
Pros of libssh2
- More comprehensive and feature-rich SSH implementation
- Supports a wider range of SSH protocols and algorithms
- Better suited for complex SSH operations and integrations
Cons of libssh2
- Steeper learning curve due to its extensive API
- Requires more setup and configuration for basic use cases
- Less Go-friendly, as it's primarily a C library
Code Comparison
libssh2:
#include <libssh2.h>
LIBSSH2_SESSION *session;
session = libssh2_session_init();
if (libssh2_session_handshake(session, sock) != 0) {
fprintf(stderr, "Failure establishing SSH session\n");
}
ssh:
import "github.com/gliderlabs/ssh"
ssh.ListenAndServe(":2222", func(s ssh.Session) {
io.WriteString(s, "Welcome to my SSH server\n")
})
The libssh2 example shows the initialization of an SSH session in C, while the ssh example demonstrates a simple SSH server setup in Go. ssh provides a more straightforward API for basic SSH server functionality, making it easier to use for simpler use cases, especially in Go projects. However, libssh2 offers more flexibility and features for complex SSH implementations across various programming languages.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
gliderlabs/ssh
The Glider Labs SSH server package is dope. —@bradfitz, Go team member
This Go package 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:
package main
import (
"github.com/gliderlabs/ssh"
"io"
"log"
)
func main() {
ssh.Handle(func(s ssh.Session) {
io.WriteString(s, "Hello world\n")
})
log.Fatal(ssh.ListenAndServe(":2222", nil))
}
This package was built by @progrium after working on nearly a dozen projects at Glider Labs using SSH and collaborating with @shazow (known for ssh-chat).
Examples
A bunch of great examples are in the _examples
directory.
Usage
Contributing
Pull requests are welcome! However, since this project is very much about API design, please submit API changes as issues to discuss before submitting PRs.
Also, you can join our Slack to discuss as well.
Roadmap
- Non-session channel handlers
- Cleanup callback API
- 1.0 release
- High-level client?
Sponsors
Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]
License
Top Related Projects
Portable OpenSSH
The leading native Python SSHv2 protocol library.
[mirror] Go supplementary cryptography libraries
Win32 port of OpenSSH
the SSH library
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot