rsyoung 사용자 생성
[root@cent ~]#useradd rsyoung
[root@cent ~]# id rsyoung
uid=500(rsyoung) gid=500(rsyoung) groups=500(rsyoung)
[root@cent ~]#
계정 삭제는 반드시 userdel -r로 해서 /home/ user directory를 제거해야한다. 왜냐하면, 삭제된 UID는 재사용되기 때문에 useradd로 생성한 사용자가 이전 사용자의 파일을 소유할 수 있어 보안의 문제가 발생할 수 있다.
그룹 dreamers 생성
[root@cent ~]# groupadd -g 601 dreamers
그룹 멤버로 추가 (-a 옵션사용)
[root@cent ~]# usermod -aG dreamers rsyoung
[root@cent ~]#
[root@cent ~]# id rsyoung
uid=500(rsyoung) gid=500(rsyoung) groups=500(rsyoung),601(dreamers)
[root@cent ~]#
shadow password 라이 확인
[root@cent ~]# cat /etc/shadow | grep rsyoung
rsyoung:$6$NKtePQa3i3uL4igb$Lgk7coKuzalMusvcEzaKkVzriz4mT6kkLR9ESYMVtjjmGMSwLRvV6d2peYlIxy2zIgSuHxRnnzYW5VBEvWojF1:15440:0:99999:7:::
[root@cent ~]#
사용자 비활성화 (-L) - ! 확인
[root@cent ~]# usermod -L rsyoung
[root@cent ~]#
[root@cent ~]# cat /etc/shadow | grep rsyoung
rsyoung:!$6$NKtePQa3i3uL4igb$Lgk7coKuzalMusvcEzaKkVzriz4mT6kkLR9ESYMVtjjmGMSwLRvV6d2peYlIxy2zIgSuHxRnnzYW5VBEvWojF1:15440:0:99999:7:::
[root@cent ~]#
사용자 활성화 (-U)
[root@cent ~]# usermod -U rsyoung
[root@cent ~]#
[root@cent ~]# cat /etc/shadow | grep rsyoung
rsyoung:$6$NKtePQa3i3uL4igb$Lgk7coKuzalMusvcEzaKkVzriz4mT6kkLR9ESYMVtjjmGMSwLRvV6d2peYlIxy2zIgSuHxRnnzYW5VBEvWojF1:15440:0:99999:7:::
[root@cent ~]#
다음로그인시 암호 업데이트 강제 수행
[root@cent ~]# chage -d 0 rsyoung
현재 설정정보
[root@cent ~]# chage -l alice
Last password change : Apr 10, 2012
Password expires : never
Password inactive : never
Account expires : Apr 20, 2012
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
[root@cent ~]#
계정정보 확인
[root@cent ~]# getent passwd rsyoung
rsyoung:x:500:500:Seo-Young Noh:/home/rsyoung:/bin/bash
[root@cent ~]#
debug log file 생성하기
현재 설정정보
[root@cent ~]# chage -l alice
Last password change : Apr 10, 2012
Password expires : never
Password inactive : never
Account expires : Apr 20, 2012
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
[root@cent ~]#
계정정보 확인
[root@cent ~]# getent passwd rsyoung
rsyoung:x:500:500:Seo-Young Noh:/home/rsyoung:/bin/bash
[root@cent ~]#
rsyslog (reliable syslog)를 이용하여 debug 정보를 로그로 만들 수 있다.
/etc/rsyslog.conf 파일에 다음 라인 추가
*.debug var/log/debug.log
logger를 이용하여 debug 메시지 생성
[root@cent etc]# logger -p debug Hello This is Debug
/var/log/debug.log에 메시지가 생성되는지 검사
[root@cent etc]# tail -f /var/log/debug.log
Apr 10 21:16:13 cent root: Hello This is Debug
logwatch 실행결과 전자우편으로 받아보기
/etc/logwatch/conf/logwatch.conf 파일에 다음 라인 추가
MailTo = <your email address>
logwatch의 default conf 파일은 /usr/share/logwatch/default.conf/logwatch.conf에 존재하지만, /etc/logwatch/conf/logwatch.conf에 설정된 값이 오버라이딩하게된다.
매일 새벽 1시에 logwatch를 수행하려면 crontab을 작성한다.
[root@cent etc]# crontab -e
1 0 * * * logwatch
만약 매일 자정 1분에 logwatch를 시작하기로 되어있으나 문제가 발생하여 실핼을 못시킬 수 도 있다 이를 예방하려면, /etc/cron.daily에 cron job 생성한다.
logrotate
설정파일은 /etc/logrotate.conf
yum
yum list installed <package name>
yum list installed
yum info <package name>
yum install <package name>
yum remove <package name>
yum update <package name>
yum repolist
yum check-update
yum history
yum history list
yum history info <num>
yum history undo <num>
yum search 'web server'
yum grouplist -v
yum groupinstall @kde-desktop
yum install @kde-desktop
rpm
rpm -q samba-client
rpm -qa
rpm -q zlib -l # location
rpm -q httpd --scripts # scripts
rpm -q httpd -c # conf files
rpm -q httpd -d # document
rpm -q -p <local rpm packages> -l
rpm -q -p <local rpm packages> -c
rpm -q -p <local rpm packages> -d
yum localinstall <local rpm package>
yum localinstall --nogpgcheck <local rpm package>
/etc/yum.repos.d/*.repo 설정예
[root@cent yum.repos.d]# cat errata.repo
[Updates]
name=Update Repository
baseurl=ftp://update.url.com/pub
gpgcheck=1
enabled=1
[root@cent yum.repos.d]#
[root@cent yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: ftp.daum.net
* extras: ftp.daum.net
* updates: ftp.daum.net
ftp://update.url.com/pub/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"
Trying other mirror.
repo id repo name status
Updates Update Repository 0
base CentOS-6 - Base 0
extras CentOS-6 - Extras 0
updates CentOS-6 - Updates 0
repolist: 0
[root@cent yum.repos.d]#
- 명령어의 위치: /usr/bin/man
- 파일의 실제위치
- /usr/local/share/man
- man1, man2, ..., man2x
- man1: user command
- man2: system call
- man3: 라이브러리 함수 & 서브루틴
- man4: /dev의 특수파일 보관 디렉토리
- man5: 파일포맷관련
- man6: 게임관련
- man7: 기타
- man8: 시스템 관리 명령
- man9: 커널관련 명령어
- mann: Tcl/tk 내장
- 예
- man 1 ps
- man 5 sssd
- man 8 sssd.conf
- man path ls
- /usr/share/man/ko
- /usr/share/man
- /usr/x11r6/man
top
- M: Memory를 가장 많이 소비하고있는 프로세스
- P: Processor를 가장 많이 소비하고있는 프로세스
- renice -n 15 <pid>
ssh
키생성하기
[root@cent ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
49:73:4f:8a:29:86:fb:f2:b4:bb:65:2c:02:f3:30:e2 root@cent.rsyoung.org
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| o . . |
| . . * + |
|. = . o S . . |
|.. * o o |
| E + o + |
| .+ = |
| o*o |
+-----------------+
[root@cent ~]#
[root@cent ~]# ls -al .ssh/
total 16
drwx------. 2 root root 4096 Apr 10 22:20 .
dr-xr-x---. 25 root root 4096 Apr 10 22:20 ..
-rw-------. 1 root root 1675 Apr 10 22:20 id_rsa
-rw-r--r--. 1 root root 403 Apr 10 22:20 id_rsa.pub
[root@cent ~]#
다른서버로 public key 보내기
[root@cent ~]# ssh-copy-id root@targetserver
설정파일
[root@cent ~]# rpm -q openssh-server -c
/etc/pam.d/ssh-keycat
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
[root@cent ~]#
루트로그인 막기 (/etc/ssh/sshd_config)
PermitRootLogin no
암호인증 막기
PasswordAuthentication no
ssh 접속이 매우 늦을때
GSSAPIAuthentication no
타임관리
현재시간: data
하드웨어시간: hwclock
네트워크시간: rdate -s time.bora.net
시간프린트: rdate -p time.bora.net
FTP 서버설정
/etc/vsftpd/vsftpd.conf
anonymous =YES
local_enable=NO # local user 접근불가
write_enable=NO # 쓰기금지
SELINUX
/etc/selinux/config
- Mode
- enabled
- enforcing
- permissive: log는 남김
- disabled
[root@cent ~]# getenforce
Enforcing
[root@cent ~]# setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@cent ~]#
[root@cent ~]# setenforce Permissive
[root@cent ~]# getenforce
Permissive
[root@cent ~]# setenforce 1
[root@cent ~]# getenforce
Enforcing
[root@cent ~]#
selinux가 enforcing되어있을때 ls -Z
[root@cent ~]# ls -Z
-rw-------. root root system_u:object_r:admin_home_t:s0 anaconda-ks.cfg
drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 Desktop
drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 Documents
drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 Downloads
drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 Music
drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 Pictures
-rw-r--r--. root root system_u:object_r:admin_home_t:s0 post-install
-rw-r--r--. root root system_u:object_r:admin_home_t:s0 post-install.log
drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 Public
drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 Templates
drwxr-xr-x. root root unconfined_u:object_r:admin_home_t:s0 Videos
[root@cent ~]#
admin_home_t: 컨텍스트를 의미함. 이 컨텍스트가 아닌 다른 컨텍스트에서 파일을 조작할경우 selinux 에러메시지가 /var/log/message에 기록됨.
[root@cent /]# touch /tmp/file1
[root@cent /]# touch /tmp/file2
[root@cent /]# ls -Z /tmp/file*
-rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 /tmp/file1
-rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 /tmp/file2
[root@cent /]#
[root@cent /]# mv /tmp/file1 /var/www/html/
[root@cent /]# cp /tmp/file2 /var/www/html/
[root@cent /]#
[root@cent /]# cd /var/www/html/
[root@cent html]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:user_tmp_t:s0 file1
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 file2
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
[root@cent html]#
[root@cent html]# cd ..
[root@cent www]# restorecon -R /var/www/
[root@cent www]#
[root@cent www]# cd html/
[root@cent html]# ls -Z
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 file1
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 file2
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
[root@cent html]#
Access Control List
현재 파일시스템이 ACL을 지원하는지여부 파악
[root@cent ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
5.5G 2.2G 3.3G 40% /
tmpfs 1004M 272K 1004M 1% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 43M 43M 0 100% /media/VBOXADDITIONS_4.1.2_73507
[root@cent ~]#
[root@cent ~]# dumpe2fs /dev/mapper/vg_centos-lv_root | grep Default
dumpe2fs 1.41.12 (17-May-2010)
Default mount options: user_xattr acl
Default directory hash: half_md4
[root@cent ~]#
[root@cent ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
5.5G 2.2G 3.3G 40% /
tmpfs 1004M 272K 1004M 1% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 43M 43M 0 100% /media/VBOXADDITIONS_4.1.2_73507
[root@cent ~]#
[root@cent ~]# dumpe2fs /dev/mapper/vg_centos-lv_root | grep Default
dumpe2fs 1.41.12 (17-May-2010)
Default mount options: user_xattr acl
Default directory hash: half_md4
[root@cent ~]#
ACL을 지원하고있다. 만약 지원하지 않는다면, tune2fs로 ACL지원하도록 설정.
[root@cent ~]# tune2fs -o user_xattr,acl /dev/mapper/vg_centos-lv_root
tune2fs 1.41.12 (17-May-2010)
[root@cent ~]#
주의: 컴마(,) 사이는 공백이 있으면 안됨.
ACL의 특징중의 하나가 다중 group을 지원한다는 점이다. ugo 모드에서는 단일 그룹만지원한다.
/opt/research 디렉토리
[root@cent opt]# ls -al /opt/research/
total 16
drwxr-s---. 2 root grads 4096 Apr 12 22:36 .
drwxr-xr-x. 4 root root 4096 Apr 12 22:29 ..
-rw-rw----+ 1 root grads 29 Apr 12 22:36 file.txt
[root@cent opt]#
./research 디렉토리의 ACL
[root@cent opt]# getfacl ./research/
# file: research/
# owner: root
# group: grads
# flags: -s-
user::rwx
group::r-x
other::---
grads, profs 그룹이 /opt/research 디렉토리를 접근하고 읽고쓸수 있도록 설정.
[root@cent opt]# setfacl -m g:profs:rwx ./research/
[root@cent opt]# setfacl -m g:grads:rwx ./research/
[root@cent opt]#
[root@cent opt]# getfacl ./research/
# file: research/
# owner: root
# group: grads
# flags: -s-
user::rwx
group::r-x
group:profs:rwx
group:grads:rwx
mask::rwx
other::---
[root@cent opt]#
grads 그룹이 ./research 디렉토리하에 생기는 모든 파일들을 읽고쓸수 있게함.
other들은 ./research 디렉토리 접근을 원천 차단
other들은 ./research 디렉토리내에 생성된 파일들을 접근할 수 없음.
[root@cent opt]# setfacl -m d:g:grads:rwx ./research/
[root@cent opt]# setfacl -m o::- ./research/
[root@cent opt]# setfacl -m d:o::- ./research/
[root@cent opt]#
[root@cent opt]# getfacl ./research/
# file: research/
# owner: root
# group: grads
# flags: -s-
user::rwx
group::r-x
group:profs:rwx
group:grads:rwx
mask::rwx
other::---
default:user::rwx
default:group::r-x
default:group:grads:rwx
default:mask::rwx
default:other::---
[root@cent opt]#
grads 그룹이 ./research 디렉토리를 소유하게하고, 이 디렉토리 하에 생기는 모든 파일들들에 대해 grads 그룹이 소유하도록 설정.
[root@cent opt]# chgrp grads ./research/
[root@cent opt]# chmod g+s ./research/
[root@cent opt]# ls -al
total 20
drwxr-xr-x. 4 root root 4096 Apr 12 22:29 .
dr-xr-xr-x. 26 root root 4096 Apr 12 22:57 ..
drwxrws---+ 2 root grads 4096 Apr 12 22:36 research
[root@cent opt]#
디렉토리를 오픈하기위해서는 rwx에서 x가 반드시 설정되어 있어야 함. man chmod를 해보면 다음과 같은 설명이 있음.
The letters rwxXst select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory or already has execute permission for some user (X), set user or group ID on execution (s), restricted deletion flag or sticky bit (t). Instead of one or more of these letters, you can specify exactly one of the letters ugo: the permissions granted to the user who owns the file (u), the permissions granted to other users who are members of the file’s group (g), and the permissions granted to users that are in neither of the two preceding categories (o).
Fedora, RedHat, CentOS에서 Boot Time시 문제 해결
fstab 문제로 Maintenance 모드로 빠지고 fstab을 수정할 수 없을때
fstab 문제로 Maintenance 모드로 빠지고 fstab을 수정할 수 없을때
mount -o remount rw, /
root password를 잃어버렸을 때
GRUB에서 Kernel Parameter로 "s"를 넘겨 single user로 접속
passwd 변경시도.
passwd 변경시도시 바로 빠져나오면 SELinux가 enable 되었는지 확인
SELinux가 enable되었다면 setenforce 0으로 SELinux를 passive 모드로 전환
passwd로 root 패스워드 변경
passwd 변경시도.
passwd 변경시도시 바로 빠져나오면 SELinux가 enable 되었는지 확인
SELinux가 enable되었다면 setenforce 0으로 SELinux를 passive 모드로 전환
passwd로 root 패스워드 변경