#!/bin/bash if which ssh >/dev/null 2>&1; then echo "SSH is installed" exit 1 else echo "SSH is not installed" fi if lsb_release -a 2>/dev/null | grep -q -E "Debian|Ubuntu"; then echo "Running Debian or Ubuntu" apt-get install openssh-server systemctl start sshd elif cat /etc/os-release 2>/dev/null | grep -q -i "alpine"; then echo "Running Alpine" # Stop and remove Dropbear rc-service dropbear stop rc-update del dropbear apk del dropbear* -f # Stop and remove SSHD rc-service sshd stop rc-update del sshd apk del openssh* -f # Clean up Dropbear and SSH configurations rm -rf /etc/dropbear rm -rf /etc/ssh rm /etc/init.d/ssh # Reboot now if needed # reboot now # Install OpenSSH and necessary packages apk add openssh gcompat libstdc++ curl bash git grep apk add procps --no-cache # Start and add SSHD to startup rc-service sshd start rc-update add sshd # Update AllowTcpForwarding setting sed -i 's/^#*AllowTcpForwarding.*/AllowTcpForwarding yes/' /etc/ssh/sshd_config # Update PermitTunnel setting sed -i 's/^#*PermitTunnel.*/PermitTunnel yes/' /etc/ssh/sshd_config # Uncomment the line if needed (remove '#' at the beginning) sed -i 's/^#PermitTunnel.*/PermitTunnel yes/' /etc/ssh/sshd_config # Restart the SSH service to apply the changes /etc/init.d/sshd restart else echo "Unknown distribution" exit 1 fi # Set PermitRootLogin to prohibit-password sed -i 's/^#*PermitRootLogin.*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config