diff --git a/scripts/ctcreate/ctcreate.sh b/scripts/ctcreate/ctcreate.sh index b57f768..d470a32 100755 --- a/scripts/ctcreate/ctcreate.sh +++ b/scripts/ctcreate/ctcreate.sh @@ -2,6 +2,8 @@ ## Create new Linux contanier at a proxmox host DMZKEYFILE=$(echo -n ~)"/.ssh/dmz" +USER=$(cut -d" " -f3 $DMZKEYFILE.pub | cut -d "@" -f1) +USEREMAIL=$(cut -d" " -f3 $DMZKEYFILE.pub) PROXMOXHOST=$1 CTHOST=$2 @@ -23,25 +25,26 @@ if [[ -z "$GENPASS" ]]; then exit 1 fi -ssh-add -t 200 $DMZKEYFILE +ssh-add -t 600 $DMZKEYFILE torsocks scp ./remotecmd $PROXMOXHOST:/root/ctcreate.sh +torsocks scp $DMZKEYFILE.pub $PROXMOXHOST:/root/.ssh/$USER.pub -torsocks ssh $PROXMOXHOST "chmod +x /root/ctcreate.sh; /root/ctcreate.sh $CTHOST $GENPASS" >> cmdoutput.txt +torsocks ssh $PROXMOXHOST "chmod +x /root/ctcreate.sh; /root/ctcreate.sh $CTHOST $GENPASS $USER" >> cmdoutput.txt CREDS=$( tail -3 cmdoutput.txt) rm cmdoutput.txt -printf "$CREDS\n" | gpg -e -r fram3d@dmz.rs -r sienna@dmz.rs --output ~/src/dmzadmin/credentials/krov/$CTHOST.gpg +printf "$CREDS\n" | gpg -e -r $USEREMAIL --output $CTHOST.gpg CTIP=$(printf "$CREDS" | head -1 | cut -d'@' -f 2) -echo Host dmzkrov$CTHOST >> ~/.ssh/autoconfig -echo " Hostname" $CTIP >> ~/.ssh/autoconfig -echo " ProxyJump" dmzkrovtor12 >> ~/.ssh/autoconfig -echo " User" root >> ~/.ssh/autoconfig -echo " IdentityFile" /home/anon/.ssh/krov/tor11 >> ~/.ssh/autoconfig -echo " PasswordAuthentication" no >> ~/.ssh/autoconfig +echo "Host dmzkrov"$CTHOST >> ~/.ssh/autoconfig +echo " Hostname "$CTIP >> ~/.ssh/autoconfig +echo " ProxyJump dmzkrovtor12" >> ~/.ssh/autoconfig +echo " User root" >> ~/.ssh/autoconfig +echo " IdentityFile "$DMZKEYFILE >> ~/.ssh/autoconfig +echo " PasswordAuthentication no" >> ~/.ssh/autoconfig ssh -R $CTIP torsocks scp ./newct dmzkrov$CTHOST:/root/newct.sh diff --git a/scripts/ctcreate/newct b/scripts/ctcreate/newct index a7974de..95d3a65 100644 --- a/scripts/ctcreate/newct +++ b/scripts/ctcreate/newct @@ -1,5 +1,5 @@ #!/bin/bash apt update apt -y dist-upgrade -apt install unattended-upgrades +apt -y install unattended-upgrades dpkg-reconfigure unattended-upgrades diff --git a/scripts/ctcreate/remotecmd b/scripts/ctcreate/remotecmd index d80f84f..8230982 100644 --- a/scripts/ctcreate/remotecmd +++ b/scripts/ctcreate/remotecmd @@ -1,6 +1,7 @@ #!/bin/bash CTHOSTNAME=$1 CTPASS=$2 +USER=$3 echo Creating $CTHOSTNAME ... @@ -17,6 +18,11 @@ if [[ -z "$CTPASS" ]]; then exit 1 fi +if [[ -z "$USER" ]]; then + echo "USER not set" + exit 1 +fi + if [[ -z "$LASTID" ]]; then LASTID=99 fi