Ensure SSH key ends with newline

In at least some versions of the 'ssh-add' command, adding a SSH key
requires that SSH key is newline terminated. If it is not, ssh-add
doesn't add the key and, instead, unhelpfully prompts for a
passphrase for the key ('Enter passphrase for (stdin):').

This change makes sure the key is terminated with a newline character to
hopefully avoid this issue occurring as often.

Signed-off-by: Sam Lewis <sam.vr.lewis@gmail.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Sam Lewis 2020-01-09 04:56:32 +01:00 committed by Jan Kiszka
parent a5d0153e84
commit b5ba370049

View File

@ -269,6 +269,11 @@ def ssh_add_key(env, key):
"""
Adds an ssh key to the ssh-agent
"""
# The ssh-agent needs the key to end with a newline, otherwise it
# unhelpfully prompts for a password
if not key.endswith('\n'):
key += '\n'
process = Popen(['ssh-add', '-'], stdin=PIPE, stdout=None,
stderr=PIPE, env=env)
(_, error) = process.communicate(input=str.encode(key))