vm-start/ssh-local.sh
2024-01-22 00:44:36 +00:00

69 lines
1.7 KiB
Bash
Executable file

#/bin/bash
#
# little class about bash extension parametters.
#
# ${myvar#pattern} delete shortest occurence from the begining
# ${myvar##pattern} delete longuest occurence from begining
# ${myvar%pattern} delete shortest occurence from the end
# ${myvar%%pattern} delete longuest occurence from the end
#
# conclusion, use of # will delete the pattern at begining
# and % will delete the parameter at the end.
User="root"
Port=10022
Version="1.0.1"
Help_message="
ssh-local [OPTION] [OPTION=VALUE]
script which permit to launch ssh to connect to the vm on localhost without letting any traces on this computer.
-u <user>,--user=<user> Select the user, by default root
-p <port>,--port=<port> Select the port, by default 10022
-v, --version print the version and exit
-h, --help print this help and exit
"
# looking for double parametters.
for (( arg=1; arg<$#; arg++)); do
value="$((arg+1))"
if [ "${!arg}" == "-u" ]
then
User=${!value}
elif [ "${!arg}" == "-p" ]
then
Port=${!value}
fi
done
# looking for all parametter alone
for i in "$@"; do
if [ "${i%=*}" == "--user" ]
then
User="${i#*=}"
elif [ "${i%=*}" == "--port" ]
then
Port="${i#*=}"
elif [ "${i}" == "--version" ] || [ "${i}" == "-v" ]
then
echo "Prog ssh-local v.${Version}"
exit 0
elif [ "${i}" == "--help" ] || [ "${i}" == "-h" ]
then
echo "$Help_message"
exit 0
fi
done
echo try to connect with user=${User} and port=${Port}
echo port=${Port}
ssh -o "StrictHostKeyChecking no" -o "UserKnownHostsFile=/dev/null" -p ${Port} ${User}@localhost