Skip to content

Instantly share code, notes, and snippets.

@iolate
Created February 17, 2019 15:53
Show Gist options
  • Save iolate/956e3859fadb7d5b79051b3ed55e1265 to your computer and use it in GitHub Desktop.
Save iolate/956e3859fadb7d5b79051b3ed55e1265 to your computer and use it in GitHub Desktop.
#!/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