From f0e4d73a38e93072ee6848c4e450b996b443caab Mon Sep 17 00:00:00 2001 From: Henrik Tunedal Date: Fri, 4 Nov 2022 11:21:18 +0100 Subject: [PATCH 1/2] Automate adding known public host key --- dbwebb2-bootstrap.bash | 9 +++++++++ dbwebb2.bash | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/dbwebb2-bootstrap.bash b/dbwebb2-bootstrap.bash index 3650828..a4da9a4 100644 --- a/dbwebb2-bootstrap.bash +++ b/dbwebb2-bootstrap.bash @@ -33,6 +33,15 @@ DBW_CURRENT_DIR="$( pwd )" +# +# Known public keys of SSH servers. +# +DBW_HOST_KEYS=( + "ssh.student.bth.se ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBER6Y1R4EmZZfJD9L//cHo/PEVgBOg/jEwgwdPmL9pBc4e6QtHT1Lgnp5sAi+OgA2P0uQU4UJ0qVAhNAUA8SCLE=" +) + + + # What is the directory of the current course repo, find recursivly up the tree DBW_COURSE_FILE_NAME=".dbwebb.course" diff --git a/dbwebb2.bash b/dbwebb2.bash index bc47961..30bf88f 100644 --- a/dbwebb2.bash +++ b/dbwebb2.bash @@ -308,6 +308,7 @@ function dbwebb-init() function dbwebb-sshkey() { local sshkey="$HOME/.ssh/dbwebb" + local key hostname if [ ! -d "$HOME/.ssh" ] then @@ -328,6 +329,15 @@ function dbwebb-sshkey() chmod 700 "$HOME/.ssh" chmod 600 "$sshkey" "$sshkey.pub" + # Add the public keys of SSH servers to known_hosts if needed. + for key in "${DBW_HOST_KEYS[@]}"; do + hostname="$(echo "$key"|awk '{print $1}')" + if ! ssh-keygen -F "$hostname" >/dev/null 2>&1; then + echo "Adding known public key for $hostname." + echo "$key" >>"$HOME/.ssh/known_hosts" + fi + done + intro="I will now install the ssh-key at the remote server." command="cat '$sshkey.pub' | ssh $DBW_USER@$DBW_HOST 'sh -c \"if [ ! -d .ssh ]; then mkdir .ssh; fi; chmod 700 .ssh; touch .ssh/authorized_keys; cat >> .ssh/authorized_keys\"'" message="to install the ssh-keys." From be413f19fcbb1a8217b8c8d972d5502df375b008 Mon Sep 17 00:00:00 2001 From: Henrik Tunedal Date: Fri, 4 Nov 2022 11:27:32 +0100 Subject: [PATCH 2/2] Update generated scripts --- dbwebb2 | 19 +++++++++++++++++++ dbwebb2-inspect | 9 +++++++++ dbwebb2-validate | 9 +++++++++ 3 files changed, 37 insertions(+) diff --git a/dbwebb2 b/dbwebb2 index 88eb103..f748e2e 100755 --- a/dbwebb2 +++ b/dbwebb2 @@ -973,6 +973,15 @@ DBW_CURRENT_DIR="$( pwd )" +# +# Known public keys of SSH servers. +# +DBW_HOST_KEYS=( + "ssh.student.bth.se ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBER6Y1R4EmZZfJD9L//cHo/PEVgBOg/jEwgwdPmL9pBc4e6QtHT1Lgnp5sAi+OgA2P0uQU4UJ0qVAhNAUA8SCLE=" +) + + + # What is the directory of the current course repo, find recursivly up the tree DBW_COURSE_FILE_NAME=".dbwebb.course" @@ -1678,6 +1687,7 @@ function dbwebb-init() function dbwebb-sshkey() { local sshkey="$HOME/.ssh/dbwebb" + local key hostname if [ ! -d "$HOME/.ssh" ] then @@ -1698,6 +1708,15 @@ function dbwebb-sshkey() chmod 700 "$HOME/.ssh" chmod 600 "$sshkey" "$sshkey.pub" + # Add the public keys of SSH servers to known_hosts if needed. + for key in "${DBW_HOST_KEYS[@]}"; do + hostname="$(echo "$key"|awk '{print $1}')" + if ! ssh-keygen -F "$hostname" >/dev/null 2>&1; then + echo "Adding known public key for $hostname." + echo "$key" >>"$HOME/.ssh/known_hosts" + fi + done + intro="I will now install the ssh-key at the remote server." command="cat '$sshkey.pub' | ssh $DBW_USER@$DBW_HOST 'sh -c \"if [ ! -d .ssh ]; then mkdir .ssh; fi; chmod 700 .ssh; touch .ssh/authorized_keys; cat >> .ssh/authorized_keys\"'" message="to install the ssh-keys." diff --git a/dbwebb2-inspect b/dbwebb2-inspect index bbefebf..e4cb030 100755 --- a/dbwebb2-inspect +++ b/dbwebb2-inspect @@ -973,6 +973,15 @@ DBW_CURRENT_DIR="$( pwd )" +# +# Known public keys of SSH servers. +# +DBW_HOST_KEYS=( + "ssh.student.bth.se ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBER6Y1R4EmZZfJD9L//cHo/PEVgBOg/jEwgwdPmL9pBc4e6QtHT1Lgnp5sAi+OgA2P0uQU4UJ0qVAhNAUA8SCLE=" +) + + + # What is the directory of the current course repo, find recursivly up the tree DBW_COURSE_FILE_NAME=".dbwebb.course" diff --git a/dbwebb2-validate b/dbwebb2-validate index 05150b1..307351f 100755 --- a/dbwebb2-validate +++ b/dbwebb2-validate @@ -973,6 +973,15 @@ DBW_CURRENT_DIR="$( pwd )" +# +# Known public keys of SSH servers. +# +DBW_HOST_KEYS=( + "ssh.student.bth.se ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBER6Y1R4EmZZfJD9L//cHo/PEVgBOg/jEwgwdPmL9pBc4e6QtHT1Lgnp5sAi+OgA2P0uQU4UJ0qVAhNAUA8SCLE=" +) + + + # What is the directory of the current course repo, find recursivly up the tree DBW_COURSE_FILE_NAME=".dbwebb.course"