37 lines
1.3 KiB
Bash
Executable file
37 lines
1.3 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
which myssh > /dev/null 2>&1
|
|
if [ $? -eq 1 ]
|
|
then
|
|
mkdir -p $HOME/bin
|
|
cp ./script/myssh $HOME/bin/myssh
|
|
if [[ ! $PATH =~ $HOME/bin ]]
|
|
then
|
|
if [[ $SHELL =~ bin/bash$ ]]
|
|
then
|
|
echo -e 'PATH=$PATH:$HOME/bin' >> $HOME/.bashrc
|
|
elif [[ $SHELL =~ bin/zsh$ ]]
|
|
then
|
|
echo -e 'PATH=$PATH:$HOME/bin' >> $HOME/.zshrc
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [ ! -f ./etc/ssh/ssh_host_ed25519_key ]
|
|
then
|
|
echo "Generating sqlproxy SSHD keys"
|
|
ssh-keygen -f ./ -A
|
|
fi
|
|
|
|
read -r -p "Auto generate client keys+config? [Y/n] " GEN_KEYS
|
|
case $GEN_KEYS in
|
|
[yY]*)
|
|
mkdir -p ~/.ssh
|
|
read -r -p "Key Name (should not already exist in ~/.ssh): " KEY_NAME
|
|
ssh-keygen -t ed25519 -f ~/.ssh/$KEY_NAME.key -C "$(date --iso-8601)_$(whoami)@$HOST"
|
|
read -r -p "Target Host: " HOST_NAME
|
|
echo -ne "\n\nHost $HOST_NAME\n User sqlproxy\n IdentityFile ~/.ssh/$KEY_NAME.key" >> ~/.ssh/config
|
|
echo -e command=\"/sqlproxy_cli.sh\" $(cat ~/.ssh/$KEY_NAME.key.pub) >> ./etc/ssh/.ssh/authorized_keys
|
|
break;;
|
|
*) echo -e "Not generating client ssh key.\nPlease put your desired public keys into ./etc/ssh/.ssh/authorized_keys\nAlso add 'command=\"/sqlproxy_cli.sh\" ' in front of your key";;
|
|
esac
|