2018-07-19 21:45:12 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function gpg-agent-forward() {
|
2018-07-19 22:05:24 +00:00
|
|
|
# BEGIN variables
|
|
|
|
# Input variables
|
2018-07-19 21:45:12 +00:00
|
|
|
ruser=$1
|
|
|
|
hostname=$2
|
2018-07-19 22:05:24 +00:00
|
|
|
# Generates random 3 character host shortcut. LC_CTYPE is needed for OS X and FreeBSD.
|
|
|
|
# https://gist.github.com/earthgecko/3089509
|
|
|
|
hostshortcut=$(cat /dev/urandom | env LC_CTYPE=C tr -dc "a-z0-9" | fold -w 3 | head -n 1)
|
|
|
|
# END VARIABLES
|
|
|
|
|
|
|
|
# BEGIN script
|
2018-07-19 21:45:12 +00:00
|
|
|
touch ~/.ssh/config
|
|
|
|
echo "CREATING GPG-AGENT FORWARDING CONFIG"
|
|
|
|
echo "YOUR HOST SHORTCUT IS \"$hostshortcut\""
|
|
|
|
echo "host $hostshortcut" >> ~/.ssh/config
|
|
|
|
echo " hostname $hostname" >> ~/.ssh/config
|
|
|
|
echo " User $ruser" >> ~/.ssh/config
|
|
|
|
echo " RemoteForward /home/$ruser/.gnupg/S.gpg-agent $HOME/.gnupg/S.gpg-agent" >> ~/.ssh/config
|
|
|
|
echo " RemoteForward /home/$ruser/.gnupg/S.gpg-agent.ssh $HOME/.gnupg/S.gpg-agent.ssh" >> ~/.ssh/config
|
|
|
|
echo " ServerAliveInterval 10" >> ~/.ssh/config
|
|
|
|
echo "Use this shortcut to forward your Yubikey to $host:"
|
|
|
|
echo " ssh $hostshortcut"
|
2018-07-19 22:05:24 +00:00
|
|
|
echo "Inspect or edit the config:"
|
|
|
|
echo " vi ~/.ssh/config"
|
|
|
|
echo "DONE"
|
2018-07-19 21:45:12 +00:00
|
|
|
return 0
|
2018-07-19 22:05:24 +00:00
|
|
|
# END script
|
2018-07-19 21:45:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gpg-agent-forward $1 $2
|