Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
move the callback to its own function to make the logging appear litt…
…le nicer

Signed-off-by: Andrew Thornton <[email protected]>
  • Loading branch information
zeripath committed Jun 28, 2021
commit d8c77e2e469780bb06a48bce1c3190a5c3baee63
16 changes: 10 additions & 6 deletions modules/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ func publicKeyHandler(ctx ssh.Context, key ssh.PublicKey) bool {
return true
}

// sshConnectionFailed logs a failed connection
// - this mainly exists to give a nice function name in logging
func sshConnectionFailed(conn net.Conn, err error) {
// Log the underlying error with a specific message
log.Warn("Failed connection from %s with error: %v", conn.RemoteAddr(), err)
// Log with the standard failed authentication from message for simpler fail2ban configuration
log.Warn("Failed authentication attempt from %s", conn.RemoteAddr())
}

// Listen starts a SSH server listens on given port.
func Listen(host string, port int, ciphers []string, keyExchanges []string, macs []string) {
srv := ssh.Server{
Expand All @@ -253,12 +262,7 @@ func Listen(host string, port int, ciphers []string, keyExchanges []string, macs
config.Ciphers = ciphers
return config
},
ConnectionFailedCallback: func(conn net.Conn, err error) {
// Log the underlying error with a specific message
log.Warn("Failed connection from %s with error: %v", conn.RemoteAddr(), err)
// Log with the standard failed authentication from message for simpler fail2ban configuration
log.Warn("Failed authentication attempt from %s", conn.RemoteAddr())
},
ConnectionFailedCallback: sshConnectionFailed,
// We need to explicitly disable the PtyCallback so text displays
// properly.
PtyCallback: func(ctx ssh.Context, pty ssh.Pty) bool {
Expand Down