#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: https://mirrors.slickstack.io/bash/ss-perms-ubuntu-ssh.txt ############################ #### path: /var/www/ss-perms-ubuntu-ssh ############################################################ #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Resets all file and user permissions for the Ubuntu SSH daemon and SSH keys ########## #### module version: Ubuntu 22.04 LTS ############################################################## #### sourced by: ss-perms, ss-install-ubuntu-ssh ################################################### #### bash aliases: ss perms ubuntu ssh, ss perms ssh ############################################### #################################################################################################### ## source ss-config ## source /var/www/ss-config ## source ss-functions ## source /var/www/ss-functions ## BELOW THIS RELIES ON SS-CONFIG AND SS-FUNCTIONS #################################################################################################### #### TABLE OF CONTENTS (SS-Perms-Ubuntu-SSH) ####################################################### #################################################################################################### ## this is a brief summary of the different code snippets you will find in this script ## ## each section should be commented so you understand what is being accomplished ## ## A. Touch Timestamp File ## B. Message (Begin Script) ## C. Reset Permissions (SSH) #################################################################################################### #### A. SS-Perms-Ubuntu-SSH: Touch Timestamp File ################################################## #################################################################################################### ## 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 ## ss_touch "${TIMESTAMP_SS_PERMS_UBUNTU_SSH}" #################################################################################################### #### B. SS-Perms-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 seen by sudo users who manually run this script in the shell ## ss_echo "${COLOR_INFO}Running ss-perms-ubuntu-ssh... ${COLOR_RESET}" #################################################################################################### #### C. SS-Perms-Ubuntu-SSH: Reset Permissions (SSH) ############################################### #################################################################################################### ## ssh keys ## mkdir "$PATH_DIR_AUTH" chown root:root "$PATH_DIR_AUTH" ## must be root:root (centralized keys) chmod 0755 "$PATH_DIR_AUTH" ## must be 0755 ss_touch "${PATH_SSH_AUTHORIZED_KEYS_FILE}" chown root:root "$PATH_SSH_AUTHORIZED_KEYS_FILE" ## must be root:root (centralized keys) chmod 0644 "$PATH_SSH_AUTHORIZED_KEYS_FILE" ## must be 0644 #### sshd daemon ## chown root:root /etc/ssh/sshd_config ## must be root:root chmod 0644 /etc/ssh/sshd_config ## 0644 Ubuntu default #################################################################################################### #### SlickStack: Reset Permissions (SlickStack Scripts) ############################################ #################################################################################################### ## we include this permissions reset in all cron jobs and bash scripts for redundancy ## ## chmod 0700 means only the root/sudo users can execute any SlickStack scripts ## ## THIS SNIPPET DOES NOT RELY ON SS-CONFIG OR SS-FUNCTIONS ## SNIPPET: ss bash scripts, ss cron jobs ## UPDATED: 02JUL2022 chown root:root /var/www/ss* ## must be root:root chown root:root /var/www/crons/*cron* ## must be root:root chown root:root /var/www/crons/custom/*cron* ## must be root:root chmod 0700 /var/www/ss* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/*cron* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/custom/*cron* ## 0700 means only root/sudo can execute #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://askubuntu.com/questions/466549/bash-home-user-ssh-authorized-keys-no-such-file-or-directory ## Ref: https://serverfault.com/questions/313465/is-a-central-location-for-authorized-keys-a-good-idea ## Ref: https://github.com/littlebizzy/slickstack/issues/81 ## SS_EOF