우분투 자동 업데이트: unattended-upgrades로 보안 패치 자동화
우분투 자동 업데이트는 unattended-upgrades 패키지가 담당하며, 하루 한 번 보안 업데이트를 스스로 내려받아 설치합니다. Ubuntu Server에서는 기본으로 켜져 있지만 직접 확인하는 것이 좋습니다. /etc/apt/apt.conf.d/20auto-upgrades의 두 설정이 모두 "1"이어야 하고, sudo unattended-upgrade -v --dry-run을 실행하면 보안 저장소(origin) 목록이 보여야 합니다. 이렇게 해 두면 OpenSSL, OpenSSH, 커널 패치가 서버에 접속하지 않아도 적용됩니다.
이 가이드에서는 활성화, 재부팅, 제외 패키지, 로그, "could not get lock" 오류, 그리고 자동 업데이트를 끄는 방법을 다룹니다. 명령어는 24.04 LTS 기준 Ubuntu Server 공식 문서를 따르며, Debian 12 섹션도 따로 있습니다.
자동 업데이트가 켜져 있는지 확인
apt list --installed 2>/dev/null | grep unattended-upgrades
cat /etc/apt/apt.conf.d/20auto-upgrades
정상이라면 다음과 같이 나옵니다.
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
"1"은 매일이라는 뜻입니다. 실제 작업은 systemd 타이머가 실행합니다.
systemctl list-timers 'apt-daily*'
apt-daily.timer는 패키지 목록을 새로 고치고, apt-daily-upgrade.timer는 업데이트를 설치합니다.
Ubuntu 24.04에서 우분투 자동 업데이트 켜기
패키지나 20auto-upgrades 파일이 없다면 다음을 실행하세요.
sudo apt update
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades # answer Yes; writes 20auto-upgrades
아무것도 바꾸지 않고 무엇이 설치될지 미리 확인하려면 다음 명령어를 씁니다.
sudo unattended-upgrade -v --dry-run
업데이트 대상: Allowed-Origins
업데이트 소스는 /etc/apt/apt.conf.d/50unattended-upgrades에 있습니다. 우분투 기본값은 보안 업데이트만입니다.
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}ESMApps:${distro_codename}-apps-security";
"${distro_id}ESM:${distro_codename}-infra-security";
// "${distro_id}:${distro_codename}-updates";
};
-updates는 주석 처리된 상태로 둡니다. 서버에는 합리적인 기본값입니다. 보안 수정은 자동으로 들어가고, 일반 업데이트는 우분투 서버 업데이트 방법에 설명한 대로 원하는 때에 직접 진행합니다.
자주 빠지는 함정: 서드파티 저장소는 대상이 아닙니다. download.docker.com의 Docker, NodeSource의 Node.js, PPA는 Allowed-Origins에 없어서 unattended-upgrades가 건너뜁니다. 직접 업데이트하거나 해당 Origin을 목록에 추가하세요. Origin 값은 /var/lib/apt/lists/ 아래 저장소의 InRelease 파일에서 찾을 수 있습니다.
재부팅, 정리, 제외 패키지
변경 사항은 기본 파일 다음에 읽히는 별도 파일에 두세요. 그러면 패키지 업그레이드 때 수정된 설정 파일을 어떻게 할지 묻지 않습니다.
sudo tee /etc/apt/apt.conf.d/52unattended-upgrades-local > /dev/null <<'EOF'
// reboot at 04:00 server time if a kernel update requires it
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";
// remove dependencies that are no longer needed
Unattended-Upgrade::Remove-Unused-Dependencies "true";
// never touch these packages
Unattended-Upgrade::Package-Blacklist {
"postgresql-";
};
EOF
| 옵션 | 기본값 | 언제 바꾸나 |
|---|---|---|
Automatic-Reboot |
false |
밤에 1분 정도 멈춰도 괜찮다면 켜기 (봇, n8n) |
Automatic-Reboot-Time |
now |
서버 시간대 기준으로 한가한 시각 지정 |
Automatic-Reboot-WithUsers |
true |
누군가 로그인해 있을 때 재부팅을 건너뛰려면 false |
Package-Blacklist |
비어 있음 | 데이터베이스 등 직접 업그레이드할 패키지 |
--dry-run을 다시 실행해 확인하세요. 자동 재부팅을 켜지 않았다면 커널 업데이트 후 /var/run/reboot-required 파일이 생기는지 살펴보세요.
unattended-upgrades 로그
sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log
sudo less /var/log/unattended-upgrades/unattended-upgrades-dpkg.log
첫 번째 파일에는 설치된 패키지와 오류가, 두 번째 파일에는 dpkg 전체 출력이 기록됩니다.
멈춤 현상: Could not get lock
새 서버가 부팅된 직후에는 apt install이 Could not get lock /var/lib/dpkg/lock-frontend 오류로 실패하는 경우가 많습니다. unattended-upgrades가 첫 번째 패치 묶음을 적용하는 중이기 때문입니다. 확인한 뒤 몇 분 기다리세요.
ps aux | grep -i unattended
설치 도중에 lock 파일을 지우거나 프로세스를 강제 종료하지 마세요. dpkg가 반쯤 설정된 상태로 남을 수 있습니다. 30분 넘게 정말 멈춰 있다면 위의 로그를 확인하세요.
우분투 자동 업데이트 끄기
sudo dpkg-reconfigure unattended-upgrades # answer No
또는 20auto-upgrades의 두 값을 "0"으로 바꾸세요. 타이머까지 완전히 멈추려면 sudo systemctl disable --now apt-daily.timer apt-daily-upgrade.timer를 실행합니다. 정해진 일정에 따라 직접 패치하는 경우에만 끄세요.
Debian 12
최소 설치한 Debian에는 패키지가 없을 수 있습니다. apt list --installed | grep unattended로 확인하고 필요하면 설치하세요.
sudo apt install unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgrades
Debian은 같은 50unattended-upgrades 파일에서 Unattended-Upgrade::Origins-Pattern을 씁니다. 기본값으로 보안 업데이트(label=Debian-Security)와 stable 포인트 릴리스 수정(label=Debian, 예: 12.12에서 12.13으로)을 설치하며, -updates는 주석 처리되어 있습니다. 참고로 2026년 7월 11일부터 Debian 12 보안 수정은 Debian LTS 팀이 제공합니다(2028년 6월 30일까지). 같은 bookworm-security 스위트로 들어오므로 바꿀 설정은 없습니다.
자동 업데이트와 함께 갖출 안전장치
자동 업데이트는 알려진 취약점을 막아 주지만 UFW 방화벽, 키 전용 SSH 로그인, 최소한의 열린 포트를 대신하지는 못합니다.
연습용으로 새 서버를 만든다면 s1-1 요금제(vCPU 1개, 메모리 1GB, NVMe 15GB, 월 $4.49)로 충분합니다. unattended-upgrades는 리소스를 거의 쓰지 않습니다. 시간 단위 요금으로 1시간 테스트하면 약 $0.030750이고, 설치비는 $0입니다. 삭제하면 사용하지 않은 금액은 잔액으로 돌아옵니다. 요금제는 요금 페이지에서 확인하세요.
큰 규모의 수동 업그레이드 전에는 스냅샷(0x.cloud에서 $0.99/월)을 만들어 두세요. 몇 분 만에 되돌릴 수 있습니다. 또는 에이전트에게 설정을 모두 맡기세요.
내 0x.cloud 서버에 접속해 줘(MCP run_command 도구 또는 SSH 사용). unattended-upgrades가 설치되어 있는지, /etc/apt/apt.conf.d/20auto-upgrades 내용이 어떤지 확인하고, 꺼져 있으면 켜 줘. 서버 시간 기준 04:00 자동 재부팅을 설정한 /etc/apt/apt.conf.d/52unattended-upgrades-local 파일을 만들고, unattended-upgrade -v --dry-run을 실행해서 결과를 보여 줘.
FAQ
우분투에서 unattended-upgrades는 기본으로 켜져 있나요? Ubuntu Server에는 패키지가 기본 설치되어 있고 하루 한 번 보안 업데이트를 적용합니다. /etc/apt/apt.conf.d/20auto-upgrades의 두 줄이 모두 "1"인지 확인하세요.
unattended-upgrades가 서버를 재부팅하나요? 기본값으로는 하지 않습니다. Automatic-Reboot가 false입니다. 재부팅이 필요한 업데이트가 설치되면 /var/run/reboot-required 파일이 생깁니다. 정해진 시각에 자동 재부팅하도록 켤 수 있습니다.
우분투 자동 업데이트는 어떻게 끄나요? /etc/apt/apt.conf.d/20auto-upgrades의 두 값을 "0"으로 바꾸거나, sudo dpkg-reconfigure unattended-upgrades를 실행하고 No를 선택하세요. 정해진 일정에 따라 직접 패치하는 경우에만 끄세요.
업데이트 후 서버가 고장 나면 어떻게 하나요? 스냅샷(0x.cloud에서 $0.99/월)으로 되돌리거나 OS를 $0에 재설치하세요.