run on ip
This commit is contained in:
parent
9b60386710
commit
325a2157b5
4
Makefile
4
Makefile
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
# paths
|
# paths
|
||||||
PREFIX = /home/${USER}/.local
|
PREFIX = /home/${USER}/.local
|
||||||
|
CONFPREFIX = /home/${USER}/.config
|
||||||
MANPREFIX = $(PREFIX)/share/man
|
MANPREFIX = $(PREFIX)/share/man
|
||||||
SHELL = bash
|
SHELL = bash
|
||||||
|
|
||||||
|
@ -16,8 +17,11 @@ install:
|
||||||
cp sshin $(PREFIX)/bin
|
cp sshin $(PREFIX)/bin
|
||||||
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
|
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
|
||||||
cp sshin.1 $(DESTDIR)$(MANPREFIX)/man1
|
cp sshin.1 $(DESTDIR)$(MANPREFIX)/man1
|
||||||
|
mkdir -p $(DESTDIR)$(CONFPREFIX)/sshin
|
||||||
|
cp -n hosts.example $(DESTDIR)$(CONFPREFIX)/sshin/hosts
|
||||||
|
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(DESTDIR)$(PREFIX)/bin/sshin
|
rm -f $(DESTDIR)$(PREFIX)/bin/sshin
|
||||||
rm -f $(DESTDIR)$(MANPREFIX)/man1/sshin.1
|
rm -f $(DESTDIR)$(MANPREFIX)/man1/sshin.1
|
||||||
|
rm -f $(DESTDIR)$(CONFPREFIX)/sshin/
|
||||||
|
|
61
sshin
61
sshin
|
@ -1,49 +1,28 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
usage() {
|
command="ssh "
|
||||||
echo "Usage: sshin user hostname/last byte of IP address"
|
|
||||||
echo
|
|
||||||
echo "This tools automatically chooses the server port based on the port_association file in ~/local/share/sshin/port_association"
|
|
||||||
echo
|
|
||||||
echo "Example: \"sshin foo bar.com \" will run \"ssh foo@bar.com -p 2323\""
|
|
||||||
echo "Example: \"sshin foo 43 \" will run \"ssh foo@192.168.1.43\""
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
IP_PREFIX="192.168.1."
|
MANY_ARGS=$#
|
||||||
[[ $# -le 1 ]] && usage && exit 1
|
[[ $MANY_ARGS -eq 2 ]] && SSHIN_USER=$1 && shift
|
||||||
[[ $1 = "-h" ]] && usage -h && exit 1
|
DOMAIN=$1
|
||||||
re='^[0-9]+$'
|
|
||||||
|
|
||||||
USUAL_PUBKEY=~/.ssh/id_rsa
|
IFS="," read -r DOMAIN DEFAULT_USER REMOTE_PORT LOCAL_PORT YUBIKEY_SUPPORT USUAL_PUBKEY YUBIKEY_PUBKEY < <(tail -n +2 $HOME/.config/sshin/hosts | grep $DOMAIN | head -n 1)
|
||||||
YUBIKEY_PUBKEY=~/.ssh/id_ed25519_sk
|
|
||||||
|
|
||||||
HOSTS_FILE=~/.local/share/sshin/hosts
|
[[ $MANY_ARGS -eq 1 ]] && SSHIN_USER=$DEFAULT_USER
|
||||||
|
|
||||||
command="ssh ${1}@"
|
command="${command} ${SSHIN_USER}@${DOMAIN}"
|
||||||
shift
|
|
||||||
if [[ $1 =~ $re ]]
|
|
||||||
then
|
|
||||||
command="${command}192.168.1.$1"
|
|
||||||
else
|
|
||||||
[[ $(uname) = "Linux" ]] && ports_file="$HOME/.local/share/sshin/port_association" || ports_file="$HOME/sshin/port_association"
|
|
||||||
port=$(grep $1 $ports_file | awk '{print $2}')
|
|
||||||
command="${command}$1"
|
|
||||||
[[ -n $port ]] && command="${command} -p $port"
|
|
||||||
dport=$(grep $1 $ports_file | awk '{print $NF}')
|
|
||||||
[[ -n $port ]] && command="${command} -D$dport"
|
|
||||||
fi
|
|
||||||
|
|
||||||
#check if Yubikey is present
|
|
||||||
lsusb | grep -q "Yubico" && YUBIKEY_PRESENCE=1 || YUBIKEY_PRESENCE=0
|
lsusb | grep -q "Yubico" && YUBIKEY_PRESENCE=1 || YUBIKEY_PRESENCE=0
|
||||||
|
[[ $YUBIKEY_PRESENCE -eq 1 ]] && [[ $YUBIKEY_SUPPORT -eq 1 ]] && command="${command} -i $YUBIKEY_PUBKEY"
|
||||||
#check if the host you are connecting to has Yubikey support (both client and server need openssh >= 8.2)
|
[[ $USUAL_PUBKEY ]] && command="${command} -i ${USUAL_PUBKEY}"
|
||||||
YUBIKEY_SUPPORT=$(cat $HOSTS_FILE | grep $1 | awk '{print $2}')
|
[[ $REMOTE_PORT ]] && command="${command} -p ${REMOTE_PORT}"
|
||||||
[[ $YUBIKEY_SUPPORT = "" ]] && echo "vuoto" && YUBIKEY_SUPPORT=0
|
[[ $LOCAL_PORT ]] && command="${command} -D${LOCAL_PORT}"
|
||||||
|
echo "${command}"
|
||||||
|
sleep 1
|
||||||
[[ $YUBIKEY_PRESENCE -eq 1 ]] && [[ $YUBIKEY_SUPPORT -eq 1 ]] && command="${command} -i $YUBIKEY_PUBKEY" || command="${command} -i $USUAL_PUBKEY"
|
#echo "Domain $DOMAIN"
|
||||||
|
#echo "User $DEFAULT_USER"
|
||||||
echo $command
|
#echo "Remote $REMOTE_PORT"
|
||||||
#echo $YUBIKEY_SUPPORT
|
#echo "Local $LOCAL_PORT"
|
||||||
$command
|
#echo "Support $YUBIKEY_SUPPORT"
|
||||||
|
#echo "Usual $USUAL_PUBKEY"
|
||||||
|
${command}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user