우분투 서버 보안 자동 업데이트 및 업데이트 메일 통보 방법

Updated on 2020-07-12 by

사이트 운영이든 프로그램이나 앱 사용 시 보안 업데이트는 반드시 적용해야합니다. 우부투 서버 운영 시 우분투 서버 보안 자동 업데이트 및 업그레이드 방법 및 이 결과 메일 통보 방법에 대해 살펴봅니다.

서버 보안 업데이트의 필요성

인터넷이 발전하면서 인터넷 사용자가 증가하고, 인터넷을 이용한 비지니스가 크게 융성해지고 있기 때문에 이에 편승한 해킹 위험이 크게 증가하고 있습니다.

테스트 또는 교육용으로 해킹하는 경우도 있겠지만 대부분은 무엇인가 이득을 노리는경우가 많죠. 그리고 이는 사용자가 많아질수록, 관련된 비지니스가 커질수록 시도는 증가하기 마련입니다.

이렇게 해킹 위험이 증가하고 프로그램등이 빠르게 변하면서 그동안 생각하지 못했던 위약점들이 나타나고 예전에 몰랐던 취약점을 새롭게 발견하기도 합니다.

그렇기 때문에 이러한 취약점들은 보완하는 보안 업데이트는 굉장히 자두 이루어집니다. 서버나 사이트를 안전하게 지키려면 이런 보안 업데이트를 바로바로 실행해 주는 것이 필요합니다.

실제로 해깅등은 이러한 업데이트를 무시하고 방치된 서버나 사이트에서 주로 일어나고 있다는 것도 보안 업데이트 및 업그레이드의 중요성을 웅변해 준다고 할 수 있습니다.

그리고 이런 업데이트 및 업그레이드 시 반드시 사전 백업이 필수적입이죠. 어떤 일이 닐어날지 모르기 때문이죠.

그런데 전업으로 서버 운영을 하는 담당자가 있다면 매일 일정 시간에 안정적을 상황을 파악해 업데이트 및 업그레이드를 진행 후 문제가 없는지 확인할 수 있지만.. 대부분의 경우는 그렇지 않고 서버에 접속할 여유가 적습니다.

그렇기 때문에 최소한 보안 업데이트 및 업그레이드는 자동으로 이루어지고 이를 메일로 통보받는 것이 필요합니다. 그리고 이러한 업데이트는 가능하면 사용하지 않는 새벽 시간에 이루어 지도록 설정하는 것이 필요할 것입니다.

  • 보안 업데이트 전에 사전 백업
  • 보안 업데이트는 자동 실행
  • 보안 업데이트로 시스템 부팅이 필요한 경우, 시스템 부팅은 사용자가 적은 새벽 시간에 진행
  • 보안 업데이트 내용은 메일로 송부

우분투 서버 보안 자동 업데이트 방법

여기서는 운분투 서버 운영 시 보안 자동 업데이트 방법에 대해서 살펴봅니다.

어느 운영체제나 마찬가지겠지만 리눅도도 필요가 있으면 이를 지원하는 다양한 방법들을 제공되고 있습니다.

우분투 리눅스에서는 보안 업데이트가 발생 시 관련 내용만 업데이트하도록 하는 unattended-upgrades라는 프로그램이 있습니다. 오늘은 이를 이용해 우분투 서버 자동 업데이트 방법에 대해서 알아보도록 하겠습니다.

unattended-upgrades 프로그램 설치

먼저 서버 업데이트 및 업그레이드를 통해서 최신 상태로 만듭니다.

sudo apt update && sudo apt upgradeCode language: PHP (php)

다음으로는 위에서 이야기한 unattended-upgrades 프로그램을 설치합니다. 이는 아래 명령을 사용합니다. 별다른 메일 프로그램이 설치되어 있지 않으면 postfix를 설치합니다.

sudo apt install unattended-upgrades apt-listchanges bsd-mailxCode language: PHP (php)

지메일 릴레이 서비를 이용해 우분투 서버에서 메일 발송 시스템 구축에 대해서는 아래 글을 참조하시기 바랍니다.

설치를 시작하다가 중간에 이 프로그램이 서버 용량을 사용할 것인데 설치를 진행할 것인지 질문합니다. 사용하겠다는 용량은 기껏 588K 정도 되기 때문에 부담없이 Y를 누릅니다.

# sudo apt install unattended-upgrades apt-listchanges bsd-mailx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
unattended-upgrades is already the newest version (2.3).
The following packages were automatically installed and are no longer required:
  lockfile-progs sendmail-base sendmail-cf sensible-mda
