From d5ea6ca351bad03c121ca521cdc8224c9a486fa2 Mon Sep 17 00:00:00 2001 From: Someone Date: Thu, 19 Nov 2015 23:18:46 +0100 Subject: [PATCH] Script to deploy ssh authorized_keys across our network. --- ssh_redeploy_authorized_keys.sh | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 ssh_redeploy_authorized_keys.sh diff --git a/ssh_redeploy_authorized_keys.sh b/ssh_redeploy_authorized_keys.sh new file mode 100755 index 0000000..10081ea --- /dev/null +++ b/ssh_redeploy_authorized_keys.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# +# Copyright 2015-2016 by Jan Vales (Someone ) +# send me your changes. credit author(s). do not publish. share alike. +# to be done: find a suitable licence text. +# +# Script to deploy authorized keys on all out CTF machines. +# + +echo "merge keys" +cat /root/.ssh/authorized_keys > /root/authorized_keys.adm.tmp +cat /root/.ssh/authorized_keys > /root/authorized_keys.all.tmp + + +mkdir -p /media/sf_vmshare/_orga/read_only_info +touch /media/sf_vmshare/_orga/authorized_keys +cat /media/sf_vmshare/_orga/authorized_keys >> /root/authorized_keys.all.tmp + + +echo "distribute keys to localhost (gw.i)" +mkdir -p /home/user/.ssh +chmod 700 /home/user/.ssh +cat /root/authorized_keys.adm.tmp > /home/user/.ssh/authorized_keys +chmod 600 /home/user/.ssh/authorized_keys + + +echo "distribute keys to spof (spof.i)" +# put admkeys on root +scp /root/authorized_keys.adm.tmp root@spof.i:/root/.ssh/authorized_keys +ssh root@spof.i "mkdir -p /root/.ssh ; chmod 700 /root/.ssh ; chmod 600 /root/.ssh/authorized_keys" + +echo "distribute keys to apof (apof.i)" +# put admkeys on root +scp /root/authorized_keys.adm.tmp root@apof.i:/root/.ssh/authorized_keys +ssh root@apof.i "mkdir -p /root/.ssh ; chmod 700 /root/.ssh ; chmod 600 /root/.ssh/authorized_keys" + + +echo "distribute keys to vmSVC (service.i)" +# put adminkeys on root +scp -P22 /root/authorized_keys.adm.tmp root@s.i:/root/.ssh/authorized_keys +ssh -p22 root@s.i "mkdir -p /root/.ssh ; chmod 700 /root/.ssh ; chmod 600 /root/.ssh/authorized_keys" + +# put all keys on user +#scp -P22 /root/authorized_keys.all.tmp root@s.i:/home/user/.ssh/authorized_keys +#ssh -p22 root@s.i "mkdir -p /home/user/.ssh ; chmod 700 /home/user/.ssh ; chmod 600 /home/user/.ssh/authorized_keys ; chown -R user:user /home/user/.ssh" + +scp -P22 /root/authorized_keys.all.tmp root@service.i:/home/ctf/.ssh/authorized_keys +ssh -p22 root@s.i "mkdir -p /home/ctf/.ssh ; chmod 700 /home/ctf/.ssh ; chmod 600 /home/ctf/.ssh/authorized_keys ; chown -R ctf:ctf /home/ctf/.ssh" + + +echo "distribute keys to vmVULN (v.i)" +# put allkeys on root +scp -P22 /root/authorized_keys.all.tmp root@v.i:/root/.ssh/authorized_keys +ssh -p22 root@v.i "mkdir -p /root/.ssh ; chmod 700 /root/.ssh ; chmod 600 /root/.ssh/authorized_keys" + +# put allkeys on user +scp -P22 /root/authorized_keys.all.tmp root@v.i:/opt/ctf/.ssh/authorized_keys +ssh -p22 root@v.i "mkdir -p /opt/ctf/.ssh ; chmod 700 /opt/ctf/.ssh ; chmod 600 /opt/ctf/.ssh/authorized_keys ; chown -R ctf:ctf /opt/ctf/.ssh" + +echo "distribute keys to vmVULN2 (v2.i)" +# put allkeys on root +scp -P22 /root/authorized_keys.all.tmp root@v2.i:/root/.ssh/authorized_keys +ssh -p22 root@v2.i "mkdir -p /root/.ssh ; chmod 700 /root/.ssh ; chmod 600 /root/.ssh/authorized_keys" + +# put allkeys on user +scp -P22 /root/authorized_keys.all.tmp root@v2.i:/opt/ctf/.ssh/authorized_keys +ssh -p22 root@v2.i "mkdir -p /opt/ctf/.ssh ; chmod 700 /opt/ctf/.ssh ; chmod 600 /opt/ctf/.ssh/authorized_keys ; chown -R ctf:ctf /opt/ctf/.ssh" + +echo "cleanup" +cat /root/authorized_keys.all.tmp > /media/sf_vmshare/_orga/read_only_info/authorized_keys +rm /root/authorized_keys.adm.tmp /root/authorized_keys.all.tmp + -- 2.43.0