Better SSH handling #6

Closed
opened 1 year ago by CyberShell · 1 comments
Owner

Implement better SSH handling.

Maybe functional programming.

Inspiration:

https://github.com/melbahja/goph

Implement better SSH handling. Maybe functional programming. Inspiration: https://github.com/melbahja/goph
CyberShell added this to the Plans project 1 year ago
CyberShell modified the project from Plans to Version 0.1.0 1 year ago
CyberShell modified the project from Version 0.1.0 to Plans 1 year ago
Poster
Owner

https://stackoverflow.com/questions/35906991/go-x-crypto-ssh-how-to-establish-ssh-connection-to-private-instance-over-a-ba

You can do this even more directly with the "x/crypto/ssh" without the nc command, since there is a method to dial a connection from the remote host and presents it as a net.Conn.

Once you have an ssh.Client, you can use the Dial method to get a virtual net.Conn between you and the final host. You can then turn that into a new ssh.Conn with ssh.NewClientConn, and create a new ssh.Client with ssh.NewClient

// connect to the bastion host
bClient, err := ssh.Dial("tcp", bastionAddr, config)
if err != nil {
    log.Fatal(err)
}

// Dial a connection to the service host, from the bastion
conn, err := bClient.Dial("tcp", serviceAddr)
if err != nil {
    log.Fatal(err)
}

ncc, chans, reqs, err := ssh.NewClientConn(conn, serviceAddr, config)
if err != nil {
    log.Fatal(err)
}

sClient := ssh.NewClient(ncc, chans, reqs)
// sClient is an ssh client connected to the service host, through the bastion host.
https://stackoverflow.com/questions/35906991/go-x-crypto-ssh-how-to-establish-ssh-connection-to-private-instance-over-a-ba You can do this even more directly with the "x/crypto/ssh" without the `nc` command, since there is a method to dial a connection from the remote host and presents it as a net.Conn. Once you have an `ssh.Client`, you can use the [`Dial`](https://godoc.org/golang.org/x/crypto/ssh#Client.Dial) method to get a virtual net.Conn between you and the final host. You can then turn that into a new `ssh.Conn` with [`ssh.NewClientConn`](https://godoc.org/golang.org/x/crypto/ssh#NewClientConn), and create a new `ssh.Client` with [`ssh.NewClient`](https://godoc.org/golang.org/x/crypto/ssh#NewClient) ```go // connect to the bastion host bClient, err := ssh.Dial("tcp", bastionAddr, config) if err != nil { log.Fatal(err) } // Dial a connection to the service host, from the bastion conn, err := bClient.Dial("tcp", serviceAddr) if err != nil { log.Fatal(err) } ncc, chans, reqs, err := ssh.NewClientConn(conn, serviceAddr, config) if err != nil { log.Fatal(err) } sClient := ssh.NewClient(ncc, chans, reqs) // sClient is an ssh client connected to the service host, through the bastion host. ```
CyberShell closed this issue 1 year ago
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: CyberShell/backy#6
Loading…
There is no content yet.