#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: http://mirrors.slickstack.io/bash/ss-install-ubuntu-ssh.txt ########################### #### path: /var/www/ss-install-ubuntu-ssh ########################################################## #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Reinstalls the Ubuntu (OS) SSH daemon for SlickStack servers (idempotent) ############ #### module version: Ubuntu 20.04 LTS ############################################################## #### sourced by: ss-install ######################################################################## #### bash aliases: ss install ubuntu ssh, ss install ssh ########################################### #################################################################################################### ## SS-CONFIG MUST BE PROPERLY CONFIGURED AND ON CURRENT BUILD BEFORE RUNNING SS-INSTALL ## ## ENSURE YOUR SS-CONFIG BUILD REMAINS CURRENT BY RUNNING SS-UPDATE OCCASIONALLY ## ## include SlickStack configuration ## source /var/www/ss-config ## include SlickStack functions ## source /var/www/ss-functions #################################################################################################### #### SS-Install-Ubuntu-SSH: Message (Begin Script) ################################################# #################################################################################################### ## this is a simple message that announces to the shell the purpose of this bash script ## ## it will only be noticed by sudo users who manually call ss core bash scripts ## ## echo message ## echo -e "${PURPLE}Running ss-install-ubuntu-ssh: Reinstalls the Ubuntu (OS) SSH daemon for SlickStack servers (idempotent)... ${NOCOLOR}" sleep "$SLEEP_MESSAGE_BEGIN" #################################################################################################### #### SS-Install-Ubuntu-SSH: Cleanup Temporary Files ################################################ #################################################################################################### ## delete tmp files ## rm /tmp/sshd_config* #################################################################################################### #### SS-Install-Ubuntu-SSH: Install (Configure) SSH Daemon ######################################### #################################################################################################### ## here we use an optimized boilerplate to reinstall the SSH/SFTP daemon to your server ## ## keep in mind that the port number will change (and root disabled) after this ## ## download latest versions ## wget -O /tmp/sshd_config http://mirrors.slickstack.io/ubuntu/sshd-config.txt ## replace variables ## sed -i "s/@SUDO_USER/${SUDO_USER}/g" /tmp/sshd_config sed -i "s/@SFTP_USER/${SFTP_USER}/g" /tmp/sshd_config ## set SSH port number (optional) ## if [[ -z "$SSH_PORT" ]]; then sed -i "s/@SSH_PORT/6969/g" /tmp/sshd_config else sed -i "s/@SSH_PORT/${SSH_PORT}/g" /tmp/sshd_config fi ## enable/disable password authentication (depending on if SSH_KEYS is enabled) ## if [[ "$SSH_KEYS" == "true" ]]; then sed -i "s/@SSH_PASSWORD_AUTHENTICATION/no/g" /tmp/sshd_config else sed -i "s/@SSH_PASSWORD_AUTHENTICATION/yes/g" /tmp/sshd_config fi ## enable/disable public key authentication (depending on if SSH_KEYS is enabled) ## if [[ "$SSH_KEYS" == "true" ]]; then sed -i "s/@SSH_PUBKEY_AUTHENTICATION/yes/g" /tmp/sshd_config else sed -i "s/@SSH_PUBKEY_AUTHENTICATION/no/g" /tmp/sshd_config fi ## allow IPv6 SSH sessions (any) if no IPv4 address is detected on the server ## # if [[ CURRENT IP ADDRESS IS IPV6 ONLY ]]; then # sed -i "s/AddressFamily inet/AddressFamily any/g" /tmp/sshd_config # fi ## Ref: https://stackoverflow.com/questions/5281341/get-local-network-interface-addresses-using-only-proc ## Ref: https://stackoverflow.com/questions/39983121/how-to-detect-if-system-has-ipv6-enabled-in-a-unix-shell-script ## Ref: https://www.cyberciti.biz/faq/bash-shell-command-to-find-get-ip-address/ ## copy files to their destinations ## cp /tmp/sshd_config /etc/ssh/sshd_config #################################################################################################### #### SS-Install-Ubuntu-SSH: Reset Permissions (Ubuntu SSH) ######################################### #################################################################################################### ## run ss-perms-ubuntu-ssh ## source /var/www/ss-perms-ubuntu-ssh #################################################################################################### #### SS-Install-Ubuntu-SSH: Restart Services (SSH) ################################################# #################################################################################################### ## restart services ## /etc/init.d/ssh restart #################################################################################################### #### SS-Install-Ubuntu-SSH: Cleanup Temporary Files ################################################ #################################################################################################### ## delete tmp files ## rm /tmp/sshd_config* #################################################################################################### #### SS-Install-Ubuntu-SSH: Touch Timestamp File (End Script) ###################################### #################################################################################################### ## this is a dummy timestamp file that will remember the last time this script was run ## ## it can be useful for developer reference and is sometimes used by SlickStack ## ## script timestamp ## touch /var/www/meta/.timestamp-ss-install-ubuntu-ssh #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: ## SS_EOF