#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: https://mirrors.slickstack.io/bash/ss-install-ubuntu-users.txt ######################## #### path: /var/www/ss-install-ubuntu-users ######################################################## #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Reinstalls Linux OS users based on ss-config ######################################### #### module version: Ubuntu 22.04 LTS ############################################################## #### sourced by: ss-install ######################################################################## #### bash aliases: ss install ubuntu users, ss install users ####################################### #################################################################################################### ## 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 ## ## 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-Install-Ubuntu-Users) ################################################### #################################################################################################### ## 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) ## D. Configure Users + Passwords + Groups ## E. Configure Sudo Permissions ## F. Reset Permissions (Ubuntu Users) ## H. Configure Ubuntu Bash Shortcuts #################################################################################################### #### A. SS-Install-Ubuntu-Users: 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 ## ## script timestamp ## ss_touch "${TIMESTAMP_SS_INSTALL_UBUNTU_USERS}" #################################################################################################### #### B. SS-Install-Ubuntu-Users: 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 ## ss_echo "${COLOR_INFO}Running ss-install-ubuntu-users... ${COLOR_RESET}" #################################################################################################### #### D. SS-Install-Ubuntu-Users: Configure Root User ################################################### #################################################################################################### ## set root password ## echo "root:${ROOT_PASSWORD}" | /usr/sbin/chpasswd ## ensure root password never expires ## chage -E -1 -m 0 -M -1 -I -1 -W 99999 root #################################################################################################### #### D. SS-Install-Ubuntu-Users: Configure Sudo User ################################################### #################################################################################################### ## create sudo user ## ss_adduser "${SUDO_USER}" ## assign password to sudo user ## echo "${SUDO_USER}:${SUDO_PASSWORD}" | /usr/sbin/chpasswd # chage -E -1 -m 0 -M -1 -I -1 -W 99999 $SUDO_USER ## ensure home directory exists ## mkhomedir_helper "${SUDO_USER}" #################################################################################################### #### D. SS-Install-Ubuntu-Users: Configure SFTP User ################################################### #################################################################################################### ## create sftp user ## ss_adduser "${SFTP_USER}" ## assign password to sftp user ## echo "${SFTP_USER}:${SFTP_PASSWORD}" | /usr/sbin/chpasswd # chage -E -1 -m 0 -M -1 -I -1 -W 99999 $SFTP_USER ## ensure home directory exists ## mkhomedir_helper "${SFTP_USER}" #################################################################################################### #### D. SS-Install-Ubuntu-Users: Configure Groups ################################################## #################################################################################################### ## add slickstack group ## groupadd -f slickstack ## add sftp user to groups ## usermod -a -G slickstack "${SFTP_USER}" usermod -a -G www-data "${SFTP_USER}" ## add sudo user to groups ## usermod -a -G slickstack "${SUDO_USER}" usermod -a -G www-data "${SUDO_USER}" ## add www-data user to groups ## usermod -a -G slickstack www-data #################################################################################################### #### E. SS-Install-Ubuntu-Users: Configure Sudoers File ######################################## #################################################################################################### ## download latest versions ## ss_wget "${TMP_SUDOERS}" "${MIRROR_SUDOERS}" ## replace variables ## sed -i "s/@SUDO_USER/${SUDO_USER}/g" "${TMP_SUDOERS}" ## copy files to their destinations ## ss_mv "${TMP_SUDOERS}" "${PATH_SUDOERS}" ## delete tmp files ## ss_rm "${TMP_SUDOERS}" #################################################################################################### #### F. SS-Install-Ubuntu-Users: Reset Permissions (Ubuntu Users) ################################## #################################################################################################### ## run ss-perms-ubuntu-users ## source "${PATH_SS_PERMS_UBUNTU_USERS}" #################################################################################################### #### H. SS-Install-Ubuntu-Users: Configure Ubuntu Bash Shortcuts ################################### #################################################################################################### ## here we reinstall bash run commands which requires the users to be installed already ## ## there is no drawback to running this repeatedly so we include it here casually ## ## run ss-install-ubuntu-bash ## source "${PATH_SS_INSTALL_UBUNTU_BASH}" #################################################################################################### #### PLACEHOLDER: 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/94060/run-adduser-non-interactively ## Ref: http://manpages.ubuntu.com/manpages/trusty/man8/adduser.8.html ## Ref: https://www.computerhope.com/unix/adduser.htm ## Ref: https://explainshell.com/explain?cmd=adduser+--disabled-password+--quiet+--system+--home+%2Fvar%2Frun%2Frails-new+--no-create-home+--gecos+%22Rails+New+daemon%22+--group+rails-new ## Ref: https://stackoverflow.com/questions/2150882/how-to-automatically-add-user-account-and-password-with-a-bash-script ## Ref: https://github.com/jupyterhub/jupyterhub/issues/2145 ## Ref: https://serverfault.com/questions/167416/how-can-i-automatically-change-directory-on-ssh-login ## Ref: https://unix.stackexchange.com/questions/140602/how-do-i-start-all-shell-sessions-in-a-directory-other-than-home ## Ref: https://askubuntu.com/questions/335961/create-default-home-directory-for-existing-user-in-terminal ## Ref: https://unix.stackexchange.com/questions/121087/why-is-this-random-password-flagged-saying-it-is-too-simplistic-systematic ## Ref: https://www.codedodle.com/fix-wpcli-wp-settings-error.html ## Ref: https://www.alexgeorgiou.gr/wp-cli-www-data-user-permissions-linux/ ## Ref: https://github.com/littlebizzy/slickstack/issues/164 ## SS_EOF