V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m48s
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m48s
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
@@ -36,11 +36,30 @@ guard_sourcing
|
||||
setup_ssh() {
|
||||
do_in_target "${TARGET}" apt-get install -y ssh
|
||||
|
||||
#######################################
|
||||
# Variable declaration
|
||||
#######################################
|
||||
declare -a ary_user=()
|
||||
ary_user+=("${user_user0_name}")
|
||||
[[ -v "${user_user1_name}" ]] && ary_user+=("${user_user1_name}")
|
||||
[[ -v "${user_user2_name}" ]] && ary_user+=("${user_user2_name}")
|
||||
[[ -v "${user_user3_name}" ]] && ary_user+=("${user_user3_name}")
|
||||
declare -i max_index=0 index i
|
||||
declare var=""
|
||||
|
||||
### Search all set variables for user_userN_name patterns.
|
||||
while IFS='=' read -r var; do
|
||||
if [[ "${var}" =~ ^user_user([0-9]+)_name$ ]]; then
|
||||
index="${BASH_REMATCH[1]}"
|
||||
(( index > max_index )) && max_index="${index}"
|
||||
fi
|
||||
done < <(compgen -v)
|
||||
|
||||
### Only process those for which both *_name and *_authentication_access_ssh are set.
|
||||
for ((i = 0; i <= max_index; i++)); do
|
||||
declare var_auth="user_user${i}_authentication_access_ssh"
|
||||
declare var_name="user_user${i}_name"
|
||||
|
||||
if [[ -v "${var_auth}" && -v "${var_name}" && "${!var_auth}" == "true" ]]; then
|
||||
ary_user+=("${!var_name}")
|
||||
fi
|
||||
done
|
||||
|
||||
rm -rf "${TARGET}"/etc/ssh/ssh_host_*key*
|
||||
|
||||
@@ -63,6 +82,7 @@ setup_ssh() {
|
||||
chmod 0600 "${TARGET}/etc/ssh/sshd_config"
|
||||
chmod 0600 "${TARGET}/etc/ssh/ssh_config"
|
||||
|
||||
# shellcheck disable=SC2153
|
||||
sed -i "s/ListenAddress 0.0.0.0/ListenAddress ${VAR_FINAL_IPV4}/" "${TARGET}/etc/ssh/sshd_config"
|
||||
|
||||
if [[ -n "${VAR_FINAL_IPV6}" ]]; then
|
||||
@@ -73,7 +93,7 @@ setup_ssh() {
|
||||
|
||||
sed -i "s/Port MUST_BE_CHANGED/Port ${ssh_port}/" "${TARGET}/etc/ssh/sshd_config"
|
||||
|
||||
if [[ -n "${user_user0_name}" ]]; then
|
||||
if (( ${#ary_user[@]} > 0 )); then
|
||||
sed -i "s/AllowUsers root/AllowUsers root ${ary_user[*]}/" "${TARGET}/etc/ssh/sshd_config"
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user