Secure Shell
Nothing here yet. Even though this is what got this whole Hugo documentation thing started again.
Nothing here yet. Even though this is what got this whole Hugo documentation thing started again.
This is just a place holder at the moment. I have not decided what I want to discuss with ssh and Go. Maybe I need to show what is possible (here is one thing)
This is the client.Listen example from Go’s documentation. As is it doesn’t run because they leave some values unassigned. For example in line 12 they define a variable to define a single known host and in line 18 they set up the check, but never assign anything to it. Either we need to assign a key, or we need to tell the client to ignore keys. Also they are only requesting a login with password (line 15) with dummy, hard coded, values.
What this code does is kind of interesting.
If someone connects to 8080 on the remote server, our client server will be
connected to them so we ca serve then a “Hello world!” message. This is similar
to the -R
switch on ssh except that our server gets to directly service the
connections.
1package main
2
3import (
4 "fmt"
5 "log"
6 "net/http"
7
8 "golang.org/x/crypto/ssh"
9)
10
11func main() {
12 var hostKey ssh.PublicKey
13 config := &ssh.ClientConfig{
14 User: "username",
15 Auth: []ssh.AuthMethod{
16 ssh.Password("password"),
17 },
18 HostKeyCallback: ssh.FixedHostKey(hostKey),
19 }
20 // Dial your ssh server.
21 conn, err := ssh.Dial("tcp", "localhost:22", config)
22 if err != nil {
23 log.Fatal("unable to connect: ", err)
24 }
25 defer conn.Close()
26
27 // Request the remote side to open port 8080 on all interfaces.
28 l, err := conn.Listen("tcp", "0.0.0.0:8080")
29 if err != nil {
30 log.Fatal("unable to register tcp forward: ", err)
31 }
32 defer l.Close()
33
34 // Serve HTTP with your SSH server acting as a reverse proxy.
35 http.Serve(l, http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
36 fmt.Fprintf(resp, "Hello world!\n")
37 }))
38}