Skip to content

Instantly share code, notes, and snippets.

@francoishill
Created December 10, 2015 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francoishill/f2de3021821a4a8f769f to your computer and use it in GitHub Desktop.
Save francoishill/f2de3021821a4a8f769f to your computer and use it in GitHub Desktop.
Add your ssh key into the `authorized_keys` of CoreOS

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.

// 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")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment