diff --git a/ssh-config.sh b/ssh-config.sh index 9a1bd45..7672527 100755 --- a/ssh-config.sh +++ b/ssh-config.sh @@ -17,27 +17,35 @@ case ${UNAME} in esac echo "warning: this script will disable ssh password authentication" -read -p "continue? [y/N] " answer +echo -n "continue? [y/N] " +read answer if [ "${answer}" != "y" ]; then exit 0 fi -echo "generating safe moduli" if [ -f /etc/ssh/moduli ]; then + echo "filtering safe primes" awk '$5 > 2000' /etc/ssh/moduli > /tmp/moduli mv /tmp/moduli /etc/ssh/moduli else - ssh-keygen -G /etc/ssh/moduli.all -b 4096 - ssh-keygen -T /etc/ssh/moduli.safe -f /etc/ssh/moduli.all + echo "generating safe primes" + echo "warning: this can take a long time (2h+)" + echo -n "continue? [n/Y] " + read answer + if [ "${answer}" == "n" ]; then + exit 0 + fi + ssh-keygen -G /etc/ssh/moduli.all -b 4096 > /dev/null + ssh-keygen -T /etc/ssh/moduli.safe -f /etc/ssh/moduli.all > /dev/null mv /etc/ssh/moduli.safe /etc/ssh/moduli rm /etc/ssh/moduli.all fi echo "cleaning ssh host keys" rm /etc/ssh/ssh_host_*key* -ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key < /dev/null -ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key < /dev/null +ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" > /dev/null +ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N "" > /dev/null echo "writing ssh config" if [ -f /etc/ssh/sshd_config ]; then @@ -77,7 +85,8 @@ EOF ;; esac -read -p "enter your username " user +echo -n "enter your username " +read user if [ -z "${user}" ]; then echo "error: no user submitted" 1>&2 @@ -91,7 +100,8 @@ fi chmod 700 /home/${user}/.ssh chown ${user}: /home/${user}/.ssh -read -p "paste your ssh public key " sshkey +echo "paste your ssh public key " +read sshkey if [ -z "${sshkey}" ]; then echo "error: no ssh key submitted" 1>&2 @@ -101,13 +111,14 @@ fi echo "${sshkey}" > /home/${user}/.ssh/authorized_keys chmod 600 /home/${user}/.ssh/authorized_keys -chown ${user}:root /home/${user}/.ssh/authorized_keys case ${UNAME} in Linux) + chown ${user}:root /home/${user}/.ssh/authorized_keys service ssh restart ;; OpenBSD|FreeBSD) + chown ${user}:wheel /home/${user}/.ssh/authorized_keys /etc/rc.d/sshd restart ;; esac