helm/shell/ssh/install
2016-12-16 22:08:31 -05:00

44 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
if [[ -z $FORCE ]]; then
pgrep sshd >/dev/null && exit
fi
case $OSTYPE in
darwin*)
macos-load-ssh() {
# Comes preinstalled on MacOS
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
}
# Activate service when script is finished
trap macos-load-ssh EXIT
;;
linux*)
if [[ -f /etc/arch-release ]]; then
sudo pacman --needed --noconfirm -S openssh
sudo systemctl enable sshd.service
sudo systemctl start sshd.service
elif [[ -f /etc/debian_version ]]; then
sudo apt-get install -y openssh-server
sudo service ssh start
sudo update-rc.d ssh defaults
fi
;;
esac
sshconf=/etc/ssh/sshd_config
sudo sed -i 's/^#\(AllowTcpForwarding\).*/\1 yes/;
s/^#\(RSAAuthentication\).*/\1 yes/;
s/^#\(PubkeyAuthentication\).*/\1 yes/;
s/^#\(PasswordAuthentication\).*/\1 no/;
s/^#\(PermitRootLogin\).*/\1 no/;
' "$sshconf"
# Enable X11 forwarding on desktop PCs (not remotes)
if [[ -z $SERVER ]]; then
sudo sed -i 's/^#\(X11Forwarding\).*/\1 yes/;
s/^#\(X11DisplayOffset.*\)/\1/;
s/^#\(X11UseLocalhost\).*/\1 yes/;
' "$sshconf"
fi