Compare commits

..

No commits in common. "pubkey_selection" and "master" have entirely different histories.

3 changed files with 28 additions and 33 deletions

View File

@ -3,7 +3,6 @@
# 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
@ -17,11 +16,8 @@ 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/

View File

@ -1,4 +0,0 @@
#domain,user,remote,local,yubi_support,usual identity file,yubikey identity file,
example.me,user,22,12345,1,~/.ssh/id_rsa,~/.ssh/id_ed25519_sk
octosrv.me,marco,22,12345,0,~/.ssh/id_rsa,
raber.me,marco,2222,4343,1,~/.ssh/id_rsa_pass,~/.ssh/id_ed25519_sk

53
sshin
View File

@ -1,28 +1,31 @@
#!/bin/bash #!/bin/bash
command="ssh " usage() {
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
}
MANY_ARGS=$# IP_PREFIX="192.168.1."
[[ $MANY_ARGS -eq 2 ]] && SSHIN_USER=$1 && shift [[ $# -le 1 ]] && usage && exit 1
DOMAIN=$1 [[ $1 = "-h" ]] && usage -h && exit 1
re='^[0-9]+$'
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) command="ssh ${1}@"
shift
[[ $MANY_ARGS -eq 1 ]] && SSHIN_USER=$DEFAULT_USER if [[ $1 =~ $re ]]
then
command="${command} ${SSHIN_USER}@${DOMAIN}" command="${command}192.168.1.$1"
else
lsusb | grep -q "Yubico" && YUBIKEY_PRESENCE=1 || YUBIKEY_PRESENCE=0 [[ $(uname) = "Linux" ]] && ports_file="$HOME/.local/share/sshin/port_association" || ports_file="$HOME/sshin/port_association"
[[ $YUBIKEY_PRESENCE -eq 1 ]] && [[ $YUBIKEY_SUPPORT -eq 1 ]] && command="${command} -i $YUBIKEY_PUBKEY" port=$(grep $1 $ports_file | awk '{print $2}')
[[ $USUAL_PUBKEY ]] && command="${command} -i ${USUAL_PUBKEY}" command="${command}$1"
[[ $REMOTE_PORT ]] && command="${command} -p ${REMOTE_PORT}" [[ -n $port ]] && command="${command} -p $port"
[[ $LOCAL_PORT ]] && command="${command} -D${LOCAL_PORT}" dport=$(grep $1 $ports_file | awk '{print $NF}')
echo "${command}" [[ -n $port ]] && command="${command} -D$dport"
sleep 1 fi
#echo "Domain $DOMAIN" echo $command
#echo "User $DEFAULT_USER" $command
#echo "Remote $REMOTE_PORT"
#echo "Local $LOCAL_PORT"
#echo "Support $YUBIKEY_SUPPORT"
#echo "Usual $USUAL_PUBKEY"
${command}