Better SSH handling #6

Closed
opened 2023-01-20 18:54:57 +00:00 by CyberShell · 1 comment
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 2023-01-20 18:55:05 +00:00
CyberShell modified the project from Plans to Version 0.1.0 2023-01-20 23:45:39 +00:00
CyberShell modified the project from Version 0.1.0 to Plans 2023-01-22 01:37:05 +00:00
Author
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. ```
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: CyberShell/backy#6
No description provided.