To enable auto updates in Ubuntu, you can follow these steps, which ensure that your system stays up to date without needing manual intervention. This script installs the unattended-upgrades package, configures it, and ensures that automatic updates are set up correctly.
nano enable_unattended_upgrades.sh
chmod +x enable_unattended_upgrades.sh
./enable_unattended_upgrades.sh
<--here is the script -->
#!/bin/bash
# Enable Unattended Upgrades Script for Ubuntu
# Function to install unattended-upgrades
install_unattended_upgrades() {
echo "Installing unattended-upgrades..."
sudo apt update
sudo apt install -y unattended-upgrades
}
# Function to configure unattended-upgrades
configure_unattended_upgrades() {
echo "Configuring unattended-upgrades..."
# Enable security updates
sudo sed -i 's,//Automatic installation of security updates,Automatic-Upgrade::Allowed-Origins {\n "${distro_id}:${distro_codename}-security";\n};,' /etc/apt/apt.conf.d/50unattended-upgrades
# Enable automatic updates checks
echo 'APT::Periodic::Update-Package-Lists "1";' | sudo tee /etc/apt/apt.conf.d/20auto-upgrades
echo 'APT::Periodic::Unattended-Upgrade "1";' | sudo tee -a /etc/apt/apt.conf.d/20auto-upgrades
}
# Function to verify installation
verify_installation() {
echo "Verifying unattended-upgrades installation..."
sudo unattended-upgrades --dry-run --debug
}
# Main execution
install_unattended_upgrades
configure_unattended_upgrades
verify_installation
echo "Unattended upgrades have been enabled successfully."
This script will install the necessary package, configure it for security updates, and verify that everything is set up correctly. After running it, your Ubuntu system will be configured to automatically receive updates