Use 'sudo apt autoremove' to remove them.
Suggested packages:
  www-browser x-terminal-emulator
The following NEW packages will be installed:
  apt-listchanges bsd-mailx
0 upgraded, 2 newly installed, 0 to remove and 31 not upgraded.
Need to get 150 kB of archives.
After this operation, 588 kB of additional disk space will be used.
Do you want to continue? [Y/n] YCode language: PHP (php)

설정 보안 업체이트 허용

다음으로는 강제 보안 업데이트를 허용합니다. 아래와 같은 명령을 사용하면 중간에 unattended-upgrades를 사용하도록 설정할지 질문하는 팝업이 뜹니다.

sudo dpkg-reconfigure -plow unattended-upgradesCode language: PHP (php)

Applying updates on a frequent basis is an important part of keeping systems secure. By default, updates need to be applied manually using package management tools. Alternatively, you can choose to have this system automatically download and install important updates.Automatically download and install stable updates?  

오늘 목적이 바로 그것이므로 키보드를 왼쪽으로 옮겨 Yes를 선택합니다.

우분투 보안 자동 업데이트 설치 옵션, unattended-upgrades 사용 허용

unattended-upgrades 세부 옵션

이제 unattended-upgrades 세부 옵션을 정합니다. 이는 아래 파일을 편집합니다.

nano /etc/apt/apt.conf.d/50unattended-upgradesCode language: PHP (php)

저는 아래 몇가지를 조정했습니다.

  1. 업데이트 결과를 받을 이메일 주소 설정(73번째 줄)
  2. 보안 업데이는 종종 우분투 서버 리부팅이 필요할 경우가 있습니다. 이 경우 관리자 확인없이 리부팅 허용(93번째 줄)
  3. 서버 리부팅이 필요한 경우 리부팅 시간을 위험이 적은 새벽 시간으로 설정(102번째 줄)

아래는 제가 설정한 내용입니다. 설명 등 군더더기 내용을 그대로 두었습니다.

// Automatically upgrade packages from these (origin:archive) pairs
//
// Note that in Ubuntu security updates may pull in new dependencies
// from non-security sources (e.g. chromium). By allowing the release
// pocket these get automatically pulled in.
Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}";
        "${distro_id}:${distro_codename}-security";
        // Extended Security Maintenance; doesn't necessarily exist for
        // every release and this system may not have it installed, but if
        // available, the policy for updates is such that unattended-upgrades
        // should also install from here by default.
        "${distro_id}ESMApps:${distro_codename}-apps-security";
        "${distro_id}ESM:${distro_codename}-infra-security";
//      "${distro_id}:${distro_codename}-updates";
//      "${distro_id}:${distro_codename}-proposed";
//      "${distro_id}:${distro_codename}-backports";
};

// Python regular expressions, matching packages to exclude from upgrading
Unattended-Upgrade::Package-Blacklist {
    // The following matches all packages starting with linux-
//  "linux-";

    // Use $ to explicitely define the end of a package name. Without
    // the $, "libc6" would match all of them.
//  "libc6$";
//  "libc6-dev$";
//  "libc6-i686$";

    // Special characters need escaping
//  "libstdc\+\+6$";

    // The following matches packages like xen-system-amd64, xen-utils-4.1,
    // xenstore-utils and libxenstore3.0
//  "(lib)?xen(store)?";

    // For more information about Python regular expressions, see
    // https://docs.python.org/3/howto/regex.html
};

// This option controls whether the development release of Ubuntu will be
// upgraded automatically. Valid values are "true", "false", and "auto".
Unattended-Upgrade::DevRelease "auto";

// This option allows you to control if on a unclean dpkg exit
// unattended-upgrades will automatically run
//   dpkg --force-confold --configure -a
// The default is true, to ensure updates keep getting installed
//Unattended-Upgrade::AutoFixInterruptedDpkg "true";

// Split the upgrade into the smallest possible chunks so that
// they can be interrupted with SIGTERM. This makes the upgrade
// a bit slower but it has the benefit that shutdown while a upgrade
// is running is possible (with a small delay)
//Unattended-Upgrade::MinimalSteps "true";

