install.fairie/home/private_dot_ssh/system/run_onchange_after_sshd.tmpl
Brian Zalewski 58361748f6 Update 3 files
- /home/private_dot_ssh/system/run_onchange_after_sshd.tmpl
- /home/private_dot_ssh/fail2ban/run_onchange_after_fail2ban.tmpl
- /home/private_dot_ssh/endlessh/run_onchange_after_endlessh.tmpl
2023-02-16 02:46:46 +00:00

47 lines
1.8 KiB
Cheetah

{{- if ne .host.distro.family "windows" -}}
#!/usr/bin/env bash
# sshd_config hash: {{- include (joinPath .host.home ".ssh" "system" "sshd_config") | sha256sum -}}
# banner hash: {{- include (joinPath .host.home ".ssh" "system" "banner") | sha256sum -}}
{{ includeTemplate "universal/profile" }}
{{ includeTemplate "universal/logg" }}
### Update /etc/ssh/sshd_config if environment is not WSL
if [[ ! "$(grep Microsoft /proc/version > /dev/null)" ]]; then
if [ -d /etc/ssh ]; then
logg info 'Copying ~/.ssh/system/banner to /etc/ssh/banner'
sudo cp -f "$HOME/.ssh/system/banner" /etc/ssh/banner
logg info 'Copying ~/.ssh/system/sshd_config to /etc/ssh/sshd_config'
sudo cp -f "$HOME/.ssh/system/sshd_config" /etc/ssh/sshd_config
if command -v semanage > /dev/null; then
logg info 'Apply SELinux configuration addressing custom SSH port'
sudo semanage port -a -t ssh_port_t -p tcp {{ .host.ssh.port }}
logg info 'Allow NIS SSHD'
sudo setsebool -P nis_enabled 1
fi
### Restart SSH server
if [ -d /Applications ] && [ -d /System ]; then
# macOS
logg info 'Running `sudo launchctl stop com.openssh.sshd`'
sudo launchctl stop com.openssh.sshd
logg info 'Running `sudo launchctl start com.openssh.sshd`'
sudo launchctl start com.openssh.sshd
else
# Linux
logg info 'Enabling the `sshd` service'
sudo systemctl enable sshd
logg info 'Restarting the `sshd` service'
sudo systemctl restart sshd
fi
else
logg warn 'The /etc/ssh folder does not exist'
fi
else
logg info 'Skipping sshd_config application since environment is WSL'
fi
{{ end -}}