go1.6 + ssh script bsd support

This commit is contained in:
ston1th 2016-03-04 19:24:01 +01:00
commit 157885902b
2 changed files with 44 additions and 26 deletions

View file

@ -1,9 +1,20 @@
#!/bin/bash
#!/bin/sh
if [ ${EUID} -ne 0 ]; then
echo "error: this script must be run as root" 1>&2
exit 1
fi
UNAME=$(uname)
case ${UNAME} in
Linux)
if [ ${EUID} -ne 0 ]; then
echo "error: this script must be run as root" 1>&2
exit 1
fi
;;
OpenBSD|FreeBSD)
if [ $(id -u) -ne 0 ]; then
echo "error: this script must be run as root" 1>&2
exit 1
fi
;;
esac
echo "warning: this script will disable ssh password authentication"
read -p "continue? [y/N] " answer
@ -41,29 +52,30 @@ HostKey /etc/ssh/ssh_host_rsa_key
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com
UsePrivilegeSeparation yes
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
UsePrivilegeSeparation sandbox
PermitRootLogin no
StrictModes yes
RSAAuthentication no
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
PasswordAuthentication no
X11Forwarding no
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
EOF
case ${UNAME} in
Linux)
cat << EOF >> /etc/ssh/sshd_config
AuthorizedKeysFile %h/.ssh/authorized_keys
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
EOF
;;
OpenBSD|FreeBSD)
cat << EOF >> /etc/ssh/sshd_config
Subsystem sftp /usr/libexec/sftp-server
AuthorizedKeysFile .ssh/authorized_keys
EOF
;;
esac
read -p "enter your username " user
@ -91,10 +103,16 @@ echo "${sshkey}" > /home/${user}/.ssh/authorized_keys
chmod 600 /home/${user}/.ssh/authorized_keys
chown ${user}:root /home/${user}/.ssh/authorized_keys
service ssh restart
case ${UNAME} in
Linux)
service ssh restart
;;
OpenBSD|FreeBSD)
/etc/rc.d/sshd restart
;;
esac
ssh=$(ps aux | awk '/\/usr\/s?bin\/sshd/')
if [ -z "${ssh}" ]; then
if [ -z "$(ps aux | awk '/\/usr\/s?bin\/sshd/')" ]; then
echo "error: ssh service failed to restart" 1>&2
echo "please check for sshd config errors manually" 1>&2
exit 1