// Install all updates when the machine is shutting down
// instead of doing it in the background while the machine is running.
// This will (obviously) make shutdown slower.
// Unattended-upgrades increases logind's InhibitDelayMaxSec to 30s.
// This allows more time for unattended-upgrades to shut down gracefully
// or even install a few packages in InstallOnShutdown mode, but is still a
// big step back from the 30 minutes allowed for InstallOnShutdown previously.
// Users enabling InstallOnShutdown mode are advised to increase
// InhibitDelayMaxSec even further, possibly to 30 minutes.
//Unattended-Upgrade::InstallOnShutdown "false";

// Send email to this address for problems or packages upgrades
// If empty or unset then no email is sent, make sure that you
// have a working mail setup on your system. A package that provides
// 'mailx' must be installed. E.g. "user@example.com"
Unattended-Upgrade::Mail "업데이트 상황을 받아 볼 이메일 주소";

// Set this value to one of:
//    "always", "only-on-error" or "on-change"
// If this is not set, then any legacy MailOnlyOnError (boolean) value
// is used to chose between "only-on-error" and "on-change"

// Remove unused automatically installed kernel-related packages
// (kernel images, kernel headers and kernel version locked tools).
//Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";

// Do automatic removal of newly unused dependencies after the upgrade
//Unattended-Upgrade::Remove-New-Unused-Dependencies "true";

// Do automatic removal of unused packages after the upgrade
// (equivalent to apt-get autoremove)
//Unattended-Upgrade::Remove-Unused-Dependencies "false";

// Automatically reboot *WITHOUT CONFIRMATION* if
//  the file /var/run/reboot-required is found after the upgrade
Unattended-Upgrade::Automatic-Reboot "true";

// Automatically reboot even if there are users currently logged in
// when Unattended-Upgrade::Automatic-Reboot is set to true
//Unattended-Upgrade::Automatic-Reboot-WithUsers "true";

// If automatic reboot is enabled and needed, reboot at the specific
// time instead of immediately
//  Default: "now"
Unattended-Upgrade::Automatic-Reboot-Time "03:00";

// Use apt bandwidth limit feature, this example limits the download
// speed to 70kb/sec
//Acquire::http::Dl-Limit "70";

// Enable logging to syslog. Default is False
// Unattended-Upgrade::SyslogEnable "false";

// Specify syslog facility. Default is daemon
// Unattended-Upgrade::SyslogFacility "daemon";

// Download and install upgrades only on AC power
// (i.e. skip or gracefully stop updates on battery)
// Unattended-Upgrade::OnlyOnACPower "true";

// Download and install upgrades only on non-metered connection
// (i.e. skip or gracefully stop updates on a metered connection)
// Unattended-Upgrade::Skip-Updates-On-Metered-Connections "true";

// Verbose logging
// Unattended-Upgrade::Verbose "false";

// Print debugging information both in unattended-upgrades and
// in unattended-upgrade-shutdown
// Unattended-Upgrade::Debug "false";

// Allow package downgrade if Pin-Priority exceeds 1000
// Unattended-Upgrade::Allow-downgrade "false";Code language: PHP (php)

APT 변경 사항 발생 시 받을 메일 주소 변경

다음으로는 listchanges.conf를 편집해 APT 변경 사항 발생 시 받아볼 이메일 주소를 root에서 설정합니다.

 nano /etc/apt/listchanges.confCode language: PHP (php)

여기 설정은 매우 간단한데요. 아래와 같은 항목으로 구성되어 있고 이중 메일 주소를 설정하면 됩니다.

[apt]
frontend=pager
which=news
email_address=업데이트 상황을 받아 볼 이메일 주소
email_format=text
confirm=false
headers=false
reverse=false
save_seen=/var/lib/apt/listchanges.dbCode language: PHP (php)

테스트

아래와 같은 명령을 사용해 제대로 작동하는지 확인해 봅니다.

sudo unattended-upgrades --dry-runCode language: PHP (php)

그러면 아래와 같은 형식으로 변경된 내용을 출력해 줍니다. 물론 근래에 업데이트 및 업그레이드를 통해서 업데이트할 내용이 없다면 아무런 메세지를 보내지 않습니다.

