From 48516860f1577ec339ea58832b502f89cef42e18 Mon Sep 17 00:00:00 2001 From: d-fens Date: Tue, 21 Feb 2017 12:18:55 +0000 Subject: [PATCH] Use ecdsa or ed25519 for the SSH_KEY if required Currently this will not connect if the server forces a particular key type such as ed25519 which can prevent the script from connecting. This allows the server to connect if it detects a particular key in use by the user. Not included in this change is a DSA key since they are typically being depreciated and therefore not recommended. --- upload.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/upload.sh b/upload.sh index 383be89..1556a22 100755 --- a/upload.sh +++ b/upload.sh @@ -88,8 +88,19 @@ mkdir -p "$home/.ssh" printf "StrictHostKeyChecking no\n" > "$home/.ssh/config" chmod 0700 "$home/.ssh/config" -echo "$SSH_KEY" > "$home/.ssh/id_rsa" -chmod 0600 "$home/.ssh/id_rsa" +keyfile="$home/.ssh/id_rsa" +echo "$SSH_KEY" | grep -q "ssh-ed25519" +if [ $? -eq 0 ]; then + printf "Using ed25519 based key\n" + keyfile="$home/.ssh/id_ed25519" +fi +echo "$SSH_KEY" | grep -q "ecdsa-" +if [ $? -eq 0 ]; then + printf "Using ecdsa based key\n" + keyfile="$home/.ssh/id_ecdsa" +fi +echo "$SSH_KEY" > $keyfile +chmod 0600 $keyfile # Parse SSH commands function join_with { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }