Skip to content

Instantly share code, notes, and snippets.

@francoishill
Created December 10, 2015 13:21
Show Gist options
  • Select an option

  • Save francoishill/f2de3021821a4a8f769f to your computer and use it in GitHub Desktop.

Select an option

Save francoishill/f2de3021821a4a8f769f to your computer and use it in GitHub Desktop.

Revisions

  1. francoishill created this gist Dec 10, 2015.
    19 changes: 19 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    # On your machine (windows / linux) that you want to get access to from

    Setup a (temporary) http server on your machine that always responds with your machine's SSH public key.

    Replace the 'YOUR-SSH-KEY-GOES-HERE' if using the golang file of this gist.

    # On the CoreOS box you want to access

    Call these commands below on the CoreOS box by replacing `IP-OF-YOUR-MACHINE` of your machine having the http server.

    ```
    curl http://[IP-OF-YOUR-MACHINE]:8888 > ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys
    ```

    Note that I chose port 8888 in the golang file but it could be changed there and then also adapted in the `curl` command from CoreOS.

    # SSH into CoreOS
    Now you should be able to connect if you know the ip. Hint: `ip addr show` to show IPs.
    24 changes: 24 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    // Golang example of http server

    package main

    import (
    "fmt"
    "net/http"
    )

    const YOUR_SSH_KEY = `YOUR-SSH-KEY-GOES-HERE`

    func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    // Now write the ssh key
    fmt.Fprintf(w, "%s", string(YOUR_SSH_KEY))
    })

    portStr := "8888"
    fmt.Println("Attempting to listen on port " + portStr)
    err := http.ListenAndServe(":"+portStr, nil)
    if err != nil {
    fmt.Println("ERROR: Unable to start http server")
    }
    }