Modify : function service
This commit is contained in:
parent
8b8626d035
commit
c3576e785b
@ -159,7 +159,14 @@ is_package_installed() {
|
||||
|
||||
# Function to check if a service is running
|
||||
service() {
|
||||
systemctl $1 $2
|
||||
systemctl $1 $2 || handle_error "test"
|
||||
|
||||
log_message "SUCCESS" "Action : $1 for service : $2 successfully"
|
||||
}
|
||||
|
||||
# Fonction pour la gestion des erreurs
|
||||
handle_error() {
|
||||
log "${RED} - Erreur : $1 ${NOCOLOR}"
|
||||
|
||||
exit 1
|
||||
}
|
@ -98,16 +98,16 @@ EOF
|
||||
|
||||
# Function to harden SSH configuration
|
||||
harden_ssh_config() {
|
||||
local ssh_config="/etc/ssh/sshd_config"
|
||||
local ssh_config_backup="$BACKUP_DIR/etc/ssh/sshd_config"
|
||||
local SSH_CONFIG="/etc/ssh/sshd_config"
|
||||
local SSH_CONFIG_BACKUP="$BACKUP_DIR/etc/ssh/sshd_config"
|
||||
|
||||
# Backup current SSH configuration
|
||||
backup_file "$ssh_config"
|
||||
backup_file "$SSH_CONFIG"
|
||||
|
||||
log_message "INFO" "Hardening SSH configuration"
|
||||
|
||||
# Create a new SSH configuration with hardened settings
|
||||
cat > "$ssh_config" << EOF
|
||||
cat > "$SSH_CONFIG" << EOF
|
||||
# SSH Server Configuration
|
||||
# Hardened configuration from security script
|
||||
|
||||
@ -164,7 +164,7 @@ EOF
|
||||
else
|
||||
log_message "ERROR" "Failed to restart SSH service"
|
||||
# Revert to backup
|
||||
cp "$ssh_config_backup" "$ssh_config"
|
||||
cp "$SSH_CONFIG_BACKUP" "$SSH_CONFIG"
|
||||
service restart sshd
|
||||
|
||||
log_message "WARNING" "Reverted to original SSH configuration"
|
||||
|
Loading…
x
Reference in New Issue
Block a user