리눅스 공부를 시작한겸 자격증이라는 목표를 두고 학습하는게 효율적일 것 같아서
RHCSA9 자격증 취득을 목표로 했다.
자격증 취득도 중요하지만 더 중요한건 리눅스에 대한 이해이기 때문에
각종 유튜브, 유데미 강의 등을 통해 기본을 익혔고, 이제 기출문제들을 정리하여 무한실습을 하려고 한다.
아래 정리한 문제들은 https://www.youtube.com/watch?v=_csC_cUpwh8&t=1056s 기반이고
다른 블로그들을 참고하여 내가 가장 잘 이해할 수 있도록 기출문제를 만들었다.
--------------------------------------------------- node 1 (Servera) ---------------------------------------------------
[ Q1 ] Configure TCP/IP and "hostname" as following (매우 중요)
IP ADDRESS = 172.25.250.11
NETMASK = 255.255.255.0
GATEWAY = 172.25.250.254
DNS = 172.25.250.254
HOST NAME = node1.domain250.example.com
# hostname 변경 & 확인
hostnamectl set-hostname node1.domain250.example.com
hostnamectl hostname
# 커넥션 정보 확인(name ex-enp0s3)
nmcli con show
# 설정
nmcli con modify enp0s3 autoconnect yes ipv4.method manual ipv4.address 172.25.250.11/24 ipv4.gateway 172.25.250.254 ipv4.dns 172.25.250.254
# connection 활성화 (up만해도 재구동 됨)
nmcli con up enp0s3
# 변경 잘 되었는지 확인
ip a
[ Q2 ] Configure your servera VM repository installed the packages ditribution is available via YUM: (매우 중요)
Base os url = http://content.example.com/rhel9.0/x86_64/dvd/BaseOS
App stream url = http://content.example.com/rhel9.0/x86_64/dvd/AppStream
# repo 생성(/etc/yum.repos.d 경로는 외우되 한번 직접 가보기 + 다른 repo 파일 있으면 참고 가능)
vi /etc/yum.repos.d/rhel9.repo
# 아래와 같이 입력(5yy->p 하면 편함)하고 저장
[BaseOS]
name=BaseOS
baseurl=http://content.example.com/rhel9.0/x86_64/dvd/BaseOS
enabled=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=http://content.example.com/rhel9.0/x86_64/dvd/AppStream
enabled=1
gpgcheck=0
# 캐시정리 및 확인(yum -> dnf 대체 가능)
cat /etc/yum.repos.d/rhel9.repo
yum clean all
yum repolist -v
[ Q3 ] SELINUX PORT
- In your system, httpd service has some files in /var/www/html (do not change or alter files)
- solve the problem, httpd service of your system having some issues, service is not running on port 82.
비표준 포트 82에서 실행 중인 웹 서버가 서비스 제공 시 문제를 겪고 있다. 다음 조건을 충족하도록 트러블슈팅을 하라 :
- 시스템의 웹 서버가 /var/www/html에 있는 모든 기존 HTML 파일을 제공할 수 있어야 한다. (참고: 기존 파일의 내용을 삭제하거나 수정하지 말 것)
- 웹 서버가 포트 82로 서비스가 되도록 하라
- 웹 서버가 시스템이 시작될 때 자동으로 시작되어야 한다.
# SELinux 상태 확인(default:1 - Enforcing)
getenforce
# 0으로 세팅
setenforce 0
# 포트 확인(82 없음)
semanage port -l | grep http_port_t
# 포트 추가
semanage port -a -t http_port_t -p tcp 82
# 포트 확인(82 있음)
semanage port -l | grep http_port_t
# 82 port Listen 설정(필요시 httpd 설치)
vi /etc/httpd/conf/httpd.conf
Listen 82 (vi에서 /80 후 아래에 삽입/저장)
#httpd 재시작 및 enable(시스템기동시 자동시작) 세팅
systemctl restart httpd
systemctl enable --now httpd
# 방화벽 추가 및 재시작(영구저장)
firewall-cmd --permanent --add-port=82/tcp
firewall-cmd --reload
# 다시 1로 세팅
setenforce 1
# SELinux 상태 확인(Enforcing 확인)
getenforce
# 검증
curl http://localhost:82
systemctl status httpd
[ Q4 ] Create User accounts with supplementary group
- create the group named "sysadms"
- create users named "natasha" and "harry", will be the supplementry group "sysadms"
- create a user named "sarah", should have non-interactive shell and it should be not the member of "sysadms"
- password for all users should be "trootent"
- "sysadms" group has access to user add in the server
- "harry" user has access to set password for users without asking sudo password
# sysadms라는 그룹 추가
groupadd sysadms
# 사용자 생성 및 부가그룹에 추가
useradd -G sysadms natasha
useradd -G sysadms harry
# non-interactive shell 계정 추가
useradd -s /sbin/nologin sarah
# 패스워드 "trootent" 로 지정
passwd natasha
passwd harry
passwd sarah
# useradd/passwd 경로 확인
which useradd(-> /usr/sbin/useradd)
which passwd(-> /usr/bin/passwd)
visudo
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL 밑에 내용 추가
%sysadms ALL=(ALL) NOPASSWD: ALL
harry ALL=(ALL) NOPASSWD: /usr/bin/passwd
# 확인
cat /etc/passwd
[ Q5 ] Create a collaborative Directory
- Create the Directory "/home/manager" with the following charactericstics
- Group ownership of "/home/manager" should go to "sysadms" group
- The directory should have full permission for all members of "sysadms" group but not to the other users except "root"
- Files created in future under "/home/manager" should get the same group ownership
# 디렉토리 생성
mkdir /home/manager
# 그룹 소유권 변경
chown :sysadms /home/manager
# 3. 권한 설정
chmod 2770 /home/manager
# 4. 검증
ls -ld /home/manager
touch /home/manager/testfile
ls -l /home/manager
[ Q6 ] Configure a cron job that runs every 2 minutes and executes: logger "EX200 in progress" as the user natasha.
# crond 서비스 상태 확인
systemctl status crond
# 필요시 패키지 설치
yum install -y cronie
# crond 서비스 자동+즉시 시작
systemctl enable --now crond
# natasha의 crontab 수정
crontab -e -u natasha
# 내용 추가하기
*/2 * * * * logger "EX200 in progress"
# 확인하기(logger로 남긴 메시지는 /var/log/messages 또는 /var/log/syslog 등에 기록됨)
# tail -f /var/log/messages -- 경로가 다른 듯 안나옴
journalctl | grep "EX200"
[ Q7 ] autofs를 설정하여 원격 사용자의 홈 디렉터리를 아래 요구대로 자동으로 마운트되독록 하세요.
- materials.example.com (172.25.254.254) 에는 NFS 공유 드렉토리 /rhome 있습니다. 이 파일 시스템에는 사용자 remoteuser1 대해 사전 구성된 홈 디렉터리가 포함됩니다.
- remoteuser1의 홈 디렉터리는 materials.example.com:/rhome/remoteuser1입니다.
- remoteuser1의 홈 디렉터리는 로컬의 /rhome 디렉토리 하위의 /rhome/remoteuser1로 자동으로 마운트 되어야 합니다.
- 홈 디렉터리는 사용자가 쓰기 가능해야 합니다.
- remoteuser1의 비밀번호는 flectrag입니다.
# 1. Autofs 설치 및 서비스 관리
dnf install -y autofs
systemctl enable --now autofs
systemctl status autofs
# 2. Autofs 구성
vi /etc/auto.master
# /misc /etc/auto.misc 주석처리후 아래 추가
/rhome /etc/auto.rhome
vi /etc/auto.rhome
# 추가(auto.rhome은 위에 매핑한대로 새로 생성되는 파일임)
remoteuser1 -fstype=nfs4,rw,sync materials.example.com:/rhome/remoteuser1
# 3. Autofs 서비스 재시작
systemctl restart autofs
# 4. 검증
ls /rhome/remoteuser1
touch /rhome/remoteuser1/testfile
ls -l /rhome/remoteuser1/testfile
[ Q8 ] /usr/local의 내용을 포함하는 tar 아카이브를 생성하고, 이를 bzip2로 압축하여 /root/backup.tar.bz2로 저장하세요.
유튜브 문제 - 영어지문연습(위 문제와 비슷한 유형)
Create a tar archive of "/etc/" Directory with .bzip2 extension.
Tar archive named "myetcbackup.tar" should be place in "/root/" Directory.
j : bzip2
J : xz
z : gzip
# tar: 파일을 묶거나 압축을 해제하는 데 사용되는 아카이브 유틸리티입니다.
# -c (create): 새로운 아카이브 파일을 생성하도록 지시합니다.
# -v (verbose): 처리되는 파일들을 자세히(verbose) 출력하여 진행 상황을 보여줍니다. 즉, 아카이브에 추가되는 파일 목록을 화면에 표시합니다.
# -j (bzip2): bzip2 압축 알고리즘을 사용하여 아카이브를 압축하도록 지시합니다. .bz2 확장자는 일반적으로 bzip2로 압축된 파일에 사용됩니다. (참고: -z는 gzip, -J는 xz 압축에 사용됩니다.)
# -f /root/backup.tar.bz2 (file): 생성될 아카이브 파일의 이름을 지정합니다.
# -f 옵션은 항상 마지막에 오고 그 뒤에 파일 이름이 와야 합니다.
tar -cvjf /root/backup.tar.bz2 /usr/local
# -t (list): 아카이브 파일의 내용을 나열하도록 지시합니다. 즉, 아카이브 내부에 어떤 파일과 디렉토리가 포함되어 있는지 보여줍니다.
# -v (verbose): 나열될 파일들의 자세한 정보를 출력합니다. 즉, 파일 소유자, 그룹, 크기, 생성 시간 등의 상세 정보를 보여줍니다. 이 옵션이 없으면 파일 이름만 나열됩니다.
# -f /root/backup.tar.bz2 (file): 내용을 나열할 대상 아카이브 파일의 이름을 지정합니다.
tar -tvf /root/backup.tar.bz2
[ Q9 ] Copy the file /etc/fstab to /var/tmp. Configure the permissions of /var/tmp/fstab so that:
- the file /var/tmp/fstab is owned by the root user
- the file /var/tmp/fstab belong to the group root
- the file /var/tmp/fstab should not be executable by anyone
- the user "natasha" is able to read and write /var/tmp/fstab
- the user "harry" can neither write nor read /var/tmp/fstab
- all other users (current or future) have the ability to read /var/tmp/fstab
# 1. 파일 복사
cp /etc/fstab /var/tmp/fstab
# 2. 기본 소유권 및 권한 설정
chown root:root /var/tmp/fstab
chmod 644 /var/tmp/fstab
# 3. ACL 설정
setfacl -m u:natasha:rw /var/tmp/fstab
setfacl -m u:harry:--- /var/tmp/fstab
setfacl -m o::r /var/tmp/fstab
# 4. 검증
ls -ld /var/tmp/fstab
getfacl /var/tmp/fstab
[ Q10 ] Configure NTP - Synchronize the of your system with the server "ntp.example.com"
유튜브 문제 - 영어지문연습(위 문제와 비슷한 유형)
Configure your system to synchronize the time from form "classroom.example.com".
# 1. Chrony 서비스 상태 확인 및 설치
systemctl status chronyd
yum install -y chrony
systemctl enable --now chronyd
# 2. NTP 서버 설정
vi /etc/chrony.conf
# 추가 또는 수정: 원래있으면 주석처리하고 추가
# pool 2.rhel.pool.ntp.org iburst 아래에
server ntp.example.com iburst
# 3. Chrony 서비스 재시작 및 확인
systemctl restart chronyd
chronyc sources
# 4. 시간 동기화 설정 및 확인
timedatectl set-ntp true
timedatectl
[ Q11 ] Find all files and directories which is created by a user "natasha" in to this system and copy it into a "/root/natashafiles" directory
# 1. 복사 대상 디렉터리 생성
# -p 옵션은 만약 없다면, 상위디렉토리까지 모두 생성해주는 것
mkdir -p /root/natashafiles
# 2. 사용자 natasha가 소유한 파일 및 디렉토리 검색 후 복사
# 시스템의 루트 디렉토리(/)부터 시작하여
# natasha라는 사용자(-user natasha)가 소유한
# 모든 파일(find /)을 찾아,
# 찾은 각 파일({})을 /root/natashafiles/ 디렉토리로
# 원본 파일의 속성(권한, 소유자, 타임스탬프 등)을 최대한 보존(-ap)하면서 복사(cp)하는 명령어
find / -user natasha -exec cp -ap {} /root/natashafiles/ \;
# 3. 복사된 파일 확인
ls -l /root/natashafiles
[ Q12 ] Find all strings "ich" from "/usr/share/dict/words" file and copy that strings in a /root/lines file.
# 1. 문자열 검색 및 결과 저장
grep ich /usr/share/dict/words > /root/lines
# 2. 결과 확인
cat /root/lines
[ Q13 ] Create a user "unilao" with UID "2334" with password as "souspolo"
# 1. 사용자 생성
useradd -u 2334 unilao
# 2. 비밀번호 설정
# 이렇게 해도 됨 -> echo "souspolo" | passwd --stdin unilao
passwd unilao
# 3. 검증 및 로그인 테스트
cat /etc/passwd | tail -1
su - unilao
# 비밀번호입력: souspolo
[ Q14 ] Set Password Max days as 20 days
vi /etc/login.defs
# 기존 99999 에서 수정
PASS_MAX_DAYS 20
[ Q15 ] Build an application rhcsa that print message when logged in as ablerate user (shell script 문제)
vi /usr/local/bin/rhcsa
#!/bin/bash
echo "Welcome to RHCSA!"
chmod +x /usr/local/bin/rhcsa
vi /home/ablerate/.bashrc
if [ -f /usr/local/bin/rhcsa ]; then
/usr/local/bin/rhcsa
fi
[ Q16 ] 사용자 natasha가 파일과 디렉터리를 생성했을 때, 다음과 같은 권한이 설정되도록 구성하시오
- 파일 생성 시 기본 권한: rw------- .
- 디렉터리 생성 시 기본 권한: rwx------ .
vi /home/natasha/.bash_profile
# 내용 추가
umask 077
# 검증
su - natasha
touch testfile
ls -ld testfile
umask
--------------------------------------------------- node 2 (Serverb) ---------------------------------------------------
[ Q17 ] RootPassword 재설정 (매우 중요) --> NumLock 체크하기!
1. VM reboot(재시동)
2. 아무키나 누르고 e누르기(내가 부팅시킬 grup에서 e를 누르자)
3. linux로 시작하는 끝줄(~quiet)에 init=/bin/bash 추가
4. ctrl + x
5, mount -o rw,remount /
6. passwd root (요구되는 비밀번호로 변경)
7. touch /.autorelabel
8. exec /sbin/init (재부팅)
[ Q18 ] Create an LVM name wshare from wgroup volume group. Note the following:
PE size should be 8MB
LVM size should be 50 extents
Format with "ext4" file system and mount it under /mnt/wshare. And it should auto mount after next reboot
Exam can have filesystem - vfat, xfs
# 1. 디스크 상태 확인
lsblk
# 2. 디스크를 LVM 파티션으로 설정
fdisk /dev/sdb
# n -> p -> 1 -> Enter -> Enter -> t -> 8e -> w (꼭 8e 아닐 수 있으니 alias 확인)
# 3. Physical Volume 생성
pvcreate /dev/sdb1
pvdisplay
# 4. Volume Group 생성
vgcreate -s 8M wgroup /dev/sdb1
vgdisplay
# 5. Logical Volume 생성
lvcreate -l 50 -n wshare wgroup
lvdisplay
# 6. 파일 시스템 생성
mkfs.ext4 /dev/wgroup/wshare
# 7. 마운트 및 자동 마운트 설정
mkdir /mnt/wshare
vi /etc/fstab
# 추가:
# /dev/wgroup/wshare /mnt/wshare ext4 defaults 0 0
mount -a
lsblk
df -h
[ Q19 ] Create a swap partition of 400 MB and make it available permanent
# 1. 디스크 상태 확인
lsblk
# 2. Swap 파티션 생성
fdisk /dev/sdb
# n -> p -> 2 -> Enter -> +400M -> t -> 82(alias 확인하기) -> w
# 3. Swap 초기화 및 활성화
mkswap /dev/sdb2
swapon /dev/sdb2
# 4. 자동 마운트 설정
vi /etc/fstab
# 추가하기
# /dev/sdb2 swap swap defaults 0 0
mount -a
# 5. 상태 확인
swapon --show
free -m
# 6. 재부팅 후 검증
reboot
lsblk
free -m
[ Q20 ] Resize your wshare logical volume, it should be approx 300MB note. only size accepted from 270mb to 290mb
# 1. Logical Volume 및 파일 시스템 상태 확인
blkid /dev/mapper/wgroup-wshare
lvs
df -h
# 2. Logical Volume 축소
umount /mnt/wshare
e2fsck -f /dev/mapper/wgroup-wshare
resize2fs /dev/mapper/wgroup-wshare 280M
lvreduce -L 280M /dev/mapper/wgroup-wshare
# 3. 마운트
mount /dev/mapper/wgroup-wshare /mnt/wshare
lsblk
df -h
[ Q21 ] Expand the ext4 filesystem on your vo logical volume to approximately 500MB, ensuring its final size is between 470MB and 510MB. (500을 늘리라는 건지(+500M), 500까지 확장하라는 건지(+a) 잘 확인하기, 아래 예시는 위의 Q20과 함께 실습하기위해 + 200M으로 처리)
# 1. Logical Volume 및 파일 시스템 상태 확인
lsblk
lvs
df -h
# 2. Logical Volume 확장
lvextend -r -L +200M /dev/mapper/wgroup-wshare
# 3. 파일 시스템 마운트(디렉토리 및 fstab에 없는 경우)
mkdir /mnt/wshare
vi /etc/fstab
# 추가:
# /dev/wgroup/wshare /mnt/wshare ext4 defaults 0 0
mount /mnt/wshare
df -h
[ Q22 ] Configure recommended tuned profile
# 1. Tuned 서비스 상태 확인 및 활성화
systemctl status tuned
systemctl enable --now tuned
# 2. 추천 Profile 설정
tuned-adm active
tuned-adm recommend
tuned-adm profile virtual-guest
# 3. 활성화 확인
tuned-adm active
[ Q23 ] Download containerfile from http://classroom/Containerfile
Do not make any modification.
Build image with this container file with user walhalla.
# 1. Podman 서비스 활성화
systemctl enable --now podman
# 2. 사용자 walhalla로 컨테이너 다운로드
ssh walhalla@node
wget http://classroom/Containerfile
# 3. 컨테이너 이미지 빌드
podman build -t pdf .
# 4. 이미지 빌드 확인
podman images
[ Q24 ] Configure a container to start automatically
- Create a container named ascii2pdf using the image which build previously.
- Configure the service to automatically mount the directory /opt/file to container directory /opt/incoming. And user directory /opt/processed to container directory /opt/outgoing
- Configure it to run as a systemd service that should run from the existing user walhalla only
- The service should be named ascii2pdf and should automatically start a system reboot without any manual intervention
# 1. 디렉터리 생성 및 권한 설정하고 walhalla로 로그인
sudo mkdir -p /opt/file /opt/processed
sudo chown walhalla:walhalla /opt/file /opt/processed
ssh walhalla@node
# 2. 컨테이너 실행
podman run -d --name ascii2pdf -v /opt/file:/opt/incoming:Z -v /opt/processed:/opt/outgoing:Z localhost/pdf
# 3. 컨테이너 상태 확인
podman ps -a
# 4. Systemd 유닛 파일 생성 및 저장
mkdir -p ~/.config/systemd/user/
cd .config/systemd/user
podman generate systemd --name ascii2pdf --files
# 5. Linger 활성화
loginctl enable-linger walhalla
# 6. Systemd 서비스 관리
systemctl --user enable --now container-ascii2pdf.service
# 7. 재부팅 후 검증
podman ps -a