# sudo unattended-upgrades --dry-run
apt-listchanges: Reading changelogs...
apt-listchanges: Reading changelogs...
/usr/bin/dpkg --status-fd 10 --no-triggers --unpack --auto-deconfigure /var/cache/apt/archives/snmp_5.8+dfsg-2ubuntu2.1_amd64.deb /var/cache/apt/archives/libsnmp35_5.8+dfsg-2ubuntu2.1_amd64.deb 
/usr/bin/dpkg --status-fd 10 --configure --pending 
apt-listchanges: Reading changelogs...
apt-listchanges: Reading changelogs...
/usr/bin/dpkg --status-fd 10 --no-triggers --unpack --auto-deconfigure /var/cache/apt/archives/glib-networking-common_2.64.2-1ubuntu0.1_all.deb /var/cache/apt/archives/glib-networking_2.64.2-1ubuntu0.1_amd64.deb /var/cache/apt/archives/glib-networking-services_2.64.2-1ubuntu0.1_amd64.deb 
/usr/bin/dpkg --status-fd 10 --configure --pending 
apt-listchanges: Reading changelogs...
apt-listchanges: Reading changelogs...
/usr/bin/dpkg --status-fd 10 --no-triggers --unpack --auto-deconfigure /var/cache/apt/archives/libsnmp-base_5.8+dfsg-2ubuntu2.1_all.deb 
/usr/bin/dpkg --status-fd 10 --configure --pending 
apt-listchanges: Reading changelogs...
apt-listchanges: Reading changelogs...
/usr/bin/dpkg --status-fd 10 --no-triggers --unpack --auto-deconfigure /var/cache/apt/archives/libseccomp2_2.4.3-1ubuntu3.20.04.2_amd64.deb 
/usr/bin/dpkg --status-fd 10 --no-triggers --configure libseccomp2:amd64 
/usr/bin/dpkg --status-fd 10 --configure --pending 
apt-listchanges: Reading changelogs...
apt-listchanges: Reading changelogs...
/usr/bin/dpkg --status-fd 10 --no-triggers --unpack --auto-deconfigure --recursive /tmp/apt-dpkg-install-m8fgGO 
/usr/bin/dpkg --status-fd 10 --configure --pending 
apt-listchanges: Reading changelogs...
apt-listchanges: Reading changelogs...
/usr/bin/dpkg --status-fd 10 --no-triggers --unpack --auto-deconfigure /var/cache/apt/archives/linux-libc-dev_5.4.0-40.44_amd64.deb 
/usr/bin/dpkg --status-fd 10 --configure --pending Code language: PHP (php)

참고

이는 우분투 서버 보안 자동 업데이트 방법은 아래 글을 참조해 테스트 결과를 기반으로 재정리 했습니다.

아래 참고글은 우분투 18.04를 기준으로 했지만 저는 우분투 20.04에서 테스트해 보았습니다.

How to set up automatic updates for Ubuntu Linux 18.04

그리고 메일을 실행시마다 보내는 것은 아니고 문제가 발생하거나 패키지 업그레이드(problems or packages upgrades)가 발생시에만 보내게 됩니다.

새롭게 뉴스레터를 시작했습니다.

1️⃣ 주식 등 투자 정보 : 기업 분석, IB 투자의견 등 투자 관련 내용
..... 테슬라 실적 및 IB들의의 테슬라 투자의견
2️⃣ 사례 및 트렌드 : 사례연구와 트렌드 관련 괜찮은 내용
.....유튜브와 경쟁대신 구독 전환한 비디오 플래폼 비메오 사례

서울에 생긴 Vultr 서버 100$ 프로모션

안녕하세요?
새로운 사이트 구축을 위한 신규 서버를 고민하신다면 , 서울 리젼이 생겨 더욱 빨라진 Vultr 서버를 Vultr 100$ 프로모션으로 이용해 보세요.

아래 프로모션 코드 링크를 통해 Vultr에서 서버 구축 후 1달 이상 사용 및 $25이상 결제 時 추가 100$을 주는 프로모션입니다.

Vultr는 서울에도 리젼이 있어 매우 빠르고, 아마존 웹 서비스(AWS)보다 성능이 높으며 가장 가성비가 뛰어납니다.

거기다 사용자 UI도 좋고, 15개까지 스냅샷을 무료로 제공하기 때문에 관리하기 좋습니다. 그리고 지금 100$ 프로모션처럼 가격적인 메리트도 있습니다.

우분투 20.04와 PHP 8 기반 워드프레스 설치 방법

가상 서버를 운영하고픈 勇者에게 전하는 가상 서버 운영 입문 노하우 – Vultr 가상서버호스팅(VPS)를 중심으로

워드프레스 최적화를 위한 18개월간의 고민, 그 노하우를 담다.

도쿄 리젼과 비교해 본 Vultr 서울 리젼 사용기

가성비가 뛰어난 Vultr 가상서버호스팅(클라우드호스팅,VPS) 사용기

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments