Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lägg automatiskt till host key i sshkey-steget #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions dbwebb2
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -1678,6 +1687,7 @@ function dbwebb-init()
function dbwebb-sshkey()
{
local sshkey="$HOME/.ssh/dbwebb"
local key hostname

if [ ! -d "$HOME/.ssh" ]
then
Expand All @@ -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."
Expand Down
9 changes: 9 additions & 0 deletions dbwebb2-bootstrap.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
9 changes: 9 additions & 0 deletions dbwebb2-inspect
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
9 changes: 9 additions & 0 deletions dbwebb2-validate
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
10 changes: 10 additions & 0 deletions dbwebb2.bash
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ function dbwebb-init()
function dbwebb-sshkey()
{
local sshkey="$HOME/.ssh/dbwebb"
local key hostname

if [ ! -d "$HOME/.ssh" ]
then
Expand All @@ -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."
Expand Down