All Downloads are FREE. Search and download functionalities are using the official Maven repository.

refcodes-batch.1.0.2.source-code.setup-ssh-client.job Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
#!/bin/bash

if [[ $HELP = y ]] ; then
	echo "The switch \"-j $JOB\" uses a given configuration to create a SSH               " >&2
	echo "client used to communicate with the (remote) SSH server:                        " >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
fi

. $SCRIPT_DIR/validate-ssh-config.job

if [[ $HELP = y ]] ; then
	exit $EXIT_SUCCESS
fi

exitOnConfigOff "SSH"

SSH_KEY_FILE="$SSH_CLIENT_KEY_DIR/$SSH_KEY_FILE_NAME"
SSH_PUB_KEY_FILE="$SSH_CLIENT_KEY_DIR/$SSH_KEY_FILE_NAME.pub"


if [[ $VERBOSE = y ]] ; then
	echo "Assuming the path \"$SSH_CLIENT_KEY_DIR\" to exist ..." >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
fi

exitOnMissingPropertyPath "SSH_CLIENT_KEY_DIR"

if [[ $HELP = y ]] ; then
	echo "Generating SSH keyfile \"$SSH_KEY_FILE\" ..." >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
fi

ssh-keygen -N '' -P '' -t rsa -b 2048 -f $SSH_KEY_FILE
# ssh-keygen -t rsa -b 2048 -f $SSH_KEY_FILE
exitOnError "Unable to generate SSH keyfile \"$SSH_KEY_FILE\" !!!"
exitOnMissingVariablePath "SSH_KEY_FILE"
exitOnMissingVariablePath "SSH_PUB_KEY_FILE"

if [[ $VERBOSE = y ]] ; then
	echo "Applying file access rights on \"$SSH_KEY_FILE\" ..." >&2
	echo "Applying file access rights on \"$SSH_PUB_KEY_FILE\" ..." >&2
	# echo "--------------------------------------------------------------------------------" >&2
	logSeparator
fi

# chown $SSH_CLIENT_FS_USER:$SSH_CLIENT_FS_GROUP $SSH_KEY_FILE
exitOnError "Unable to change owner to \"$SSH_CLIENT_FS_USER:$SSH_CLIENT_FS_GROUP\" for \"$SSH_KEY_FILE\" !!!"
chmod og-rwx,u+rw $SSH_KEY_FILE
exitOnError "Unable to change access rights for \"$SSH_KEY_FILE\" !!!"

# chown $SSH_CLIENT_FS_USER:$SSH_CLIENT_FS_GROUP $SSH_PUB_KEY_FILE
exitOnError "Unable to change owner to \"$SSH_CLIENT_FS_USER:$SSH_CLIENT_FS_GROUP\" for \"$SSH_PUB_KEY_FILE\" !!!"
chmod og-rwx,u+rw $SSH_PUB_KEY_FILE
exitOnError "Unable to change access rights for \"$SSH_PUB_KEY_FILE\" !!!"

echo "SSH client was created:" >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "* SSH keyfile: \"$SSH_KEY_FILE\"" >&2
echo "* SSH public keyfile: \"$SSH_PUB_KEY_FILE\"" >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator
echo "Copy the public keyfile \"$SSH_PUB_KEY_FILE\" to" >&2
echo "the SSH server into the folder \"$SSH_SERVER_KEY_DIR\" and apply the" >&2
echo "\"setup-ssh-server\" job!" >&2
# echo "--------------------------------------------------------------------------------" >&2
logSeparator

showSuccess "SSH client setup for \"$SSH_SERVER_HOSTNAME\" !"




© 2015 - 2024 Weber Informatics LLC | Privacy Policy