Created
August 19, 2016 20:09
-
-
Save progrium/c9e9fb40ef9bc42a2dd357cf0df496e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"github.com/progrium/automata/pkg/ssh" | |
) | |
func main() { | |
ssh.ListenAndServe(":2222", func(s ssh.Session) { | |
io.WriteString(s, "Hello world\n") | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"github.com/progrium/automata/pkg/ssh" | |
) | |
func main() { | |
ssh.Handle(func(s ssh.Session) { | |
io.WriteString(s, "Goodbye world\n") | |
s.Exit(1) | |
}) | |
ssh.ListenAndServe(":2222", nil, | |
ssh.HostKeyFile("/Users/progrium/.ssh/id_rsa"), | |
ssh.PasswordAuth(func(user, pass string) bool { | |
return pass == "secret" | |
})) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"io/ioutil" | |
"github.com/progrium/automata/pkg/ssh" | |
) | |
func main() { | |
ssh.Handle(func(s ssh.Session) { | |
username, addr := s.User() | |
fmt.Fprintf(s, "Environment for %s (%s)\n", username, addr) | |
for _, env := range s.Environ() { | |
fmt.Fprintf(s, "%s\n", env) | |
} | |
}) | |
ssh.ListenAndServe(":2222", nil, | |
ssh.HostKeyFile("/Users/progrium/.ssh/id_rsa"), | |
ssh.PublicKeyAuth(func(user string, key ssh.PublicKey) bool { | |
d, _ := ioutil.ReadFile("/Users/progrium/.ssh/id_rsa.pub") | |
allowed, _, _, _, _ := ssh.ParseAuthorizedKey(d) | |
return ssh.KeysEqual(key, allowed) | |
})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment