20160428 리눅스 관리자
============================================메모============================================
============================================복습============================================
============================================강의============================================
6. 부팅과정
(ㄱ) Firmware Phase
- POST, boot device 선택
(ㄴ) Grub Phase (EX : /boot/grub/grub.conf)
- Kernel
(ㄷ) Kernel Phase
- Kernel Module (EX : Device Driver)
(ㄹ) init Phase (EX : /etc/inittab)
- runlevel
- rc.sysinit
- rc 5 (/etc/rc5.d/S*script start)
7. 사용자 & 그룹 관리
사용자 관리
사용자 관련 파일들
- /etc/passwd
- /etc/shadow
사용자 관리 명령어
- useradd CMD
# useradd user01
# useradd -M -d /oracle oracle
- usermod CMD
# usermod -l user02 -d /home/user02 -m user01
- userdel CMD
# userdel [-r] user02
그룹 관리
그룹 관련 파일들
- /etc/group
그룹 관리 명령어
- groupadd CMD
- groupmod CMD
- groupdel CMD
암호 관리
chage CMD
# chage -M 30 -w 7 user01
# chage -E 2016-12-31 user01
# chage -l user01
8. 스케줄링
at CMD
# at 1300
# at -l (# atq)
# at -r <Job ID> (# atrm <Job ID>)
crontab CMD
# crontab -e
# crontab -l
# crontab -r (주의!!)
============================================실습============================================
[EX4] /etc/fstab 파일이 잘못되는 경우
① /etc/fstab 파일 백업
# cp /etc/fstab /etc/fstab.old
② /etc/fstab 파일 이상
# vi /etc/fstab
[수정전]
# LABEL=/testmount /tsetmount ext3 defaults 1 2
[수정후]
LABEL=/testmount /tsetmount ext3 defaults 1 2
# e2label /dev/sdb1 ""
# e2label /dev/sdb1
#
③ 재부팅
# reboot
④ 에러메세지 확인
⑤ 에러 제어
..... (중략) .....
Give root password for maintenance
(or type Control-D to continue): root 암호 입력
# mount -o remount /
# cp /etc/fstab.old /etc/fstab
or
# e2label /dev/sdb1
# e2label /dev/sdb1 /testmount
[root@linux220 ~]# cp /etc/fstab /etc/fstab.old
[root@linux220 ~]# ls /etc/fstab.old
/etc/fstab.old
[root@linux220 ~]# vi /etc/fstab
[root@linux220 ~]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/data1 /data1 ext3 defaults 1 2
LABEL=/data2 /data2 ext3 defaults 1 2
LABEL=/data3 /data3 ext3 defaults 1 2
LABEL=/data4 /data4 ext3 defaults 1 2
LABEL=/home /home ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda2 swap swap defaults 0 0
#
# (1) Specific Configuration(EX: Normal Disk Works)
#
#/dev/sdb1 /testmount ext3 defaults 1 2
LABEL=/testmount /testmount ext3 defaults 1 2
#
# (2) Oracle Disk Mount
#
#/dev/sdc1 /oracle ext3 defaults 1 2
#
# (3) LVM Configuration
#
#/dev/mapper/vg1-lv1 /lv1 ext3 defaults 1 2
#/dev/vg1/lv2 /lv2 ext3 defaults 1 2
#/dev/VG1/LV1 /lvm1 ext3 defaults 1 2
#/dev/VG1/LV2 /lvm2 ext3 defaults 1 2
#/dev/VG2/LV3 /lvm3 ext3 defaults 1 2
#/dev/VG2/LV4 /lvm4 ext3 defaults 1 2
#
# (4) RAID Configuration
#
#/dev/md0 /raid0 ext3 defaults 1 2
#/dev/md0 /raid1 ext3 defaults 1 2
#/dev/md0 /raid5 ext3 defaults 1 2
[root@linux220 ~]# e2label /dev/sdb1 ""
[root@linux220 ~]# e2label /dev/sdb1
[root@linux220 ~]# reboot
그림1
그림2
그림3
reboot
정상부팅
사용자 관리 (User Administration)
(1) 사용자 정보 파일
Ÿ /etc/passwd 사용자의 기본적인 정보가 저장된 파일
필드 설 명
root 사용자 이름
x 사용자 암호(보안상 /etc/shadow 파일에 암호를 옮겨 놓았음)
0 사용자 아이디(UID)
0 그룹 아이디(GID), 사용자의 주 그룹(Primary Group)
root 설명 정보(Comment)
/root 홈 디렉토리
/bin/bash 로그인 쉘
Ÿ /etc/shadow 사용자의 암호가 저장된 파일
필드 설 명
root 사용자 이름(login name)
$1$z0vZjMTK$pp5tRxbS9k9CWhimjHfZA. 사용자 암호(encrypted password)
14642 암호변경일(days since Jan 1, 1970 that password was last changed)
0 암호를 변경할 수 없는 최소 날짜 (days before password may be changed)
99999 암호를 사용할 수 있는 최대 날짜 (days after which password must be changed)
7 사용자 암호 만료되기전 사용자에게 경고 메세지를 주는 기간
(days before password is to expire that user is warned)
사용자 로그인하지 않으면 암호를 비활성화 시키는 기간
(days after password expires that account is disabled)
사용자 암호 만료 기간, 절대로 넘을 수 없는 기간
(days since Jan 1, 1970 that account is disabled)
아직 기능이 없음
[root@linux220 ~]# cat /etc/passwd | grep root
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@linux220 ~]# cat /etc/shadow | grep root
root:$1$vUJY07xR$Xwphobq/1RpjQJ.TmR2kq1:16902:0:99999:7:::
$1$ : 암호화 알고리즘
$vUJY07xR$ : salt key
$Xwphobq/1RpjQJ.TmR2kq1 : 암호화된 암호
(2) 사용자 관리 명령어
Ÿ useradd CMD 사용자 정보 추가 명령어
Ÿ usermod CMD 사용자 정보 변경 명령어
Ÿ userdel CMD 사용자 정보 삭제 명령어
(2-1) useradd 명령어
Ÿ useradd 명령어나 adduser 명령어 모두 수행 가능하다.
(명령어 형식)
# useradd [options] LOGIN
(명령어 사용예)
# useradd user01
# useradd -d /users/user01 user01
# useradd -u 1000 -g users -c "Test User" -d /users/user01 -s /bin/ksh user01
# useradd user01
# passwd user01
useradd 명령어의 기본 옵션(Default Options)
-u UID 자동으로 UID 선택(UID 50 이상), 기존 사용자 UID 다음번째 UID 선택
-g GID 자동으로 GID 자동 선택, 사용자 이름과 동일한 그룹 생성
-c COMENT 설명은 없음
-d HOME_DIR /home/$USER 디렉토리 생성
-s /bin/bash 기본적으로 /bin/bash 지정
[EX1] user01 사용자 추가
(조건) 기존에 존재하는 사용자는 없어야 한다.
user01/user02/user03 .....
만약 사용자가 존재한다면 아래와 같이 삭제한다.
# cat /etc/passwd
# userdel –r <사용자이름>
[root@linux220 ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/etc/news:
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
distcache:x:94:94:Distcache:/:/sbin/nologin
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
pcap:x:77:77::/var/arpwatch:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
avahi:x:70:70:Avahi daemon:/:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
hsqldb:x:96:96::/var/lib/hsqldb:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
avahi-autoipd:x:100:102:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
fedora:x:500:500:fedora:/home/fedora:/bin/bash
tomcat:x:91:91:Tomcat:/usr/share/tomcat5:/bin/sh
[root@linux220 ~]# cat /etc/passwd | tail
named:x:25:25:Named:/var/named:/sbin/nologin
hsqldb:x:96:96::/var/lib/hsqldb:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
avahi-autoipd:x:100:102:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
fedora:x:500:500:fedora:/home/fedora:/bin/bash
tomcat:x:91:91:Tomcat:/usr/share/tomcat5:/bin/sh
[root@linux220 ~]# cat /etc/passwd | tail
named:x:25:25:Named:/var/named:/sbin/nologin
hsqldb:x:96:96::/var/lib/hsqldb:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
avahi-autoipd:x:100:102:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
fedora:x:500:500:fedora:/home/fedora:/bin/bash
tomcat:x:91:91:Tomcat:/usr/share/tomcat5:/bin/sh
[root@linux220 ~]#
[root@linux220 ~]# useradd user01
pa[root@linux220 ~]# passwd user01
Changing password for user user01.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# passwd user01
Changing password for user user01.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# grep user01 | etc/shadow
bash: etc/shadow: 그런 파일이나 디렉토리가 없음
[root@linux220 ~]# grep user01 /etc/shadow
user01:$1$PqdfZhMG$4vt.zy4Gxwt8fdMvbb0Gr1:16919:0:99999:7:::
[root@linux220 ~]# grep user01 /etc/shadow
user01:$1$PqdfZhMG$4vt.zy4Gxwt8fdMvbb0Gr1:16919:0:99999:7:::
[root@linux220 ~]# grep user01 /etc/passwd
user01:x:501:501::/home/user01:/bin/bash
[root@linux220 ~]# ls -ld /home/user01
drwx------ 3 user01 user01 1.0K 4월 28 16:49 /home/user01
[root@linux220 ~]# grep user01 /etc/group
user01:x:501:
[root@linux220 ~]# ls -ld /home/user01
drwx------ 3 user01 user01 1.0K 4월 28 16:49 /home/user01
[root@linux220 ~]# ls -l /var/spoom/mail
ls: /var/spoom/mail: 그런 파일이나 디렉토리가 없음
[root@linux220 ~]# ls -l /var/spool/mail
합계 20K
-rw-rw---- 1 fedora mail 0 4월 12 04:37 fedora
-rw------- 1 root root 11K 4월 27 17:25 root
-rw-rw---- 1 rpc mail 0 4월 12 03:35 rpc
-rw-rw---- 1 user01 mail 0 4월 28 16:49 user01
[root@linux220 ~]# mkdir -p /users
[root@linux220 ~]# useradd -d /users/user02 user02
[root@linux220 ~]# passwd user02
Changing password for user user02.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# grep user02 /etc/passwd
user02:x:502:502::/users/user02:/bin/bash
[root@linux220 ~]# grep user02 /etc/shadow
user02:$1$AgtY9FvA$U9wB88RHPVO11nXRohScJ/:16919:0:99999:7:::
[root@linux220 ~]# ls -ld /users/user02
drwx------ 3 user02 user02 4.0K 4월 28 16:53 /users/user02
[root@linux220 ~]# grep user02 /etc/group
user02:x:502:
(2-2) usermod 명령어
(명령어 형식)
# usermod [options] LOGIN
Options:
-a, --append append the user to the supplemental GROUPS(use only with -G)
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the new location (use only with -d)
-o, --non-unique allow using duplicate (non-unique) UID
-p, --password PASSWORD use encrypted password for the new password
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account
-U, --unlock unlock the user account
-Z, --selinux-user new selinux user mapping for the user account
(/etc/passwd)
user01:x:1000:100:Test User:/users/user01:/bin/ksh
-l : x : -u : -g : -c : -d : -s
(명령어 사용예)
# usermod -u 2000 user01
# usermod -s /bin/ksh user01
# usermod -g 10 -c "Test Group" user01
# usermod -l user03 -d /home/user03 -m user01 (-l : login name)
[EX1] user01 사용자 정보 변경
[root@linux220 ~]# usermod -u 2000 user01
[root@linux220 ~]# grep user01 /etc/passwd
user01:x:2000:501::/home/user01:/bin/bash
[root@linux220 ~]# usermod -s /bin/ksh user01
[root@linux220 ~]# grep user01 /etc/passwd
user01:x:2000:501::/home/user01:/bin/ksh
[root@linux220 ~]# usermod -l user03 -d /home/user03 -m user01
[root@linux220 ~]# grep user03 /etc/passwd
user03:x:2000:501::/home/user03:/bin/ksh
[root@linux220 ~]# ls -l /home
합계 15K
-rw-r--r-- 1 root root 0 4월 22 17:59 499
drwx------ 3 fedora fedora 1.0K 4월 20 17:31 fedora
drwx------ 2 root root 12K 4월 12 03:33 lost+found
drwx------ 3 user03 user01 1.0K 4월 28 16:49 user03
(2-3) userdel 명령어
(명령어 형식)
# userdel [options] LOGIN
Options:
-f, --force force removal of files, even if not owned by user
-h, --help display this help message and exit
-r, --remove remove home directory and mail spool
(명령어 사용예)
# userdel user01
# userdel –r user01
[EX] 사용자 삭제 실습
[root@linux220 ~]# userdel user02
[root@linux220 ~]# grep user02 /etc/passwd
[root@linux220 ~]# ls -l /users
합계 4.0K
drwx------ 3 502 502 4.0K 4월 28 16:53 user02
[root@linux220 ~]# rm -rf /users/user02
[root@linux220 ~]# userdel -r user03
[root@linux220 ~]# grep user01 /etc/group
user01:x:501:
[root@linux220 ~]# groupdel user01
[root@linux220 ~]# grep user01 /etc/group
[EX1] 사용자 설명 정보 및 로그인 쉘 변경
[root@linux220 ~]# cat /etc/passwd | grep user01
[root@linux220 ~]# useradd user01
[root@linux220 ~]# passwd user01
Changing password for user user01.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# cat /etc/passwd | grep user01
user01:x:501:501::/home/user01:/bin/bash
[root@linux220 ~]# useradd -c testuser -s /bin/sh user02
메일함 파일을 생성 중: 파일이 존재합니다
[root@linux220 ~]# passwd user02
Changing password for user user02.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# cat /etc/passwd | grep user02
user02:x:502:502:testuser:/home/user02:/bin/sh
[root@linux220 ~]# mkdir /users
mkdir: `/users' 디렉토리를 만들 수 없습니다: 파일이 존재합니다
[root@linux220 ~]# useradd -s /bin/tcsh -d /users/test user03
[root@linux220 ~]# passwd user03
Changing password for user user03.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
Sorry, passwords do not match.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# cat /etc/passwd | grep user03
user03:x:503:503::/users/test:/bin/tcsh
[root@linux220 ~]# ls -l /users
합계 4.0K
drwx------ 3 user03 user03 4.0K 4월 28 17:05 test
[root@linux220 ~]# cat /etc/passwd | grep user*
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
user01:x:501:501::/home/user01:/bin/bash
user02:x:502:502:testuser:/home/user02:/bin/sh
user03:x:503:503::/users/test:/bin/tcsh
[root@linux220 ~]# cat /etc/passwd | grep user0*
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
user01:x:501:501::/home/user01:/bin/bash
user02:x:502:502:testuser:/home/user02:/bin/sh
user03:x:503:503::/users/test:/bin/tcsh
[EX3] 홈계정 생성시 참조되는 디렉토리 및 파일
사용자 계정이 생성될 때 /etc/skel(skelton) 디렉토리에서 파일등이 복사 된다.
[root@linux220 ~]# useradd user05
You have new mail in /var/spool/mail/root
[root@linux220 ~]# passwd user05
Changing password for user user05.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# ls -al /etc/skel /home/user05
/etc/skel:
합계 48K
drwxr-xr-x 3 root root 4.0K 5월 11 2011 .
drwxr-xr-x 111 root root 12K 4월 28 17:27 ..
-rw-r--r-- 1 root root 33 9월 26 2014 .bash_logout
-rw-r--r-- 1 root root 176 9월 26 2014 .bash_profile
-rw-r--r-- 1 root root 124 9월 26 2014 .bashrc
-rw-r--r-- 1 root root 515 4월 28 2011 .emacs
drwxr-xr-x 4 root root 4.0K 10월 30 2013 .mozilla
/home/user05:
합계 8.0K
drwx------ 3 user05 user05 1.0K 4월 28 17:27 .
drwxr-xr-x 7 root root 1.0K 4월 28 17:27 ..
-rw-r--r-- 1 user05 user05 33 4월 28 17:27 .bash_logout
-rw-r--r-- 1 user05 user05 176 4월 28 17:27 .bash_profile
-rw-r--r-- 1 user05 user05 124 4월 28 17:27 .bashrc
-rw-r--r-- 1 user05 user05 515 4월 28 17:27 .emacs
drwxr-xr-x 4 user05 user05 1.0K 4월 28 17:27 .mozilla
[root@linux220 ~]# cd /etc/skel
[root@linux220 /etc/skel]# alias ll
alias ll='ls -l --color=tty'
[root@linux220 /etc/skel]# vi .bashrc
[root@linux220 /etc/skel]# cat .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
alias ll='ls -lFh --color=tty' #파일타입, 휴먼리더블
[root@linux220 /etc/skel]# useradd user06
[root@linux220 /etc/skel]# passwd user06
Changing password for user user06.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 /etc/skel]# ls -al /etc/skel /home/user06
/etc/skel:
합계 48K
drwxr-xr-x 3 root root 4.0K 4월 28 17:28 .
drwxr-xr-x 111 root root 12K 4월 28 17:29 ..
-rw-r--r-- 1 root root 33 9월 26 2014 .bash_logout
-rw-r--r-- 1 root root 176 9월 26 2014 .bash_profile
-rw-r--r-- 1 root root 186 4월 28 17:28 .bashrc
-rw-r--r-- 1 root root 515 4월 28 2011 .emacs
drwxr-xr-x 4 root root 4.0K 10월 30 2013 .mozilla
/home/user06:
합계 8.0K
drwx------ 3 user06 user06 1.0K 4월 28 17:29 .
drwxr-xr-x 8 root root 1.0K 4월 28 17:29 ..
-rw-r--r-- 1 user06 user06 33 4월 28 17:29 .bash_logout
-rw-r--r-- 1 user06 user06 176 4월 28 17:29 .bash_profile
-rw-r--r-- 1 user06 user06 186 4월 28 17:29 .bashrc
-rw-r--r-- 1 user06 user06 515 4월 28 17:29 .emacs
drwxr-xr-x 4 user06 user06 1.0K 4월 28 17:29 .mozilla
[root@linux220 /etc/skel]# cat /home/user06/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
alias ll='ls -lFh --color=tty' #파일타입, 휴먼리더블
[EX4] 다중 사용자 추가
(권장) 관리자용 스크립트 디렉토리 : /root/bin, /root/shell
# ls -ld /root
[root@linux220 ~]# mkdir -p /root/bin
[root@linux220 ~]# cd ~/bin
[root@linux220 ~/bin]# vi passwd.txt
[root@linux220 ~/bin]# cat passwd.txt
user100 user100
user101 user101
[root@linux220 ~/bin]# vi useradd.sh
[root@linux220 ~/bin]# cat useradd.sh
#!/bin/bash
cat /root/bin/passwd.txt | while read USER_NAME PASSWD
do
useradd $USER_NAME
echo $PASSWD | /usr/bin/passwd --stdin $USER_NAME
done
[root@linux220 ~/bin]# man passwd
Formatting page, please wait...
[root@linux220 ~/bin]# echo user01
user01
[root@linux220 ~/bin]# echo user01 | passwd --stdin user01
Changing password for user user01.
passwd: all authentication tokens updated successfully.
[root@linux220 ~/bin]# chmod 750 useradd.sh
[root@linux220 ~/bin]# ./useradd.sh
Changing password for user user100.
passwd: all authentication tokens updated successfully.
Changing password for user user101.
passwd: all authentication tokens updated successfully.
[root@linux220 ~/bin]# cat /etc/passwd | grep user10*
user100:x:506:506::/home/user100:/bin/bash
user101:x:507:507::/home/user101:/bin/bash
[root@linux220 ~]# cd ~/bin
[root@linux220 ~/bin]# vi add.sh
[root@linux220 ~/bin]# cat add.sh
#!/bin/bash
START=100
END=140
while [ $START -le $END ] # -le : less equal
do
echo "user$START user$START" >> /root/bin/passwd.txt
START=`expr $START + 1`
done
[root@linux220 ~/bin]# ./add.sh
bash: ./add.sh: 허가 거부됨
[root@linux220 ~/bin]# chmod 750 add.sh
[root@linux220 ~/bin]# ./add.sh
[root@linux220 ~/bin]# ls
CoffeeTime.txt cow.txt disk mailling.sh telnet.sh
CoffeeTime2.txt cow2.txt disk_exhaust.c mem useradd.sh
add.sh cow3.txt dog.txt mem.c
backup.sh cpu.sh dog2.txt network.sh
bomb.sh cpu2.sh dog3.txt passwd.txt
bomb_exec.sh cpu3.sh hello.sh proc_count.sh
[root@linux220 ~/bin]# cat passwd.txt
user100 user100
user101 user101
user100 user100
user101 user101
user102 user102
user103 user103
user104 user104
user105 user105
user106 user106
user107 user107
user108 user108
user109 user109
user110 user110
user111 user111
user112 user112
user113 user113
user114 user114
user115 user115
user116 user116
user117 user117
user118 user118
user119 user119
user120 user120
user121 user121
user122 user122
user123 user123
user124 user124
user125 user125
user126 user126
user127 user127
user128 user128
user129 user129
user130 user130
user131 user131
user132 user132
user133 user133
user134 user134
user135 user135
user136 user136
user137 user137
user138 user138
user139 user139
user140 user140
[EX5] useradd 명령어 실행시 사용되는 기본 설정값 바꾸기
# useradd -D (-D : Default) /* 설정파일의 내용을 출력 함 */
[root@linux220 ~/bin]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@linux220 ~/bin]# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@linux220 ~/bin]# useradd -D -s /bin/sh
[root@linux220 ~/bin]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@linux220 ~/bin]# useradd -D -b /users
[root@linux220 ~/bin]# useradd -D
GROUP=100
HOME=/users
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@linux220 ~/bin]# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/users
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@linux220 ~/bin]# useradd user08
[root@linux220 ~/bin]# passwd user08
Changing password for user user08.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~/bin]# cat /etc/passwd | grep user08
user08:x:508:508::/users/user08:/bin/sh
[root@linux220 ~/bin]# cat /etc/passwd | grep user07
[root@linux220 ~/bin]# cat /etc/passwd | grep user06
user06:x:505:505::/home/user06:/bin/bash
[root@linux220 ~/bin]# useradd -D -s /bin/bash
[root@linux220 ~/bin]# useradd -D -b /home
[root@linux220 ~/bin]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
그룹 관리(Group Administration)
(1) 그룹 정보 파일
Ÿ /etc/group 파일 그룹 정보 파일
[root@linux220 ~]# cat /etc/group | head -3
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
필 드 설 명
root 그룹 이름
x 그룹 암호
0 그룹 아이디(GID)
root 그룹(Secondary Group)에 속한 사용자 목록
[root@linux220 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@linux220 ~]# groups
root bin daemon sys adm disk wheel
Primary Group : root(0)
Secondary Group : bin(1), daemon(2), sys(3), adm(4), disk(6), wheel(10)
[root@linux220 ~]# cat /etc/group | grep root
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
disk:x:6:root
wheel:x:10:root
(2) 그룹 관리 명령어
Ÿ groupadd 명령어 그룹 정보 추가
Ÿ groupmod 명령어 그룹 정보 변경
Ÿ groupdel 명령어 그룹 정보 삭제
(2-1) groupadd 명령어
(명령어 형식)
# groupadd [options] group
(명령어 사용예)
# groupadd class1
# groupadd -g 1000 class1
[EX] 그룹 추가
# groupadd class1
# grep class1 /etc/group
class1:x:507:
# groupadd -g 1000 class2
# grep class2 /etc/group
class2:x:1000:
[root@linux220 ~]# groupadd class1
[root@linux220 ~]# grep class1 /etc/group
class1:x:509:
[root@linux220 ~]# groupadd -g 1000 class2
[root@linux220 ~]# grep class2 /etc/group
class2:x:1000:
(2-2) groupmod 명령어
(명령어 형식)
# groupmod [-g gid [-o]] [-n name] group
(명령어 사용예)
# groupmod -g 1001 class1
# groupmod -n class2 class1 (-n : Group Name)
[EX] 그룹 정보 변경
[root@linux220 ~]# cat /etc/group | grep class1
class1:x:509:
[root@linux220 ~]# groupmod -g 1001 class1
[root@linux220 ~]# grep class1 /etc/group
class1:x:1001:
[root@linux220 ~]# groupmod -n class3 class1
[root@linux220 ~]# cat /etc/group | tail -3
user08:x:508:
class2:x:1000:
class3:x:1001:
(2-3) groupdel 명령어
(명령어 형식)
# groupdel group
(명령어 사용예)
# groupdel class1
[EX] 그룹 삭제
[root@linux220 ~]# cat /etc/group | tail
user01:x:501:
user02:x:502:
user03:x:503:
user05:x:504:
user06:x:505:
user100:x:506:
user101:x:507:
user08:x:508:
class2:x:1000:
class3:x:1001:
[root@linux220 ~]# groupdel class2
[root@linux220 ~]# groupdel class3
[root@linux220 ~]# cat /etc/group | tail
fedora:x:500:
tomcat:x:91:
user01:x:501:
user02:x:502:
user03:x:503:
user05:x:504:
user06:x:505:
user100:x:506:
user101:x:507:
user08:x:508:
패스워드 사용 제한 관리(Password Aging)
시스템 보안을 위해 사용자 패스워드 만기일을 설정 및 변경하는 명령어를 배워 보자.
(1) chage 명령어
(명령어 형식)
# chage [options] user
Options:
-d, --lastday LAST_DAY set last password change to LAST_DAY
-E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-h, --help display this help message and exit
-I, --inactive INACTIVE set password inactive after expiration to INACTIVE
-l, --list show account aging information
-m, --mindays MIN_DAYS set minimum number of days before password change to MIN_DAYS
-M, --maxdays MAX_DAYS set maximim number of days before password change to MAX_DAYS
-W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS
(명령어 사용예)
# chage -M 30 -W 7 user01
# chage -E 2010-03-30 user01
# chage -l user01
(/etc/shadow)
user01:$1$eG0hsAqw$Cfawvh5OsIye2rKYcRPH.0:Last Change:MIN:MAX:WARN:INATIVE:Expire Date:
user01:$1$eG0hsAqw$Cfawvh5OsIye2rKYcRPH.0:14650:0:99999:7:::
user01:$1$eG0hsAqw$Cfawvh5OsIye2rKYcRPH.0:14650:30:90:7:30:15000:
다음은 패스워드 에이징(Password Aging)에 대한 설명 그림이다.
현재(암호가 변경된 날짜)
|
| 30(MIN) 90(MAX) 2014.12.31(ExpireDate)
| | | |
|------------------------+------------------+-------+----------------------------+---
| |7(WARN)|
90(MAX) 30(Inactive) 2014.12.31(ExpireDate)
| | |
|------------------------+-------------------------------------------------------+
|
30(MIN) 지나지 않으면 비밀번호 변경 불가, 변경하면 다시 리셋 30(MIN) 지나야 변경 가능, 자주 변경하는걸 막으려고
최대 90(MAX) 까지는 같은 비밀번호 사용 가능. 기간중 변경하면 다시 90(MAX)의 유예기간이 주어진다
90(MAX)의 7(WARN)전부터 90(MAX) 까지는 로그인에는 이상없지만 경고메시지를 준다
90(MAX)의 30(Inactive)까지는 반드시 비밀번호를 변경해야만 한다 90(MAX)+30(Inactive)를 지나면 Inactive 상태
ExpireDate 는 지나면 무조건 못쓴다. 유예기간이 없다. 만료기간
[EX1] 패스워드 변경후 다시 변경할 수 있는 최소 날짜(Min Chage 설정)
(전제조건) user01/user02/user03 사용자가 존재해야 한다.
- 기존의 사용자 모두 삭제(user01, user02, user03, ..... user100, user101)
# userdel -r user01
- 새로운 사용자 추가(user01, user02, user03)
# useradd user01
# passwd user01
[root@linux220 ~]# cat /etc/passwd | tail
fedora:x:500:500:fedora:/home/fedora:/bin/bash
tomcat:x:91:91:Tomcat:/usr/share/tomcat5:/bin/sh
user01:x:501:501::/home/user01:/bin/bash
user02:x:502:502:testuser:/home/user02:/bin/sh
user03:x:503:503::/users/test:/bin/tcsh
user05:x:504:504::/home/user05:/bin/bash
user06:x:505:505::/home/user06:/bin/bash
user100:x:506:506::/home/user100:/bin/bash
user101:x:507:507::/home/user101:/bin/bash
user08:x:508:508::/users/user08:/bin/sh
[root@linux220 ~]# userdel -r user01
[root@linux220 ~]# userdel -r user02
[root@linux220 ~]# userdel -r user03
[root@linux220 ~]# userdel -r user05
[root@linux220 ~]# userdel -r user06
[root@linux220 ~]# userdel -r user100
[root@linux220 ~]# userdel -r user101
[root@linux220 ~]# userdel -r user08
[root@linux220 ~]# cat /etc/passwd | tail
named:x:25:25:Named:/var/named:/sbin/nologin
hsqldb:x:96:96::/var/lib/hsqldb:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
avahi-autoipd:x:100:102:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
fedora:x:500:500:fedora:/home/fedora:/bin/bash
tomcat:x:91:91:Tomcat:/usr/share/tomcat5:/bin/sh
[root@linux220 ~]# useradd user01
[root@linux220 ~]# useradd user02
[root@linux220 ~]# useradd user03
[root@linux220 ~]# passwd user01
Changing password for user user01.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# passwd user02
Changing password for user user02.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# passwd user03
Changing password for user user03.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# cat /etc/passwd | tail
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
avahi-autoipd:x:100:102:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
fedora:x:500:500:fedora:/home/fedora:/bin/bash
tomcat:x:91:91:Tomcat:/usr/share/tomcat5:/bin/sh
user01:x:501:501::/home/user01:/bin/bash
user02:x:502:502::/home/user02:/bin/bash
user03:x:503:503::/home/user03:/bin/bash
[root@linux220 ~]# chage -l user01
마지막으로 열쇠글을 바꾼 날 : 4월 28, 2016
열쇠글 만료 :안함
열쇠글이 비활성화 기간 :안함
계정 만료 :안함
열쇠글을 바꿀 수 있는 최소 날 수 : 0
열쇠글을 바꿔야 하는 최대 날 수 : 99999
열쇠글 만료 예고를 하는 날 수 : 7
[root@linux220 ~]# chage -m 7 user01
[root@linux220 ~]# chage -l user01
마지막으로 열쇠글을 바꾼 날 : 4월 28, 2016
열쇠글 만료 :안함
열쇠글이 비활성화 기간 :안함
계정 만료 :안함
열쇠글을 바꿀 수 있는 최소 날 수 : 7
열쇠글을 바꿔야 하는 최대 날 수 : 99999
열쇠글 만료 예고를 하는 날 수 : 7
[root@linux220 ~]# cat /etc/shadow | grep user01
user01:$1$RoFn2oXa$r1VhNVDGbMpXIr2baZqLx1:16919:7:99999:7:::
[root@linux220 ~]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
linux220.example.com (Linux release 2.6.18-409.el5 #1 SMP Tue Mar 15 18:22:22 EDT 2016) (2)
login: user01
Password:
|---> /etc/profile read
|---> /etc/profile.d/*.sh read
|---> /etc/bashrc read
[user01@linux220 ~]$ passwd
Changing password for user user01.
Changing password for user01
(current) UNIX password:
You must wait longer to change your password
passwd: Authentication token manipulation error
[user01@linux220 ~]$ exit
logout
Connection closed by foreign host.
[EX2] 패스워드 변경 후 다시 변경할 수 있는 최소 날짜(MAX Chage 설정)
# chage -M 30 user02 (-M : MAX Change)
[root@linux220 ~]# chage -M 30 user02
[root@linux220 ~]# chage -l user02
마지막으로 열쇠글을 바꾼 날 : 4월 28, 2016
열쇠글 만료 : 5월 28, 2016
열쇠글이 비활성화 기간 :안함
계정 만료 :안함
열쇠글을 바꿀 수 있는 최소 날 수 : 0
열쇠글을 바꿔야 하는 최대 날 수 : 30
열쇠글 만료 예고를 하는 날 수 : 7
[root@linux220 ~]# date
2016. 04. 28. (목) 18:20:05 KST
[root@linux220 ~]# date 05251300
2016. 05. 25. (수) 13:00:00 KST
[root@linux220 ~]# date
2016. 05. 25. (수) 13:00:04 KST
[root@linux220 ~]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
linux220.example.com (Linux release 2.6.18-409.el5 #1 SMP Tue Mar 15 18:22:22 EDT 2016) (2)
login: user03
Password:
|---> /etc/profile read
|---> /etc/profile.d/*.sh read
|---> /etc/bashrc read
[user03@linux220 ~]$ exit
logout
Connection closed by foreign host.
[root@linux220 ~]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
linux220.example.com (Linux release 2.6.18-409.el5 #1 SMP Tue Mar 15 18:22:22 EDT 2016) (2)
login: user02
Password:
[Warning: your password will expire in 3 days]
|---> /etc/profile read
|---> /etc/profile.d/*.sh read
|---> /etc/bashrc read
[user02@linux220 ~]$ exit
logout
Connection closed by foreign host.
[root@linux220 ~]# chage -l user02
마지막으로 열쇠글을 바꾼 날 : 4월 28, 2016
열쇠글 만료 : 5월 28, 2016
열쇠글이 비활성화 기간 :안함
계정 만료 :안함
열쇠글을 바꿀 수 있는 최소 날 수 : 0
열쇠글을 바꿔야 하는 최대 날 수 : 30
열쇠글 만료 예고를 하는 날 수 : 7
[root@linux220 ~]# date 06051300
2016. 06. 05. (일) 13:00:00 KST
[root@linux220 ~]#
[root@linux220 ~]#
[root@linux220 ~]#
[root@linux220 ~]#
[root@linux220 ~]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
linux220.example.com (Linux release 2.6.18-409.el5 #1 SMP Tue Mar 15 18:22:22 EDT 2016) (2)
login: user02
Password:
[You are required to change your password immediately (password aged)]
[Changing password for user02]
(current) UNIX password:
New UNIX password:
Retype new UNIX password:
Last login: Wed May 25 13:00:26 from localhost.localdomain
|---> /etc/profile read
|---> /etc/profile.d/*.sh read
|---> /etc/bashrc read
[user02@linux220 ~]$ acbd1324
[user02@linux220 ~]$ exit
logout
Connection closed by foreign host.
[root@linux220 ~]# rdate -s time.bora.net
[root@linux220 ~]#
[root@linux220 ~]#
[root@linux220 ~]#
[root@linux220 ~]# date
2016. 04. 28. (목) 18:23:24 KST
[root@linux220 ~]# chage -E 2016-11-30 user03
[root@linux220 ~]# chage -l user03
마지막으로 열쇠글을 바꾼 날 : 4월 28, 2016
열쇠글 만료 :안함
열쇠글이 비활성화 기간 :안함
계정 만료 :11월 30, 2016
열쇠글을 바꿀 수 있는 최소 날 수 : 0
열쇠글을 바꿔야 하는 최대 날 수 : 99999
열쇠글 만료 예고를 하는 날 수 : 7
[root@linux220 ~]# date 12301300
2016. 12. 30. (금) 13:00:00 KST
[root@linux220 ~]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
linux220.example.com (Linux release 2.6.18-409.el5 #1 SMP Tue Mar 15 18:22:22 EDT 2016) (2)
login: user03
Password:
[Your account has expired; please contact your system administrator]
Login incorrect
Connection closed by foreign host.
[root@linux220 ~]# rdate -s time.bora.net
[root@linux220 ~]#
[root@linux220 ~]# date
2016. 04. 28. (목) 18:25:13 KST
(원복)
[root@linux220 ~]# userdel -r user01
[root@linux220 ~]# userdel -r user02
[root@linux220 ~]# userdel -r user03
[root@linux220 ~]# useradd user01
[root@linux220 ~]# useradd user02
[root@linux220 ~]# useradd user03
[root@linux220 ~]# passwd user01
Changing password for user user01.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# passwd user02
Changing password for user user02.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# passwd user03
Changing password for user user03.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@linux220 ~]# rdate -s time.bora.net
[root@linux220 ~]#
Job Scheduling
정기적인 작업을 수행하는 경우 (EX : 스케줄링)
(예) 하루에 한번씩 풀 백업 (Full Backup)
● 특정한 시간때에 한번 작업을 수행하는 경우 --> at CMD (atd)
● 반복적인 작업을 수행하는 경우 --> crontab CMD (crond)
at 은 crontab 에 포함되기 때문에 잘 안쓰인다고 함
(명령어 사용예)
■ 작업 선언
# at 1300
# at 10:00pm today
# at now +1 mins
■ 작업 확인
# at -l
# atq
■ 작업 취소
# atrm N (N : Job ID)
# at -r N
그림4
그림5
[root@linux220 ~]# at 1500
at> echo
at> <EOT>
job 2 at 2016-04-29 15:00
[root@linux220 ~]# at 1600
at> echo
at> <EOT>
job 3 at 2016-04-29 16:00
[root@linux220 ~]# at -l
2 2016-04-29 15:00 a root
3 2016-04-29 16:00 a root
[root@linux220 ~]# atq
2 2016-04-29 15:00 a root
3 2016-04-29 16:00 a root
[root@linux220 ~]# atrm 2
[root@linux220 ~]# at -r 3
[root@linux220 ~]# at -l
[root@linux220 ~]# atq
[EX] at 명령어 사용자 제한
.deny만 있다면 .deny에 포함되어있는 유저는 못써
.allow가 있다면 .allow에 포함되어있는 유저만 써
둘 다 없다면 권한이 있는 유저(root)만 써
-> at.allow 파일이 없고, at.deny 파일만 존재하는 경우에는 at.deny 파일에 등록된 사용자만 at 명령어를 수행할 수 없다
-> at.deny 파일에 기본적으로 사용자 등록이 없기 때문에 at 명령어 사용에 대한 거부할 사용자가 없어서,
모든 사용자가 at 명령어를 사용할 수 있는 설정이다
-> at.allow 파일이 존재하는 경우, at.allow 파일에 등록된 사용자만 at 명령어 수행이 가능하고, 등록되지 않은 모든 사용자는 사용할 수 없다
[root@linux220 ~]# ls -l /etc/at.*
-rw------- 1 root root 1 10월 8 2014 /etc/at.deny
[root@linux220 ~]# cat /etc/at.deny
[root@linux220 ~]# vi /etc/at.allow
[root@linux220 ~]# cat /etc/at.allow
user01
user02
[root@linux220 ~]# su - user01
|---> /etc/profile read
|---> /etc/profile.d/*.sh read
|---> /etc/bashrc read
[user01@linux220 ~]$ at 1300
at> echo
at> <EOT>
job 4 at 2016-04-29 13:00
[user01@linux220 ~]$ at -l
4 2016-04-29 13:00 a user01
[user01@linux220 ~]$ su - user03
암호:
|---> /etc/profile read
|---> /etc/profile.d/*.sh read
|---> /etc/bashrc read
[user03@linux220 ~]$ id
uid=503(user03) gid=503(user03) groups=503(user03)
[user03@linux220 ~]$ at 1300
You do not have permission to use at.
[user03@linux220 ~]$ T_T
(원복)
[root@linux220 ~]# rm /etc/at.allow
rm: remove 일반 파일 `/etc/at.allow'? y
cron 데몬
cron 데몬은 같은 작업을 주기적으로 반복 실행되도록 하는 작업 스케줄용 데몬으로,
매분, 매시, 매일, 매주, 매 월, 매요일 단위로 cron 데몬에 의해서 작업이 실행될 수 있다.
/etc 디렉토리에 보면 시, 일, 주, 월, 요일 단위 형태로 cron 디렉토리가 존재하며,
이들 디렉토리에는 작업 예약 스크립트들이 들어 있다.
/etc/cron/daily 디렉토 리안에는 여러 가지 스크립트들이 존재하는데,
매일 이들 스크립트는 cron 데몬에 의해서 자동적으로 실행된다.
(cron 데몬실행)
cron으로 작업 스케줄을 예약하기 위해서는 crond 데몬을 작동시켜야 하는데 다음과 같이 데몬을 재실행해 주면 된다.
이 작동하고 있어야 한다. 그러므로, 작업 스케줄을 예약하기 전에 항상 cron 데몬이 작동될 수 있도록 다음과 같이 처리한다.
# service crond restart
(명령어 형식)
# crontab [-u user] file
# crontab [-u user] [ -e | -l | -r ]
-e (edit user's crontab)
-l (list user's crontab)
-r (delete user's crontab)
-i (prompt before deleting user's crontab)
-s (selinux context)
(명령어 사용예)
■ 작업 선언
# crontab -e (-e : Edit, # vi /var/spool/cron/<사용자이름>)
# crontab -e -u user01
■ 작업 확인
# crontab -l (-l : List, # cat /var/spool/cron/<사용자이름>)
■ 작업 삭제
# crontab -r (주의) (-r : Remove, # rm /var/spool/cron/<사용자이름>)
[root@linux220 ~]# cd /var/spool
[root@linux220 /var/spool]# ls
anacron clientmqueue cups mail news rwho squid
at cron lpd mqueue repackage samba vbox
[root@linux220 /var/spool]# cd at
[root@linux220 /var/spool/at]# ls
a000040173c7f0 spool
[root@linux220 /var/spool/at]# at -l
4 2016-04-29 13:00 a user01
[root@linux220 /var/spool/at]# at -r 4
[root@linux220 /var/spool/at]# ls
spool
[root@linux220 /var/spool/at]# at -l
[root@linux220 /var/spool/at]# cd ..
[root@linux220 /var/spool]# cd cron
[root@linux220 /var/spool/cron]# ls
[root@linux220 /var/spool/cron]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@linux220 /var/spool/cron]# ls
root
[root@linux220 /var/spool/cron]# cat root
#
# (1) Test Scheduling
#
* * * * * date >> /tmp/date.log
[root@linux220 /var/spool/cron]# crontab -l
#
# (1) Test Scheduling
#
* * * * * date >> /tmp/date.log
[root@linux220 /var/spool/cron]#
[root@linux220 /var/spool/cron]# crontab -r
[root@linux220 /var/spool/cron]# ls
[root@linux220 /var/spool/cron]# crontab -l
no crontab for root
[root@linux220 /var/spool/cron]#
# crontab -e (/var/spool/cron/<사용자이름>)
55 15 * * * echo "hello test" > /dev/pts/5
[분] [시] [일] [월] [요일] [명령어]
-> 초기 생성이기 때문에 특별한 내용은 들어 있지 않다. crontab 설정을 생성해 줘야 한다.
-> [분] (ㄱ) 0 [시] (ㄱ) 1
(ㄴ) 1-3 (ㄴ) 1-3
(ㄷ) 1,5,10 (ㄷ) 0,12
(ㄹ) * (0-59) (ㄹ) * (0-23) //매분, 매시
[분] [시] [일] [월] [요일] [명령어]
필드 범위
분 0-59 (*)
시 0-23 (*)
일 1-31 (*)
월 1-12 (*)
요일 0-7 (*) // (0,7) : 일요일, 1 : 월요일, 2 : 화요일
작업내용 명령어
참조 http://byseob.blogspot.kr/2010/08/crontab%ED%81%AC%EB%A1%A0%ED%83%AD-%EC%82%AC%EC%9A%A9-%EB%B0%A9%EB%B2%95.html
참조 http://egloos.zum.com/program/v/802690
예문에 매일 오후 4,5,6시 라는건 매일 오전 4,5,6시 인거 같음 24시간 표기법을 쓰는데 오후라니..
테스트를 해보긴 해야할듯
[EX] at 명령어의 실무예 (백업 스크립트 실행)
# cat /root/bin/backup.sh
(백업 스크립트 내용 예제)
cd /home
tar cvzf /backup/home.`date +%m%d`.tar.gz
(현재) # /root/bin/backup.sh
(지정된 시간) # echo /root/bin/backup.sh | at 1200 (# echo /root/bin/backup.sh | at noew +2 min)
[root@linux220 ~]# vi /root/bin/backup.sh
[root@linux220 ~]# cp /root/bin/backup.sh root/bin/backup.sh.old
cp: cannot create regular file `root/bin/backup.sh.old': 그런 파일이나 디렉토리가 없음
[root@linux220 ~]# cp /root/bin/backup.sh /root/bin/backup.sh.old
[root@linux220 ~]# vi /root/bin/backup.sh
[root@linux220 ~]# chmod 755 /root/bin/backup.sh
[root@linux220 ~]# ls -ld /home
drwxr-xr-x 7 root root 1.0K 4월 28 18:26 /home
[root@linux220 ~]# ls -ld /backup
drwxr-xr-x 2 root root 4.0K 4월 25 17:26 /backup
[root@linux220 ~]# cat /root/bin/backup.sh
#!/bin/bash
cd /home
tar cvzf /backup/home.`date +%m%d_%H%M$`.tar.gz . > /backup/backup.log 2>&1
[root@linux220 ~]# vi /root/bin/backup.sh
[root@linux220 ~]# cat /root/bin/backup.sh
#!/bin/bash
cd /home
tar cvzf /backup/home.`date +%m%d_%H%M%S`.tar.gz . > /backup/backup.log 2>&1
[root@linux220 ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@linux220 ~]# cd /backup
[root@linux220 /backup]# ls
back-0419.tar.gz home.0428_205001.tar.gz lv1.tar.gz
backup.log linux220.tar.gz
[root@linux220 /backup]# ls
back-0419.tar.gz home.0428_205001.tar.gz linux220.tar.gz
backup.log home.0428_205101.tar.gz lv1.tar.gz
[root@linux220 /backup]# ls
back-0419.tar.gz home.0428_205001.tar.gz home.0428_205201.tar.gz lv1.tar.gz
backup.log home.0428_205101.tar.gz linux220.tar.gz
[root@linux220 /backup]# crontab -e
crontab: installing new crontab
[root@linux220 /backup]#
[root@linux220 /backup]# mkdir /etc/MESS
[root@linux220 /backup]# scp 172.16.9.252:/root/shell/CoffeeTime.txt /etc/MESS
root@172.16.9.252's password:
CoffeeTime.txt 100% 840 0.8KB/s 00:00
[root@linux220 /backup]# cat /etc/MESS/CoffeeTime.txt
,,)))))));,
))))))))))))));,
(((((''''((((((((
(('' . `)))))),
| @ ;-. (((((
`| / ) )))/~~~~~~~~~~__\__---~~__--~~--_
| | | (/ /__-----~~ ,;::' \
o_); ; / / \,-~~~\ |
; ( / `:::| |;|
| _ `----~~~~' / `:| \;\
______/\/~ / / \/
/~;;.____/;;' / ___----( `;;;/
/ // _;______;'------~~~~~ |;;/\ /
// | | / | \;;,\
(<_ | ; /',/-----' _>
\_| ||_ //~;~~~~~~~~~
`\_| (,~~
[root@linux220 /backup]# crontab -e
crontab: installing new crontab
[root@linux220 /backup]# crontab -l
50 16-18 * * 1-5 wall < /etc/MESS/CoffeeTime.txt
20 20-22 * * 1-5 wall < /etc/MESS/CoffeeTime.txt
50 18 * * 1-5 wall 19:00~19:30 Dinner
DB 사용자로 로그인/백업
# crontab -e
01 04 * * * /root/bin/DB_backup.sh
# vi /root/bin/DB_backup.sh
---------------------------------------------
#!/bin/bash
sqlplus /as sysdba << EOF
CMD ;
CMD ;
CMD ;
EOF
---------------------------------------------
수업 종료 후 서버 Power OFF
(Linux)
# echo "/sbin/poweroff" | at now +5 minutes //5분뒤에
# at -r <N>
(Windows)
C:\>shutdown /s /t 600 //10분뒤에
C:\>shutdown /a //shutdown 취소
백업과 복구
▶ 백업이 필요한 이유
- 예기치 못한 천재지변
- 관리자의 실수
- 기계적 오류
- 소프트웨어 버그
▶ 주요 백업 대상
- 전체 파일 시스템
- 마지막 백업 후의 변경된 파일 시스템
- 어플리케이션
- 각종 환경 설정 파일
- 사용자 파일 등
▶ 데이터 손실의 주요 원인
- 하드웨어적인 사유
- 소프트웨어적인 사유
- 사용자의 부주의
- 해커의 침입
- 기타 도난, 자연재해
(주의) 백업시간 && 복구시간
백업은 복구를 위해서 존재한다. 하지만 백업은 거의 매일 같이 하고, 복구는 일년에 한번 있을까 말까하는 작업이다.
백업시간이 긴 형태로 작업을 하면 보통은 복구시간은 줄어 들고, 백업시간을 짧게 하는 방식을 택하 면 보통은 복구시간이 길어 진다.
따라서 백업시간과 복구시간은 적당하게 조절할 필요가 있다.
30분-3시간 이내가 적당
일반적으로 백업 종류는
(ㄱ) 완전 백업(Full Backup),
(ㄴ) 증분 백업(Incremental Backup)
(ㄷ) 차등 백업(Differential Backup)
등이 있다.
(1) 완전 백업(Full Backup)
모든 데이터를통째로 한 번에 백업하는 방법을 말한다. 말 그대로 모든 것을 백업하기 때문에 백업하는데 오래
ltrks이 걸리며, 백업 매체의용량 또한 커야 하므로,비용 소모가 많은 것이 단점이다. 그러나 시스템에 문제가 발 생되었을 때 발생되기 이전의 상태로 시스템을 확실히 복구할 수 있는 장점이 있다. 리눅스를 설치한 후에는 완전
백업을 하는 것이 향후에 리눅스를 재설치 해야 할 경우를 리눅스를 다시 설치하지 않고서도 백업을 복원시켜 부트 로더만 수정해 주면 설치 원상태로 되돌려 놓을 수 있는 이점이 있다.
(2) 증분 백업(Incremental Backup)
일반적으로 백업은 완전 백업과 증분 백업을 병행하는데, 증분 백업은 완전 백업한 이후에 변경된 데이터만을 백업 하는 방법이다. 최근 백업이후에 변경된 파일에 대해서만 백업이 이뤄지기 때문에 빠른 시간 내에 백업이 이뤄지는
장점이 있다. 리눅스 설치 이후에 생성되는 데이터이후에 파일에 대해서 증분 백업으로 백업을 도모하는 것이 리눅
스 시스템에 문제가 발생되더라도 리눅스를 다시 설치하지 않고서도 완전 백업을 복원하여 그 이후의 생성된 데이 터이후에 파일을 문제 방생 이전의 상태로 되돌려 놓을 수 있게 된다.
(3) 차등 백업(Differential Backup)
보통 증분백업과 비슷하기 때문에 혼동하는 경우가 없지 않는데, 차등 백업은 완전 백업이 이뤄진 이후의 모든 데
이터에 대해서 백업이 이뤄지도록 하는 방법이다. 증분 백업으로 백업된 데이터가 있더라도 차등 백업은 이러한 것 을 가리지 않고, 전체 백업 이후의 모든 데이터를 백업하는 것을 말한다. 차등 백업은 완전 백업 이후의 모든 파일
에 대해서 백업이 이뤄지기 때문에 데이터를 복원하는데 있어서는 시간이 오래 걸리는 불편함이 있을 수 있다.
(1) 백업/복구 명령어 종류
(백업 명령어의 특징)
■ tar 명령어 마운트된 파일시스템내에서 백업하는 명령어
■ cpio 명령어 마운트된 파일시스템내에서 백업하는 명령어
■ dump/restore 명령어 파일시스템 단위(파티션 단위)로 백업하는 명령어
■ dd 명령어 디스크 마이그레이션(Migration)하는 명령어
이 문서에서는 가장 많이 사용되고 있는 tar 명령어를 통한 백업 부분만을 다룬다.
(2) tar 명령어
(백업 방법)
# cd /home
# tar cf /mnt/backup/home-backup.tar . (# tar cfz /mnt/backup/home-backup.tar.gz . )
(주의) 백업 받을 당시에 절대 경로 형태로 백업받지 않는다.
(복구 방법)
# cd /home
# tar tf /mnt/backup/home-backup.tar
# tar xf /mnt/backup/home-backup.tar
[EX1] tar 명령어를 이용한 풀백업(Full Backup) & 증분 백업(Incremental Backup)
매일 매일 증가하는 데이터가 큰 서버에서 풀백업을 매일 같이 받는 방법은 좋은 방법이 아니다. 중간에 적당하게
증분 백업을 섞어 쓰는 방법이 좋다. tar 명령어를 통해서 풀백업과 증분 백업을 적당하게 섞어 쓰는 방법을 배워
보자.
Target Directory : /home
# tar cvzf /backup/home_`date +%m%d`.tar.gz /home
(백업 방법)
■ 풀백업(Full Backup) 방법
# cd /home
# tar -g /backup/2002-05-11.list -cvzf /backup/2002-05-11-full.tar.gz .
■ 증분백업(Incremental Backup) 방법
# cd /home
# tar -g /backup/2002-05-11.list -czvf /backup/2002-05-12.tar.gz .
(복구 방법)
■ 풀백업(Full Backup) 복구방법
# cd /home
# tar -g /backup/2002-05-11.list -xzvf /backup/2002-05-11-full.tar.gz
■ 증분백업(Incremental Backup) 복구방법
# cd /home
# tar -g /backup/2002-05-11.list -xzvf /backup/2002-05-12.tar.gz
[root@linux220 ~]# cd /home/usr01
bash: cd: /home/usr01: 그런 파일이나 디렉토리가 없음
[root@linux220 ~]# cd /home/user01
[root@linux220 /home/user01]# ls
[root@linux220 /home/user01]# cp -p /etc/passwd file1
[root@linux220 /home/user01]# cp -p /etc/hosts file2
[root@linux220 /home/user01]# cp -p /etc/group file3
[root@linux220 /home/user01]# tar -g /backup/backup.list -cvzf /backup/full_backup.tar.gz /home/user01
tar: /home/user01/.mozilla: Directory is new
tar: /home/user01/.mozilla/plugins: Directory is new
tar: /home/user01/.mozilla/extensions: Directory is new
tar: Removing leading `/' from member names
/home/user01/
/home/user01/.mozilla/
/home/user01/.mozilla/extensions/
/home/user01/.mozilla/plugins/
/home/user01/.bash_history
/home/user01/.bash_logout
/home/user01/.bash_profile
/home/user01/.bashrc
/home/user01/.emacs
/home/user01/file1
/home/user01/file2
/home/user01/file3
[root@linux220 /home/user01]# ls -l /backup
합계 7.1M
-rw-r--r-- 1 root root 45 4월 19 19:36 back-0419.tar.gz
-rw-r--r-- 1 root root 129 4월 28 21:44 backup.list
-rw-r--r-- 1 root root 753 4월 28 20:52 backup.log
-rw-r--r-- 1 root root 2.3K 4월 28 21:44 full_backup.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:50 home.0428_205001.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:51 home.0428_205101.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:52 home.0428_205201.tar.gz
-rw-r--r-- 1 root root 6.0M 4월 20 20:57 linux220.tar.gz
-rw-r--r-- 1 root root 995K 4월 25 17:27 lv1.tar.gz
[root@linux220 /home/user01]# tar tvzf /baclup/full_backup.tar.gz
tar: /baclup/full_backup.tar.gz: Cannot open: 그런 파일이나 디렉토리가 없음
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error exit delayed from previous errors
[root@linux220 /home/user01]# tar tvzf /backup/full_backup.tar.gz
drwx------ user01/user01 93 2016-04-28 21:42:57 home/user01/
drwxr-xr-x user01/user01 22 2016-04-28 18:26:01 home/user01/.mozilla/
drwxr-xr-x user01/user01 1 2016-04-28 18:26:01 home/user01/.mozilla/extensions/
drwxr-xr-x user01/user01 1 2016-04-28 18:26:01 home/user01/.mozilla/plugins/
-rw------- user01/user01 120 2016-04-28 19:51:42 home/user01/.bash_history
-rw-r--r-- user01/user01 33 2016-04-28 18:26:01 home/user01/.bash_logout
-rw-r--r-- user01/user01 176 2016-04-28 18:26:01 home/user01/.bash_profile
-rw-r--r-- user01/user01 186 2016-04-28 18:26:01 home/user01/.bashrc
-rw-r--r-- user01/user01 515 2016-04-28 18:26:01 home/user01/.emacs
-rw-r--r-- root/root 2076 2016-04-28 18:26:04 home/user01/file1
-rw-r--r-- root/root 229 2016-04-19 21:36:45 home/user01/file2
-rw-r--r-- root/root 789 2016-04-28 18:26:04 home/user01/file3
[root@linux220 /home/user01]# cat /backup/backup.list
1461847453
2051 32645 /home/user01/.mozilla/plugins
2051 32646 /home/user01/.mozilla/extensions
2051 32644 /home/user01/.mozilla
[root@linux220 /home/user01]#
[root@linux220 /home/user01]# ls
file1 file2 file3
[root@linux220 /home/user01]# cp /etc/passwd file4
[root@linux220 /home/user01]# ls
file1 file2 file3 file4
[root@linux220 /home/user01]# tar -g /backup/backup.list -cvzf /backup/incremental1.tar.gz /home/user01
tar: Removing leading `/' from member names
/home/user01/
/home/user01/.mozilla/
/home/user01/.mozilla/extensions/
/home/user01/.mozilla/plugins/
/home/user01/file4
[root@linux220 /home/user01]# ls -l /backup
합계 7.1M
-rw-r--r-- 1 root root 45 4월 19 19:36 back-0419.tar.gz
-rw-r--r-- 1 root root 129 4월 28 21:47 backup.list
-rw-r--r-- 1 root root 753 4월 28 20:52 backup.log
-rw-r--r-- 1 root root 2.3K 4월 28 21:44 full_backup.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:50 home.0428_205001.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:51 home.0428_205101.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:52 home.0428_205201.tar.gz
-rw-r--r-- 1 root root 1.1K 4월 28 21:47 incremental1.tar.gz
-rw-r--r-- 1 root root 6.0M 4월 20 20:57 linux220.tar.gz
-rw-r--r-- 1 root root 995K 4월 25 17:27 lv1.tar.gz
[root@linux220 /home/user01]# tar tvzf /backup/incremental1.tar.gz
drwx------ user01/user01 100 2016-04-28 21:46:49 home/user01/
drwxr-xr-x user01/user01 22 2016-04-28 18:26:01 home/user01/.mozilla/
drwxr-xr-x user01/user01 1 2016-04-28 18:26:01 home/user01/.mozilla/extensions/
drwxr-xr-x user01/user01 1 2016-04-28 18:26:01 home/user01/.mozilla/plugins/
-rw-r--r-- root/root 2076 2016-04-28 21:46:49 home/user01/file4
[root@linux220 /home/user01]# cat /backup/backup.list
1461847675
2051 32645 /home/user01/.mozilla/plugins
2051 32646 /home/user01/.mozilla/extensions
2051 32644 /home/user01/.mozilla
[root@linux220 /home/user01]# cp /etc/services file5
[root@linux220 /home/user01]# tar -g /backup/backup.list -cvzf /backup/incremental2.tar.gz /home/user01
tar: Removing leading `/' from member names
/home/user01/
/home/user01/.mozilla/
/home/user01/.mozilla/extensions/
/home/user01/.mozilla/plugins/
/home/user01/file5
[root@linux220 /home/user01]# ls -l /backup
합계 7.2M
-rw-r--r-- 1 root root 45 4월 19 19:36 back-0419.tar.gz
-rw-r--r-- 1 root root 129 4월 28 21:50 backup.list
-rw-r--r-- 1 root root 753 4월 28 20:52 backup.log
-rw-r--r-- 1 root root 2.3K 4월 28 21:44 full_backup.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:50 home.0428_205001.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:51 home.0428_205101.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:52 home.0428_205201.tar.gz
-rw-r--r-- 1 root root 1.1K 4월 28 21:47 incremental1.tar.gz
-rw-r--r-- 1 root root 97K 4월 28 21:50 incremental2.tar.gz
-rw-r--r-- 1 root root 6.0M 4월 20 20:57 linux220.tar.gz
-rw-r--r-- 1 root root 995K 4월 25 17:27 lv1.tar.gz
[root@linux220 /home/user01]# tar tvzf /backup/incremental2.tar.gz
drwx------ user01/user01 107 2016-04-28 21:49:41 home/user01/
drwxr-xr-x user01/user01 22 2016-04-28 18:26:01 home/user01/.mozilla/
drwxr-xr-x user01/user01 1 2016-04-28 18:26:01 home/user01/.mozilla/extensions/
drwxr-xr-x user01/user01 1 2016-04-28 18:26:01 home/user01/.mozilla/plugins/
-rw-r--r-- root/root 362031 2016-04-28 21:49:41 home/user01/file5
[root@linux220 /home/user01]# ls
file1 file2 file3 file4 file5
[root@linux220 /home/user01]# rm -f file5
[root@linux220 /home/user01]# ls
file1 file2 file3 file4
[root@linux220 /home/user01]# tar -g /backup/backup.list -cvzf /backup/incremental3.tar.gz /home/user01
tar: Removing leading `/' from member names
/home/user01/
/home/user01/.mozilla/
/home/user01/.mozilla/extensions/
/home/user01/.mozilla/plugins/
[root@linux220 /home/user01]# ls -l /backup
합계 7.2M
-rw-r--r-- 1 root root 45 4월 19 19:36 back-0419.tar.gz
-rw-r--r-- 1 root root 129 4월 28 21:51 backup.list
-rw-r--r-- 1 root root 753 4월 28 20:52 backup.log
-rw-r--r-- 1 root root 2.3K 4월 28 21:44 full_backup.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:50 home.0428_205001.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:51 home.0428_205101.tar.gz
-rw-r--r-- 1 root root 1.8K 4월 28 20:52 home.0428_205201.tar.gz
-rw-r--r-- 1 root root 1.1K 4월 28 21:47 incremental1.tar.gz
-rw-r--r-- 1 root root 97K 4월 28 21:50 incremental2.tar.gz
-rw-r--r-- 1 root root 284 4월 28 21:51 incremental3.tar.gz
-rw-r--r-- 1 root root 6.0M 4월 20 20:57 linux220.tar.gz
-rw-r--r-- 1 root root 995K 4월 25 17:27 lv1.tar.gz
[root@linux220 /home/user01]# tar tvzf /backup/incremental3.tar.gz
drwx------ user01/user01 100 2016-04-28 21:51:09 home/user01/
drwxr-xr-x user01/user01 22 2016-04-28 18:26:01 home/user01/.mozilla/
drwxr-xr-x user01/user01 1 2016-04-28 18:26:01 home/user01/.mozilla/extensions/
drwxr-xr-x user01/user01 1 2016-04-28 18:26:01 home/user01/.mozilla/plugins/
[root@linux220 /home/user01]# pwd
/home/user01
[root@linux220 /home/user01]# rm -rf *
[root@linux220 /home/user01]# ls
[root@linux220 /home/user01]# cd /
[root@linux220 /]# tar -g /backup/backup.list -xvzf /backup/full_backup.tar.gz
home/user01/
home/user01/.mozilla/
home/user01/.mozilla/extensions/
home/user01/.mozilla/plugins/
home/user01/.bash_history
home/user01/.bash_logout
home/user01/.bash_profile
home/user01/.bashrc
home/user01/.emacs
home/user01/file1
home/user01/file2
home/user01/file3
[root@linux220 /]# ls /home/user01
file1 file2 file3
[root@linux220 /]# tar -g /backup/backup.list -xczf /backup/incremental1.tar.gz
tar: `-Acdtrux' 옵션 중 하나 이상을 지정하면 안 됩니다
Try `tar --help' or `tar --usage' for more information.
[root@linux220 /]# tar -g /backup/backup.list -xvzf /backup/incremental1.tar.gz
home/user01/
home/user01/.mozilla/
home/user01/.mozilla/extensions/
home/user01/.mozilla/plugins/
home/user01/file4
[root@linux220 /]# ls /home/user01
file1 file2 file3 file4
[root@linux220 /]# tar -g /backup/backup.list -xvzf /backup/incremental2.tar.gz
home/user01/
home/user01/.mozilla/
home/user01/.mozilla/extensions/
home/user01/.mozilla/plugins/
home/user01/file5
[root@linux220 /]# ls
backup data3 home lvm1 mirrorlv opt raid5 srv tmp
bin data4 lib lvm2 misc oracle root stripelv users
boot dev lost+found lvm3 mnt proc sbin sys usr
data1 disk1 lv1 lvm4 net raid0 selinux test var
data2 etc lv2 media noatime raid1 setuid testmount
[root@linux220 /]# ls /home/user01
file1 file2 file3 file4 file5
[root@linux220 /]# tar -g /backup/backup.list -xvzf /backup/incremental3.tar.gz
home/user01/
tar: `home/user01/file5'를 지움
home/user01/.mozilla/
home/user01/.mozilla/extensions/
home/user01/.mozilla/plugins/
[root@linux220 /]# ls /home/user01
file1 file2 file3 file4
[EX3] tar 명령어를 통한 데이터 마이그레이션
많은 데이터가 들어 있는 디렉토리를 다른 디렉토리로 마이그레이션 작업을 하기 위해서는
cp 명령어를 사용하 지 않고, 백업하는 명령어를 통해서 옮긴다.
(cp 명령어를 통한 디렉토리 복사)
[root@linux220 ~]# cd /
[root@linux220 /]# mkdir -p /test1 /test2
[root@linux220 /]# cd /test1
[root@linux220 /test1]# cp -p /etc/passwd file1
[root@linux220 /test1]# ln -s file1 file2
[root@linux220 /test1]# cp /bin/ls file3
[root@linux220 /test1]# cp ~/.bashrc .file4
[root@linux220 /test1]# mkdir dir1
[root@linux220 /test1]# chmod 777 file1
[root@linux220 /test1]# cp -r /test1/* /test2
[root@linux220 /test1]# ls -al /test1 /test2
/test1:
합계 124K
drwxr-xr-x 3 root root 4.0K 4월 28 22:01 .
drwxr-xr-x 48 root root 4.0K 4월 28 22:01 ..
-rw-r--r-- 1 root root 530 4월 28 22:01 .file4
drwxr-xr-x 2 root root 4.0K 4월 28 22:01 dir1
-rwxrwxrwx 1 root root 2.1K 4월 28 18:26 file1
lrwxrwxrwx 1 root root 5 4월 28 22:01 file2 -> file1
-rwxr-xr-x 1 root root 93K 4월 28 22:01 file3
/test2:
합계 120K
drwxr-xr-x 3 root root 4.0K 4월 28 22:02 .
drwxr-xr-x 48 root root 4.0K 4월 28 22:01 ..
drwxr-xr-x 2 root root 4.0K 4월 28 22:02 dir1
-rwxr-xr-x 1 root root 2.1K 4월 28 22:02 file1
lrwxrwxrwx 1 root root 5 4월 28 22:02 file2 -> file1
-rwxr-xr-x 1 root root 93K 4월 28 22:02 file3
파일의 속성정보, 시간정보가 다르고 .* 의 설정파일들 복사가 안됨 --> 문제가 생김
* 로 복사하면 설정파일들 복사가 안됨
(tar 명령어를 통한 디렉토리 복사)
- : stdout
[root@linux220 /test1]# rm -rf /test2 ; mkdir /test2
[root@linux220 /test1]# ls -al /test1 /test2
/test1:
합계 124K
drwxr-xr-x 3 root root 4.0K 4월 28 22:01 .
drwxr-xr-x 48 root root 4.0K 4월 28 22:06 ..
-rw-r--r-- 1 root root 530 4월 28 22:01 .file4
drwxr-xr-x 2 root root 4.0K 4월 28 22:01 dir1
-rwxrwxrwx 1 root root 2.1K 4월 28 18:26 file1
lrwxrwxrwx 1 root root 5 4월 28 22:01 file2 -> file1
-rwxr-xr-x 1 root root 93K 4월 28 22:01 file3
/test2:
합계 12K
drwxr-xr-x 2 root root 4.0K 4월 28 22:06 .
drwxr-xr-x 48 root root 4.0K 4월 28 22:06 ..
[root@linux220 /test1]# tar cvf - . | (cd /test2 ; tar xvf -)
./
./file3
./
./file3
./dir1/
./file2
./.file4
./file1
./dir1/
./file2
./.file4
./file1
[root@linux220 /test1]# ls -al /test1 /test2
/test1:
합계 124K
drwxr-xr-x 3 root root 4.0K 4월 28 22:01 .
drwxr-xr-x 48 root root 4.0K 4월 28 22:06 ..
-rw-r--r-- 1 root root 530 4월 28 22:01 .file4
drwxr-xr-x 2 root root 4.0K 4월 28 22:01 dir1
-rwxrwxrwx 1 root root 2.1K 4월 28 18:26 file1
lrwxrwxrwx 1 root root 5 4월 28 22:01 file2 -> file1
-rwxr-xr-x 1 root root 93K 4월 28 22:01 file3
/test2:
합계 124K
drwxr-xr-x 3 root root 4.0K 4월 28 22:01 .
drwxr-xr-x 48 root root 4.0K 4월 28 22:06 ..
-rw-r--r-- 1 root root 530 4월 28 22:01 .file4
drwxr-xr-x 2 root root 4.0K 4월 28 22:01 dir1
-rwxrwxrwx 1 root root 2.1K 4월 28 18:26 file1
lrwxrwxrwx 1 root root 5 4월 28 22:12 file2 -> file1
-rwxr-xr-x 1 root root 93K 4월 28 22:01 file3
디스크I/O 발생하지 않고 메모리를 이용해서 하기 때문에 작업시간이 절반정도 줄어들고
나중에 문제(장치명령어가 안넘어갔거나 하는)가 생기지 않는다
다음시간에...
[EX4] tar 명령어를 이용한 운영체제 전체 백업
운영체제를 백업하기 위해서 /proc, /mnt, /media, tmp 디렉토리는 포함하지 않아도 된다. 제외할 디렉토리의
경우 ‘--exclude=’로 영역을 지정해준다. 지정된 영역을 제외한 나머지 부분이 ‘<백업파일명>.tar.gz'으로
백업되는 것이다.
(명령어 형식)
# tar cvzpf /backup<백업파일명>.tar.gz --exclude=<제외할 디렉토리> --absolute-name /
'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글
20160429 리눅스 네트워크 (0) | 2016.05.01 |
---|---|
20160429 리눅스 관리자 (0) | 2016.05.01 |
20160427 리눅스 관리자 (0) | 2016.04.28 |
20160426 리눅스 관리자 (0) | 2016.04.27 |
20160425 리눅스 관리자 (0) | 2016.04.27 |