From caa4ca46c0d4cb7b29e5702679b1ce70b7a2c178 Mon Sep 17 00:00:00 2001
From: John Maguire <contact@johnmaguire.me>
Date: Sun, 31 Jan 2016 22:01:16 -0500
Subject: [PATCH 1/2] Add debug log when SSH key for deletion isn't found

---
 models/ssh_key.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/models/ssh_key.go b/models/ssh_key.go
index a7b1680f6..471f4cd12 100644
--- a/models/ssh_key.go
+++ b/models/ssh_key.go
@@ -374,6 +374,11 @@ func rewriteAuthorizedKeys(key *PublicKey, p, tmpP string) error {
 			break
 		}
 	}
+
+	if !isFound {
+		log.Warn("SSH key %d not found in authorized_keys file for deletion", key.ID)
+	}
+
 	return nil
 }
 

From b3e0efc0c39f231b2f32105e15b43c26cc3d32f6 Mon Sep 17 00:00:00 2001
From: John Maguire <contact@johnmaguire.me>
Date: Sun, 31 Jan 2016 22:00:55 -0500
Subject: [PATCH 2/2] Trim whitespace when adding SSH keys (fixes #2447)

---
 models/ssh_key.go | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/models/ssh_key.go b/models/ssh_key.go
index 471f4cd12..325a40a48 100644
--- a/models/ssh_key.go
+++ b/models/ssh_key.go
@@ -165,6 +165,9 @@ func CheckPublicKeyString(content string) (_ string, err error) {
 		return "", errors.New("only a single line with a single key please")
 	}
 
+	// remove any unnecessary whitespace now
+	content = strings.TrimSpace(content)
+
 	fields := strings.Fields(content)
 	if len(fields) < 2 {
 		return "", errors.New("too less fields")