mirror of
https://github.com/elAgala/server-initializer.git
synced 2026-02-14 05:06:18 +00:00
fix: allow multiple AllowUsers on sshd_config file
This commit is contained in:
@@ -26,9 +26,11 @@ function config_ssh() {
|
||||
# Create SSH configuration file instead of modifying main sshd_config
|
||||
config_file="/etc/ssh/sshd_config.d/server-initializer.conf"
|
||||
|
||||
echo "[ SSH ]: Creating SSH configuration file"
|
||||
echo "[ SSH ]: Configuring SSH settings"
|
||||
sudo mkdir -p /etc/ssh/sshd_config.d
|
||||
|
||||
# Check if config file exists
|
||||
if [ ! -f "$config_file" ]; then
|
||||
# Create the configuration file with security settings
|
||||
sudo tee "$config_file" >/dev/null <<EOF
|
||||
# Server Initializer SSH Configuration
|
||||
@@ -45,8 +47,18 @@ UsePAM no
|
||||
# Only allow specific users
|
||||
AllowUsers $username
|
||||
EOF
|
||||
|
||||
echo "[ SSH ]: SSH configuration file created at $config_file"
|
||||
else
|
||||
# File exists, check if user is already in AllowUsers
|
||||
if ! sudo grep -q "AllowUsers.*$username" "$config_file"; then
|
||||
# Add user to existing AllowUsers line
|
||||
sudo sed -i "s/^AllowUsers.*/& $username/" "$config_file"
|
||||
echo "[ SSH ]: User $username added to existing AllowUsers"
|
||||
else
|
||||
echo "[ SSH ]: User $username already in AllowUsers"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "[ SSH ]: Root login disabled"
|
||||
echo "[ SSH ]: Password authentication disabled"
|
||||
echo "[ SSH ]: User $username added to allowed users"
|
||||
|
||||
Reference in New Issue
Block a user