Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rjeczalik/gsh
SSH for Go on steroids
https://github.com/rjeczalik/gsh
Last synced: about 2 months ago
JSON representation
SSH for Go on steroids
- Host: GitHub
- URL: https://github.com/rjeczalik/gsh
- Owner: rjeczalik
- License: apache-2.0
- Created: 2021-10-24T03:47:07.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-23T07:33:33.000Z (almost 3 years ago)
- Last Synced: 2024-06-20T00:32:06.482Z (6 months ago)
- Language: Go
- Size: 35.2 KB
- Stars: 4
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gsh
`tectum.sh/gsh` is yet another wrapper for the golang.org/x/crypto/ssh package. `gsh` is both a Go client API and a command line tool.
Since it understand OpenSSH's configuration files, it can be used as a drop-in replacement for ssh for simple use-case (it is not feature-complete yet).
### Getting started with the command line tool
The quickest way to give the `gsh` a try is to use provided Docker images. Once the container is built and started, it will serve as OpenSSH server that the `gsh` can connect to.
In order to build and start the container, run the following commands:
```bash
./sshtest/build.sh
```
```bash
docker run --rm -d -ti -p 2222:22 -P sshtest-ubuntu:latest
```Then build the `gsh` command line tool and connect to the container:
```bash
go build github.com/rjeczalik/gsh/cmd/gsh
```
```bash
gsh -F sshtest/ssh.config sshtest
```
```
To run a command as administrator (user "root"), use "sudo ".
See "man sudo_root" for details.sshtest@9ddf71ccfd81:~$
```### Getting started with the client API
Equivalent code for the above `gsh` command looks like the following:
```go
package mainimport (
"context"
"log""github.com/rjeczalik/gsh"
"github.com/rjeczalik/gsh/sshfile"
"github.com/rjeczalik/gsh/sshutil"
)func main() {
ctx := context.Background()cfg := &sshfile.Config{
User: "sshtest",
Hostname: "127.0.0.1",
Port: 2222,
IdentityFile: "sshtest/key.pem",
}client := &gsh.Client{
ConfigCallback: cfg.Callback(),
DialContext: sshutil.DialContext,
}conn, err := client.Connect(ctx, "tcp", "")
if err != nil {
log.Fatal(err)
}shell := gsh.Command("/bin/bash").Shell()
if err := conn.Session(shell); err != nil {
log.Fatal(err)
}
}
```Give it a try by running:
```bash
go run examples/sshtest.go
```
```
To run a command as administrator (user "root"), use "sudo ".
See "man sudo_root" for details.sshtest@9ddf71ccfd81:~$
```