diff options
Diffstat (limited to 'auto/ssh-script.sh')
-rwxr-xr-x | auto/ssh-script.sh | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/auto/ssh-script.sh b/auto/ssh-script.sh new file mode 100755 index 0000000..abdf7ae --- /dev/null +++ b/auto/ssh-script.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -e + +# Ensure we are jenkins user +if [ "$EUID" -ne 1006 ] + then echo "Please run as jenkins" + exit +fi + +if [ -f ~/.ssh/id_ed25519.pub ]; then + echo "SSH keypair has already been generated." +else + echo "Generating SSH keypair..." + ssh-keygen -t ed25519 -C "jenkins" -N "" -f /var/lib/jenkins/.ssh/id_ed25519 > /dev/null 2>&1 +fi + +if [ -f ~/.ssh/authorized_keys ]; then + echo "SSH key has already been authorized." +else + echo "Authorizing SSH key..." + cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys +fi + +echo "Ensuring SSH host key is trusted..." +ssh -oStrictHostKeyChecking=no 172.17.17.17 "pwd > /dev/null 2>&1" > /dev/null 2>&1 |