본문 바로가기

리눅스

[draft] 우분투 20.04 서버 기본 설정

우분투 20.04 서버 기본 설정

테스트 환경

운영체제 정보

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
$ getconf LONG_BIT
64

1. 기본 에디터 변경(nano → vim)

우분투 기본 CLI 편집기는 nano입니다.

기본 에디터 설정 변경

sudo update-alternatives --config editor
There are 4 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
  3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    15        manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in manual mode
  • 3을 선택하면 vim.basic이 기본 에디터로 설정됩니다.

2. CLI 환경에서 네트워크 고정 IP 설정(netplan)

우분투 서버는 netplan을 사용하여 네트워크를 관리합니다.

네트워크 인터페이스 확인

ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
...
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
...

netplan 설정 파일 수정(00-installer-config.yaml)

sudo vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      addresses:
      - 192.168.100.10/24
      gateway4: 192.168.100.1
      nameservers:
        addresses:
        - 8.8.8.8

  version: 2

설정 적용

sudo netplan apply

네트워크를 재기동하지 않아도 즉시 적용됩니다.

3. sudo 패스워드 없이 명령 실행하기

특정 사용자에게 sudo 명령을 암호 없이 실행할 수 있도록 설정할 수 있습니다.

⚠ 주의: 잘못 설정하면 시스템 보안이 크게 낮아집니다.
운영 환경에서는 최소 권한 사용자에게만 적용하는 것을 권장합니다.

visudo로 안전하게 편집

sudo visudo
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo           ALL=(ALL:ALL) ALL
user1           ALL=(ALL:ALL) ALL
user2           ALL=NOPASSWD: ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

echo로 한 줄 추가

echo 'user2 ALL=NOPASSWD: ALL' | sudo tee -a /etc/sudoers

사용 예시

echo 'user1 ALL=(ALL:ALL) ALL' | sudo tee -a /etc/sudoers
$ sudo su -
[sudo] password for user1:
root@linux:~#
echo 'user2 ALL=NOPASSWD: ALL' | sudo tee -a /etc/sudoers
$ sudo su -
root@linux:~#

4. Hostname 설정

현재 hostname 확인

hostnamectl

hostname 변경

sudo hostnamectl set-hostname myserver

/etc/hosts도 함께 수정

sudo vim /etc/hosts
127.0.1.1   myserver

5. Timezone 설정

현재 시간대 확인

timedatectl

시간대 목록 검색

timedatectl list-timezones | grep -i seoul

시간대 변경

sudo timedatectl set-timezone Asia/Seoul

6. Locale 설정

한국어 환경을 원하면 ko_KR.UTF-8 locale을 생성해야 합니다.

현재 Locale 확인

locale

Locale 생성

sudo locale-gen ko_KR.UTF-8

기본 Locale 설정

sudo update-locale LANG=ko_KR.UTF-8

logout 또는 재부팅 후 적용됩니다.

7. 방화벽 설정 (UFW 비활성화)

UFW 상태 확인

sudo ufw status

UFW 비활성화

sudo ufw disable

완전 초기화(옵션)

sudo ufw reset