From cdb2c949f09116218ac1f583bd33e0a6d003265d Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 21 Jul 2024 22:41:13 -0400 Subject: [PATCH] Verify user-specified SSH identity file exists --- src/cli/init.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cli/init.go b/src/cli/init.go index 4a378c2..a92478b 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -38,7 +38,18 @@ func TempInitCli() { sshUser := input("Remote SSH username:") sshPort := input("Remote SSH port:") sshIP := input("Remote SSH IP/domain:") - sshKey := expandPathWithHome(input("SSH private identity file path:")) + + // prompt for and ensure existence of SSH identity file + var sshKey string + var sshKeyIsFile bool + for !sshKeyIsFile { + sshKey = expandPathWithHome(input("SSH private identity file path:")) + sshKeyIsFile, _ = backend.TargetIsFile(sshKey, false, 0) + if !sshKeyIsFile { + fmt.Println(backend.AnsiError + "SSH identity file not found: " + sshKey + backend.AnsiReset) + } + } + sshKeyProtected := inputBinary("Is the identity file password-protected?") // initialize libmutton directories