require one user at least

This commit is contained in:
Ryo Ota 2023-08-10 03:31:30 +09:00
parent 0b3b8d0f96
commit 54b502d3ae
2 changed files with 5 additions and 3 deletions

View file

@ -101,7 +101,11 @@ var RootCmd = &cobra.Command{
} }
sshUsers = append(sshUsers, sshUser{name: splits[0], password: splits[1]}) sshUsers = append(sshUsers, sshUser{name: splits[0], password: splits[1]})
} }
if len(sshUsers) == 0 {
return fmt.Errorf(`No user specified
e.g. --user "john:mypassword"
e.g. --user "john:"`)
}
// (base: https://gist.github.com/jpillora/b480fde82bff51a06238) // (base: https://gist.github.com/jpillora/b480fde82bff51a06238)
sshConfig := &ssh.ServerConfig{ sshConfig := &ssh.ServerConfig{
//Define a function to run when a client attempts a password login //Define a function to run when a client attempts a password login

View file

@ -1,14 +1,12 @@
package main package main
import ( import (
"fmt"
"github.com/nwtgck/handy-sshd/cmd" "github.com/nwtgck/handy-sshd/cmd"
"os" "os"
) )
func main() { func main() {
if err := cmd.RootCmd.Execute(); err != nil { if err := cmd.RootCmd.Execute(); err != nil {
_, _ = fmt.Fprintf(os.Stderr, err.Error())
os.Exit(-1) os.Exit(-1)
} }
} }