From 1682255e6225642d4e54b68f0ee8b8e2d1c3918e Mon Sep 17 00:00:00 2001 From: q3aql Date: Sat, 11 Mar 2023 12:49:52 +0100 Subject: [PATCH] Added option to generate certificate on remote machine (ks-up*) --- src/ks-upa | 38 ++++++++++++++++++++++++++++++++++---- src/ks-upf | 38 ++++++++++++++++++++++++++++++++++---- src/ks-upr | 38 ++++++++++++++++++++++++++++++++++---- src/ks-upv | 36 +++++++++++++++++++++++++++++++++--- 4 files changed, 135 insertions(+), 15 deletions(-) diff --git a/src/ks-upa b/src/ks-upa index 1ef96ab..5dbfa67 100755 --- a/src/ks-upa +++ b/src/ks-upa @@ -2,12 +2,12 @@ ######################################################################## # ks-upa (ks-tools) - Upload audio file(s) to server with scp or rsync # -# Date: 13-02-2023 # +# Date: 11-03-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ######################################################################## VERSION="8.4-dev" -M_DATE="130223" +M_DATE="110323" # Global parameters. dirTemp="/tmp" @@ -397,6 +397,32 @@ function decrypt_kstools() { echo ${pass_decrypt} } +# Function to generate certificate on remote machine +function gen_pem_ssh() { + userhost="${USER}" + name_host="${HOSTNAME}" + echo "" && echo "* Generating .pem file to connect to this machine (${userhost})." + ssh-keygen << EOF + ${userhost} +EOF + mv ${userhost} ${userhost}-${name_host}.pem + mkdir -p ~/.ssh + chmod 700 ~/.ssh + touch ~/.ssh/authorized_keys + chmod 600 ~/.ssh/authorized_keys + echo "* Adding entry in the file ~/.ssh/authorized_keys" + cat ${userhost}.pub >> ~/.ssh/authorized_keys + rm -rf ${userhost}.pub + echo "" + echo "+ Copy the ${userhost}-${name_host}.pem file to your computer to connect to this machine." + if [ -f /usr/bin/puttygen ] ; then + puttygen ${userhost}-${name_host}.pem -o ${userhost}-${name_host}.ppk -O private + echo "+ Copy the ${userhost}-${name_host}.ppk file to your computer to connect to this machine." + fi + echo "+ Connect: ssh -i ${userhost}-${name_host}.pem ${userhost}@${name_host}" + echo "" +} + # Function to show config function showConfig() { configAvailable=0 @@ -649,6 +675,7 @@ function showHelp() { echo " $ ks-upa -r - Remove configuration" echo " $ ks-upa -c - Show configuration" echo " $ ks-upa -e - Edit configuration" + echo " $ ks-upv -p - Generate certificate" echo " $ ks-upa -v - Show version" echo " $ ks-upa -h - Show help" echo "" @@ -760,15 +787,18 @@ if [ "${1}" == "-r" ] ; then exit fi fi -# Show configuration file + # Show configuration file if [ "${1}" == "-c" ] ; then showConfig - # Show configuration file + # Edit configuration file elif [ "${1}" == "-e" ] ; then editConfig # Show the version elif [ "${1}" == "-v" ] ; then showVersion + # Generate certificate +elif [ "${1}" == "-p" ] ; then + gen_pem_ssh # Show the help elif [ "${1}" == "-h" ] ; then showHelp diff --git a/src/ks-upf b/src/ks-upf index 3200a3a..d484579 100755 --- a/src/ks-upf +++ b/src/ks-upf @@ -2,12 +2,12 @@ ######################################################################### # ks-upf (ks-tools) - Upload common file(s) to server with scp or rsync # -# Date: 13-02-2023 # +# Date: 11-03-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ######################################################################### VERSION="8.4-dev" -M_DATE="130223" +M_DATE="110323" # Global parameters. dirTemp="/tmp" @@ -424,6 +424,32 @@ function decrypt_kstools() { echo ${pass_decrypt} } +# Function to generate certificate on remote machine +function gen_pem_ssh() { + userhost="${USER}" + name_host="${HOSTNAME}" + echo "" && echo "* Generating .pem file to connect to this machine (${userhost})." + ssh-keygen << EOF + ${userhost} +EOF + mv ${userhost} ${userhost}-${name_host}.pem + mkdir -p ~/.ssh + chmod 700 ~/.ssh + touch ~/.ssh/authorized_keys + chmod 600 ~/.ssh/authorized_keys + echo "* Adding entry in the file ~/.ssh/authorized_keys" + cat ${userhost}.pub >> ~/.ssh/authorized_keys + rm -rf ${userhost}.pub + echo "" + echo "+ Copy the ${userhost}-${name_host}.pem file to your computer to connect to this machine." + if [ -f /usr/bin/puttygen ] ; then + puttygen ${userhost}-${name_host}.pem -o ${userhost}-${name_host}.ppk -O private + echo "+ Copy the ${userhost}-${name_host}.ppk file to your computer to connect to this machine." + fi + echo "+ Connect: ssh -i ${userhost}-${name_host}.pem ${userhost}@${name_host}" + echo "" +} + # Function to show config function showConfig() { configAvailable=0 @@ -676,6 +702,7 @@ function showHelp() { echo " $ ks-upf -r - Remove configuration" echo " $ ks-upf -c - Show configuration" echo " $ ks-upf -e - Edit configuration" + echo " $ ks-upv -p - Generate certificate" echo " $ ks-upf -v - Show version" echo " $ ks-upf -h - Show help" echo "" @@ -787,15 +814,18 @@ if [ "${1}" == "-r" ] ; then exit fi fi -# Show configuration file + # Show configuration file if [ "${1}" == "-c" ] ; then showConfig - # Show configuration file + # Edit configuration file elif [ "${1}" == "-e" ] ; then editConfig # Show the version elif [ "${1}" == "-v" ] ; then showVersion + # Generate certificate +elif [ "${1}" == "-p" ] ; then + gen_pem_ssh # Show the help elif [ "${1}" == "-h" ] ; then showHelp diff --git a/src/ks-upr b/src/ks-upr index ab42b5e..c5f85c5 100755 --- a/src/ks-upr +++ b/src/ks-upr @@ -2,12 +2,12 @@ ############################################################################## # ks-upr (ks-tools) - Upload recursively file(s) to server with scp or rsync # -# Date: 13-02-2023 # +# Date: 11-03-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ############################################################################## VERSION="8.4-dev" -M_DATE="130223" +M_DATE="110323" # Global parameters. dirTemp="/tmp" @@ -301,6 +301,32 @@ function decrypt_kstools() { echo ${pass_decrypt} } +# Function to generate certificate on remote machine +function gen_pem_ssh() { + userhost="${USER}" + name_host="${HOSTNAME}" + echo "" && echo "* Generating .pem file to connect to this machine (${userhost})." + ssh-keygen << EOF + ${userhost} +EOF + mv ${userhost} ${userhost}-${name_host}.pem + mkdir -p ~/.ssh + chmod 700 ~/.ssh + touch ~/.ssh/authorized_keys + chmod 600 ~/.ssh/authorized_keys + echo "* Adding entry in the file ~/.ssh/authorized_keys" + cat ${userhost}.pub >> ~/.ssh/authorized_keys + rm -rf ${userhost}.pub + echo "" + echo "+ Copy the ${userhost}-${name_host}.pem file to your computer to connect to this machine." + if [ -f /usr/bin/puttygen ] ; then + puttygen ${userhost}-${name_host}.pem -o ${userhost}-${name_host}.ppk -O private + echo "+ Copy the ${userhost}-${name_host}.ppk file to your computer to connect to this machine." + fi + echo "+ Connect: ssh -i ${userhost}-${name_host}.pem ${userhost}@${name_host}" + echo "" +} + # Function to show config function showConfig() { configAvailable=0 @@ -553,6 +579,7 @@ function showHelp() { echo " $ ks-upr -r - Remove configuration" echo " $ ks-upr -c - Show configuration" echo " $ ks-upr -e - Edit configuration" + echo " $ ks-upv -p - Generate certificate" echo " $ ks-upr -v - Show version" echo " $ ks-upr -h - Show help" echo "" @@ -664,15 +691,18 @@ if [ "${1}" == "-r" ] ; then exit fi fi -# Show configuration file + # Show configuration file if [ "${1}" == "-c" ] ; then showConfig - # Show configuration file + # Edit configuration file elif [ "${1}" == "-e" ] ; then editConfig # Show the version elif [ "${1}" == "-v" ] ; then showVersion + # Generate certificate +elif [ "${1}" == "-p" ] ; then + gen_pem_ssh # Show the help elif [ "${1}" == "-h" ] ; then showHelp diff --git a/src/ks-upv b/src/ks-upv index 2396bb8..c8c82ec 100755 --- a/src/ks-upv +++ b/src/ks-upv @@ -2,12 +2,12 @@ ######################################################################### # ks-upv (ks-tools) - Upload videos file(s) to server with scp or rsync # -# Date: 13-02-2023 # +# Date: 11-03-2023 # # Author: q3aql # # Contact: q3aql@duck.com # ######################################################################### VERSION="8.4-dev" -M_DATE="130223" +M_DATE="110323" # Global parameters. dirTemp="/tmp" @@ -397,6 +397,32 @@ function decrypt_kstools() { echo ${pass_decrypt} } +# Function to generate certificate on remote machine +function gen_pem_ssh() { + userhost="${USER}" + name_host="${HOSTNAME}" + echo "" && echo "* Generating .pem file to connect to this machine (${userhost})." + ssh-keygen << EOF + ${userhost} +EOF + mv ${userhost} ${userhost}-${name_host}.pem + mkdir -p ~/.ssh + chmod 700 ~/.ssh + touch ~/.ssh/authorized_keys + chmod 600 ~/.ssh/authorized_keys + echo "* Adding entry in the file ~/.ssh/authorized_keys" + cat ${userhost}.pub >> ~/.ssh/authorized_keys + rm -rf ${userhost}.pub + echo "" + echo "+ Copy the ${userhost}-${name_host}.pem file to your computer to connect to this machine." + if [ -f /usr/bin/puttygen ] ; then + puttygen ${userhost}-${name_host}.pem -o ${userhost}-${name_host}.ppk -O private + echo "+ Copy the ${userhost}-${name_host}.ppk file to your computer to connect to this machine." + fi + echo "+ Connect: ssh -i ${userhost}-${name_host}.pem ${userhost}@${name_host}" + echo "" +} + # Function to show config function showConfig() { configAvailable=0 @@ -649,6 +675,7 @@ function showHelp() { echo " $ ks-upv -r - Remove configuration" echo " $ ks-upv -c - Show configuration" echo " $ ks-upv -e - Edit configuration" + echo " $ ks-upv -p - Generate certificate" echo " $ ks-upv -v - Show version" echo " $ ks-upv -h - Show help" echo "" @@ -763,12 +790,15 @@ fi # Show configuration file if [ "${1}" == "-c" ] ; then showConfig - # Show configuration file + # Edit configuration file elif [ "${1}" == "-e" ] ; then editConfig # Show the version elif [ "${1}" == "-v" ] ; then showVersion + # Generate certificate +elif [ "${1}" == "-p" ] ; then + gen_pem_ssh # Show the help elif [ "${1}" == "-h" ] ; then showHelp