Practical Config Management
Configuration Management Strategies
graph TD
A[Config Management] --> B[Backup]
A --> C[Version Control]
A --> D[Automation]
A --> E[Security]
Key Management Approaches
Strategy |
Description |
Tools |
Backup |
Preserve original configurations |
cp, rsync |
Version Control |
Track configuration changes |
Git |
Templating |
Standardize configuration |
Ansible, Puppet |
Automation |
Manage configurations programmatically |
Shell scripts |
Backup Configuration Files
Safe Modification Techniques
## Create backup before modification
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
## Use timestamp for versioning
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.$(date +"%Y%m%d")
Version Control with Git
Managing Configuration Repositories
## Initialize git repository for configs
mkdir ~/system-configs
cd ~/system-configs
git init
## Track important configuration files
git add /etc/ssh/sshd_config
git add ~/.bashrc
git commit -m "Initial system configuration"
Configuration Templating
Using Ansible for Configuration Management
- hosts: webservers
tasks:
- name: Configure nginx
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
Automation Scripts
Shell Script for Config Management
#!/bin/bash
## Simple configuration backup script
BACKUP_DIR="/var/backups/configs"
CONFIG_FILES=(
"/etc/ssh/sshd_config"
"/etc/nginx/nginx.conf"
"/etc/resolv.conf"
)
## Create backup directory
mkdir -p $BACKUP_DIR
## Backup configurations
for file in "${CONFIG_FILES[@]}"; do
cp $file $BACKUP_DIR/$(basename $file).$(date +"%Y%m%d")
done
Security Best Practices
graph LR
A[Config Security] --> B[Permissions]
A --> C[Encryption]
A --> D[Access Control]
A --> E[Auditing]
Securing Configuration Files
## Set restrictive permissions
chmod 600 /etc/ssh/sshd_config
## Verify file permissions
ls -l /etc/ssh/sshd_config
LabEx Recommendation
In LabEx environments, practice configuration management techniques in controlled, safe sandboxes to build practical skills.
Tool |
Purpose |
Features |
Ansible |
Configuration management |
Agentless, multi-platform |
Puppet |
Infrastructure automation |
Declarative language |
Chef |
System configuration |
Ruby-based |
Monitoring Configuration Changes
## Use auditd to track configuration modifications
auditctl -w /etc/ssh/sshd_config -p wa
## View recent configuration changes
last -f /var/log/wtmp