Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions scripts/install-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -652,16 +652,18 @@ configure_openssh_server() {
(grep -Fxq 'Include /etc/ssh/sshd_config.d/*.conf' "$sshd_config" &&
{ ! grep -Eq '^AuthorizedKeysCommand|^AuthorizedKeysCommandUser' "$sshd_config" ||
! grep -Eq '^AuthorizedKeysCommand|^AuthorizedKeysCommandUser' "$sshd_config_d"/*.conf 2>/dev/null; }); then
# Configuration should be put in /etc/ssh/sshd_config.d director
# Configuration should be put in /etc/ssh/sshd_config.d directory
# Find active configuration file with the directives we're interested in (sorted numerically)
active_config=$(find "$sshd_config_d"/*.conf -exec grep -l '^AuthorizedKeysCommand\|^AuthorizedKeysCommandUser' {} \; 2>/dev/null | sort -V | head -n 1)

if [[ "$active_config" == *"$opk_config_suffix" ]] || [[ "$OVERWRITE_ACTIVE_CONFIG" == true ]]; then
# Overwrite the configuration, either from a previous run of this script or because user request it for the currently active config
sed -i '/^AuthorizedKeysCommand /s/^/#/' "$active_config"
sed -i '/^AuthorizedKeysCommandUser /s/^/#/' "$active_config"
echo "$auth_key_cmd" >> "$active_config"
echo "$auth_key_user" >> "$active_config"
{
echo "$auth_key_cmd"
echo "$auth_key_user"
}>> "$active_config"
elif [[ "$(basename "$active_config")" =~ ^0+[^0-9]+ ]]; then
# The active config starts with all zeros and is therefore the one with the
# highest priority. We cannot add a new file with even higher priority.
Expand All @@ -684,8 +686,10 @@ configure_openssh_server() {
# The directives in 'sshd_config' are active
sed -i '/^AuthorizedKeysCommand /s/^/#/' "$sshd_config"
sed -i '/^AuthorizedKeysCommandUser /s/^/#/' "$sshd_config"
echo "$auth_key_cmd" >> "$sshd_config"
echo "$auth_key_user" >> "$sshd_config"
{
echo "$auth_key_cmd"
echo "$auth_key_user"
}>> "$sshd_config"
fi
}

Expand Down
Loading