Skip to content

Instantly share code, notes, and snippets.

@iolate
Created Feb 17, 2019
Embed
What would you like to do?
#!/bin/bash
# shellinabox ssh wrapper
# -s /:nobody:nogroup:/:/path/to/sshwrapper.sh
echo ""
echo "Example: user@host[:22]"
read -p "Connect to: " connstr;
if ! [[ "$connstr" =~ "@" ]]; then
echo ""
echo "Username is required."
exit
fi
idx_at=`expr index $connstr "@"`
username=${connstr:0:idx_at-1}
port=22
if [[ "$connstr" =~ ":" ]]; then
idx_colon=`expr index $connstr ":"`
host=${connstr:idx_at:(idx_colon-idx_at-1)}
port=${connstr:idx_colon}
else
host=${connstr:idx_at}
fi
if [ -z "$host" ]; then
echo ""
echo "A hostname or ip address is required."
exit
fi
if [[ -n ${port//[0-9]/} ]]; then
echo ""
echo "Port must be a number between 0 and 65535."
exit
fi
echo ""
exec ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o "LogLevel ERROR" -p $port $username@$host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment