ssh config bug fixes

This commit is contained in:
ston1th 2016-03-04 23:29:12 +01:00
commit 321b5ce674

View file

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