본문으로 바로가기

 

특 수 권 한
setUID SetGid Sticy bit
      4         2         1

setuid가 지정되어 있는 파일을 실행하면 해당 파일은 파일 소유자의 권한으로 실행하게 된다.

setgid가 지정되어 있는 파일을 실행하면 해당 파일에 지정되어 있는 그룹의 권한으로 실행하게 된다.

sticky이 비트가 설정되어 있는 상황에서는 접근 권한이 있는 상황에서도 자신의 소유가 아닌 파일을 삭제할 수 없게 된다.

@SetUID/SetGID' 설정

[root@CentOS /]# cd test
[root@CentOS /test]# rm -rf /test/*
[root@CentOS /test]# ls
[root@CentOS /test]# touch file1
[root@CentOS /test]# ls -l file1
-rw-r--r-- 1 root root 0 2017-04-20 10:11 file1
[root@CentOS /test]# chmod 755 file1
[root@CentOS /test]# ls -l file1
-rwxr-xr-x 1 root root 0 2017-04-20 10:11 file1
 0755

@SetUID/SetGID' 설정 II

chmod 4755 file1
[root@CentOS /test]# ls -l file1
-rwsr-xr-x 1 root root 0 2017-04-20 10:11 file1
4755
---> 소유자부분은 x대신에 s가 붙으며 file1은 root 사용자의 권한으로 실행된다.


@ 'SetUID/SetGID' 설정 III

[root@CentOS /test]# chmod 2755 file1
[root@CentOS /test]# ls -l file1
-rwxr-sr-x 1 root root 0 2017-04-20 10:11 file1
---> 그룹부분을 보면 x대신에 s가 붙으며 file1은 지정되어 있는 root 그룹의  가진  권한으로 실행


@ 'SetUID/SetGID' 설정 IV

[root@CentOS /test]# chmod 6755 file1
[root@CentOS /test]# ls -l file1
-rwsr-sr-x 1 root root 0 2017-04-20 10:11 file1

---> file1은 사용자의 권한(root)과 지정되어 있는 그룹(root)의 가진 권한으로 실행


--SetUID/SetGID' 이해 I
@user1
chsh   ---> 쉘변경 명령어
Changing shell for user1.
암호:
New shell [/bin/bash]: /bin/csh
Shell changed.

@root
whereis chsh
chsh: /usr/bin/chsh /usr/share/man/man1/chsh.1.gz
[root@CentOS /root]# ls -l /usr/bin/chsh
-rws--x--x. 1 root root 20056 2014-10-15 19:38 /usr/bin/chsh
--> 기본적으로 1711이 실행이 되는듯.  다른 사용자는 읽기만된다..

[root@CentOS /usr/bin]# chmod u-s chsh
[root@CentOS /usr/bin]# ls -l chsh
-rwx--x--x. 1 root root 20056 2014-10-15 19:38 chsh

@user1
user1@CentOS /home/user1]# chsh
Changing shell for user1.
암호:
New shell [/bin/csh]: /bin/bash
setpwnam: 허가 거부  why??? root계정에서 다른사용자의 실행 권한만 주었기 때문이다.
Shell *NOT* changed.  Try again later.


@root

root@CentOS /usr/bin]# chmod u+s chsh
[root@CentOS /usr/bin]# ls -l chsh
-rws--x--x. 1 root root 20056 2014-10-15 19:38 chsh
----> root사용자가 set uid 4번을 주게 되면 다른사용자에게도 읽기가 가능하다.


@user1


user1@CentOS /home/user1]# chsh
Changing shell for user1.
암호:
New shell [/bin/csh]: /bin/bash
Shell changed.
[user1@CentOS /home/user1]# grep -w user1 /etc/passwd
user1:x:500:500::/home/user1:/bin/bash

- SetUID 가 설정된 파일은 root 권한이 할당된 개념이므로 다른 계정으로 접속하여 사용할 수 있다.

 


@ Sticky Bits: 다른 사용자에서 수정,삭제,이동이 안된다. Sticky Bits 는 디렉토리 퍼미션이 '777'인 경우 사용할 수 있다.
파일에 쓰기 권한이 없어도 디렉토리 쓰기 권한이 있는 경우, 디렉토리 권한에 의해서 파일을 삭제할 수 있다.
만약, 특정 디렉토리를 공유 목적으로 사용할 경우, 사용자들에 의해서 파일이 생성될 수 있으나, 디렉토리
파일을 삭제할 수 없도록 제한하려면 'Sticky' 권한을 설정해야 한다.

예제1) Sticky bit' 설정

[root@CentOS /test]# mkdir dir1
[root@CentOS /test]# ls -ld dir1
drwxr-xr-x 2 root root 4096 2017-04-20 10:43 dir1

[root@CentOS /test]# chmod 1777 dir1
[root@CentOS /test]# ls -ld dir1
drwxrwxrwt 2 root root 4096 2017-04-20 10:43 dir1


[root@CentOS /test]# chmod 1001 dir1
[root@CentOS /test]# ls -ld dir1   
d--------t 2 root root 4096 2017-04-20 10:43 dir1

[root@CentOS /test]# chmod 1776 dir1
[root@CentOS /test]# ls -ld dir1
drwxrwxrwT 2 root root 4096 2017-04-20 10:43 dir1


실행속성이 없는 파일에 Sticky bit가 설정되면 대문자 T가 오른쪽에 표시되며
실행속성이 있는 파일에 Sticky bit가 설정되면 소문자 t가 표시된다.

예제2) Sticky bit'를 이용한 파일 삭제 권한 제거
[root@CentOS /]# ls -ld /tmp
drwxrwxrwt. 18 root root 4096 2017-04-20 10:42 /tmp
- /tmp 디렉토리는 기본적으로 Sticky bit 가 설정되어 있다


@user2로 접속

user2@CentOS /home/user2]$
[user2@CentOS /home/user2]$ id
uid=501(user2) gid=501(user2) groups=501(user2)
[user2@CentOS /home/user2]$ cd /tmp
[user2@CentOS /tmp]$ mkdir stickybit
[user2@CentOS /tmp]$ echo 1111 > file1
[user2@CentOS /tmp]$ echo 2222 > stickybit/file2
[user2@CentOS /tmp]$ ls -l | grep user2
-rw-rw-r--. 1 user2 user2 5 2016-01-21 20:04 file1  다른사용자는 실행권한없음.
   6  6  4
drwxrwxr-x. 2 user2 user2 4096 2016-01-21 20:04 stickybit 다른사용자는 stickybit폴더는 읽기와 실행만 가능
   7  7  5


@user1로 접속

[user1@CentOS /home/user1]# cd /tmp
[user1@CentOS /tmp]# mkdir linux
[user1@CentOS /tmp]# echo 3333 > file3
[user1@CentOS /tmp]# echo 4444 > linux/file4
[user1@CentOS /tmp]#
[user1@CentOS /tmp]# ls -l | grep user1
-rw-rw-r--  1 user1 user1        5 2017-04-20 10:52 file3  다른사용자는 실행권한없음.
drwxrwxr-x  2 user1 user1     4096 2017-04-20 10:52 linux  다른사용자는 linux폴더는 읽기와 실행만 가능

 

[user1@CentOS /tmp]$ vi file3
1 3333
2 4444 <--- 추가
: wq!
[user1@CentOS /tmp]$ cat file3
3333
4444

[user1@CentOS /tmp]$ ls -l | grep user
-rw-rw-r--. 1 user2 user2 5 2016-01-21 20:30 file1
-rw-rw-r--. 1 user1 user1 10 2016-01-21 20:32 file3
drwxrwxr-x. 2 user1 user1 4096 2016-01-21 20:31 linux
drwxrwxr-x. 2 user2 user2 4096 2016-01-21 20:30 stickybit
[user1@CentOS /tmp]$ rm -rf linux
[user1@CentOS /tmp]$ rm file3
[user1@CentOS /tmp]$ ls -l file1
-rw-rw-r--. 1 user2 user2 5 2016-01-21 20:04 file1

[user1@CentOS /tmp]$ rm file1
rm: remove write-protected 일반 파일 `file1'? y
rm: cannot remove `file1': 명령을 허용하지 않음 ----> write 권한이 없다.

[user1@CentOS /tmp]$ rm -rf stickybit
rm: cannot remove `stickybit/file2': 허가 거부  ----> 기본적으로 tmp폴더는 root계정에서 stickybit가 설정되어있고
                                                      user2에서 sticky폴더는 읽기와 실행만 가능햇기때문에 삭제 불가능

[user1@CentOS /tmp]$ mv file1 file2
mv: cannot move `file1' to `file2': 명령을 허용하지 않음  ---> 기본적으로 tmp폴더는 root계정에서 stickybit가 설정되어있고
                                                               file1은 user2계정이며 다른사용자는 읽기만 가능하기 때문에 파일을 변경할 수 없다.


계정 생성 및 관리

리눅스에서 계정은 다음과 같이 root, system, user 계정 3 가지로 구분된다.


root : 관리자 계정이며, 모든 권한을 행사할 수 있다.
system : 시스템 운영시 필요한 계정이며, 로그인은 불가능하다.
user : 일반계정이며, root처럼 모든 권한을 행사할 수 있다.


/etc/passwd : 계정 전체 정보 관리 파일
/etc/shadow : 계정 패스워드 관리 파일
/etc/group ; 계정 그룹 관리 파일


[root@CentOS /root]# head -5 /etc/passwd ; tail -3 /etc/passwd

root:x:0:0:root:/root:/bin/bash  ---> root계정
bin:x:1:1:bin:/bin:/sbin/nologin   ---> system 계정
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
tcpdump:x:72:72::/:/sbin/nologin
user1:x:500:500::/home/user1:/bin/bash  ---> 사용자 계정
user2:x:501:501::/home/user2:/bin/bash

[root@CentOS /root]# useradd ccent --> 기본값으로 계정 생성
[root@CentOS /root]# useradd -d /var/user1 ccna
// 홈디렉토리를 /var/user1 를 사용하여 계정 생성 즉, 디렉토리 위치를 지정한다.
root@CentOS /root]# useradd -d /var/user2 -s /bin/csh ccnp
// 홈디렉토리를 /var/user2 를 사용하며, 로그인 쉘을 csh인 ccnp 계정 설정
[root@CentOS /root]# useradd -e 2017-04-21 -c "jang yong je" ccie
// 계정만료일과 주석 설정하여 ccie라는 계정을 만든다.
[root@CentOS /root]# useradd -u 1000 ccde
// 계정 uid 설정 (기본적으로 앞에 계정에 1 을 더해진 값으로 생성됨
root@CentOS /root]# cat /etc/passwd | tail -7
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash
ccent:x:502:502::/home/ccent:/bin/bash
ccna:x:503:503::/var/user1:/bin/bash
ccnp:x:504:504::/var/user2:/bin/csh
ccie:x:505:505:jang yong je:/home/ccie:/bin/bash
ccde:x:1000:1000::/home/ccde:/bin/bash


usermod’ 명령어 : 사용자 속성 정보를 변경할때 사용하는 명령어이다.

[root@CentOS /root]# usermod -s /bin/bash ccnp
// 로그인 쉘 변경
[root@CentOS /]# usermod -c "" ccie ---> 주석제거     
[root@CentOS /root]# usermod -e '' ccie : 만료일 없애기

[root@CentOS /root]# cat /etc/passwd | tail -7
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash
ccent:x:502:502::/home/ccent:/bin/bash
ccna:x:503:503::/var/user1:/bin/bash
ccnp:x:504:504::/var/user2:/bin/bash
ccie:x:505:505:jang yong je:/home/ccie:/bin/bash
ccde:x:506:1000::/home/ccde:/bin/bash
[root@CentOS /root]# useradd -D -b /var -e 2017-04-20 -s /bin/csh


root@CentOS /root]# userdel ccent
[root@CentOS /root]# ls /home
ccent  user1  user2
[root@CentOS /root]# rm -rf /home/ccent
[root@CentOS /root]# ls /home
user1  user2

[root@CentOS /root]# userdel -r ccna ---> 계정삭제, 홈디렉토리까지 삭제
[root@CentOS /root]# userdel -r ccnp
[root@CentOS /root]# userdel -r ccie
[root@CentOS /root]# userdel -r ccde


[참고] 사용자 디렉토리 생성 과정

[root@CentOS /root]# ls -al /etc/skel
합계 36
drwxr-xr-x.   4 root root  4096 2017-04-18 07:18 .
drwxr-xr-x. 118 root root 12288 2017-04-20 21:12 ..
-rw-r--r--.   1 root root    18 2014-10-16 22:56 .bash_logout
-rw-r--r--.   1 root root   176 2014-10-16 22:56 .bash_profile
-rw-r--r--.   1 root root   124 2014-10-16 22:56 .bashrc
drwxr-xr-x.   2 root root  4096 2010-11-12 10:04 .gnome2
drwxr-xr-x.   4 root root  4096 2017-04-18 07:13 .mozilla

 

새로운 계정을 추가할 때 먼저 /etc/skel 디렉토리 내에 있는 파일들이 사용자 홈 디렉토리로 복사되어서 사용자 홈 디렉토리가 만들어지는것이다.


@useradd 명령 기본 설정 값 변경

 

[root@CentOS /root]# useradd -D -b /var -e 2017-12-31 -s /bin/csh : 기본 디렉토리는 /var이며 만료일은 17.12.31까지 csh쉘로 변경한다.
[root@CentOS /root]# useradd -D --- > 사용자 생성 명령어 확인
GROUP=100
HOME=/var
INACTIVE=-1
EXPIRE=2017-12-31
SHELL=/bin/csh
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@CentOS /root]#


@패스워드 에이징 설정

chage -l 계정명 : 패스워드 만료일 조회
chage -E YYYY-MM-DD 계정명 : 패스워드 만료일
chage -d 패스워드를 마지막으로 변경한 일자. //마지막 날짜
chage -W 패스워드 만료기간 몇 일전에 안내메세지를 보낼것인지를 알려줌
chage -M 기간 계정명 : 마지막 변경 이후의 패스워드 유효일 수
  90일  -M90
  9999일 -M9999
  99999  -M99999
chage -m : 패스워드를 변경할 수 있는 최소일 수 0이면 아무때나 변경 가능
chage -i : 비밀번호 만료 후  계정이 비활성화 되는 기간


Password Aging 이란 패스워드에 시간 개념을 도입하는 것으로
사용자가 현재 사용중인 패스워드를 사용할 수 있는 기간과
패스워드를 바꾸지 못하는 날짜 등을 추가하여 사용자에게 패스워드를
강제적으로 바꾸도록 종용하는 것이다.


Password_Aging 관련 파일은 /etc/shadow과 /etc/default/passwd 두개이다

예제1)


*chage -l ccna : 패스워드 만료일 조회

 chage -M 옵션 : 해당계정의 패스워드 최대 사용기간 설정

 

chage -m : 패스워드를 변경할 수 있는 최소일 수

 

chage -I(대문자I) : 계정이 만기된 후 사용하지 못하는 기간, 여기서는 200일동안 사용하면 만기가 되는데 그 후 15일 동안

사용하지 못하게 된다.


chage -E : 계정 만료일 지정


chage -d : 계정의 새 패스워드 변경



chage -W : 패스워드 만료기간 몇 일전에 안내 메세지를 출력한다.

 

@'group' 파일

cat /etc/group
` 중간생략~
root:x:0  그룹이름: 패스워드 : 그룹id
tcpdump:x:72:
slocate:x:21:
wireshark:x:493:
mailnull:x:47:
smmsp:x:51:
user1:x:500:
user2:x:501:
ccna:x:505:
ccnp:x:506:


@ 그룹 추가 /변경 /삭제
[root@CentOS /root]# groupadd cisco1

[root@CentOS /root]# groupmod -n cisco2 cisco1  //cisco1계정을 cisco2계정으로 바꾼다.

[root@CentOS /root]# useradd -g cisco1 -G cisco2,cisco3 ccie // 주그룹 -g, 보조그룹 -G
ccie계정의 주그룹 cisco1, 보조그룹 cisco2,cisco3



-프로세스 관리

1. 프로세스란?

-프로그램(program): 저장장치에 있는 실행 가능한 파일, 실행 중이지 않는 파일
-프로세서(processor) : CPU
-프로세스(process) : 실행중인 파일
프로그램이 메모리에 적재되어 실행되고 있는 상태

2. 프로세스 상태점검

1) 프로세스 정보 확인 : ps
ps 명령어는 현재 실행중인 프로세스를 확인하는 명령어입니다.
즉 프로세스의 상태를 확인 할 수 잇습니다.

tty /0 : 터미널
pts /0 : 원격

[사용방법]

#> ps [option]

-a : 실행중인 프로세스 중 제어 터미널을 가지고 있는 프로세스
-e : 시스템에서 실행중인 모든 프로세스의 상태를 출력
-f : 각 명령에 대해 PID와 PPID를 포함한 정보를 출력
-l : -f 옵션보다 더 자세히 정보를 출력
-u : 사용자의 이름과 프로세스가 시작된 시간 출력
-x: 터미널에 종속되지 않는 프로세스 출력

자주쓰는 명령어
ps -elf
ps aux

[root@CentOS /test]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 11:57 ?        00:00:01 /sbin/init


[root@CentOS /test]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  4112  4104  0  80   0 - 27120 wait   pts/1    00:00:00 bash
4 R     0 24969  4112  0  80   0 - 27033 -      pts/1    00:00:00 ps

PRI
NI : 순위
SZ : 가상메모리 사이즈

[root@CentOS /test]# ps -aux
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  19364  1536 ?        Ss   11:57   0:01 /sbin/init
root         2  0.0  0.0      0     0 ?        S    11:57   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    11:57   0:00 [migration/0]

USER : 프로세스의 권한을 갖고 있는 사용자명
PID : 프로세스가 갖는 PID
%CPU : 프로세스가 사용하고 잇는 cpu 점유율
%MEM : 프로세스가 사용하고 잇는 메모리 점유율
VSZ:  프로세스가 사용하고 있는 가상메모리 크기
RSS : 프로세스가 사용하고 있는 실제메모리 크기
TTY : 프로세스가 실행된 터미널 포트
STAT : 실행되고 잇는 프로세스의 상태
   R : 실행중
 S : 잠자고 있는 상태, 외부의 요청을 기다리고 있는 상태(sleeping)
 T : 실행대기
 Z : 좀비프로세스
  O : 고아프로세스
TTY : 터미널
TIME : cpu 사용 시간
START : 프로세스가 시작된 시간
TIME : 총 CPU 사용시간
COMMAND : 실행된 명령라인


[root@CentOS /test]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  4112  4104  0  80   0 - 27120 wait   pts/1    00:00:00 bash
4 R     0 25174  4112  0  80   0 - 27031 -      pts/1    00:00:00 ps

F : 프로세스와 관련된 플래그
S:  프로세스의 수행상태
UID
PID
PPID
PRI : 프로세스의 우선순의
NI : 프로세스 우선순위 결정에 게산되는 nice 값
ADDR :  프로세스의 메모리주소
SZ : 프로세스에 할당되는 메모리의 크기
WCHAN : 프로세스가 실행하고 있는 커널 루틴
STIME :  프로세스가 실행된 터미널 포트
TIME : 총 cpu 사용시간
CMD : 실행된 명령어

*pgrep 
ps명령어를 사용하게 되면 너무 많은 양이 한꺼번에 출력되기 때문에 꽉차거나 넘어가 버립니다.
이때ㅔ 파이프라인과(|) grep 명령어를 이용하여 필요로 하는 프로세스 정보만을 확인하게 되는데.
이러한 과정을 한번에 진행 할 수 있도록 도와주는 명령어

 


[root@CentOS /test]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0  4112  4104  0  80   0 - 27120 wait   pts/1    00:00:00 bash
4 R     0 25174  4112  0  80   0 - 27031 -      pts/1    00:00:00 ps

[사용방법]
#> pgrep [option] 패턴

[option]
-l : PID와 함께 프로세스의 이름을 출력
-f : -l옵션과 함걔 사용하면 명령어의 경로도 출력
-n : 패턴과 일치하는 프로세스와 가장 최근 PID 출력
-x : 패턴과 정확하게 일치되는 프로세스만 출력

*pstree구조 확인

[root@CentOS /test]# pstree
init─┬─NetworkManager─┬─dhclient
     │                └─{NetworkManager}
     ├─abrtd
     ├─acpid
     ├─atd
     ├─auditd───{auditd}
     ├─automount───4*[{automount}]
     ├─bonobo-activati───{bonobo-activat}

 


[root@CentOS /proc]# top

top - 14:59:20 up  3:01,  4 users,  load average: 0.06, 0.19, 0.16
Tasks: 194 total,   1 running, 193 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   2046532k total,   834356k used,  1212176k free,    85580k buffers
Swap:  4095996k total,        0k used,  4095996k free,   369764k cached


[예제 12-5] CPU 부하 발생 테스트
Ex1) CPU 부하 발생 테스트 I
[root@CentOS /test]# vi cpu1.sh
1 START=0
2 END=1000000000000000000
3 while [ $START -le $END ]
4 do
5 START=`expr $START + 1`
6 done
:wq!
[root@CentOS /test]# chmod 755 cpu1.sh
[root@CentOS /test]# ./cpu1.sh

 gui에서 Xwindow 'gnome-system-monitor' 확인


Ex2) CPU 부하 발생 테스트 II
[root@CentOS /test]# vi cpu2.sh
1 while true
2 do
3 a=1
4 done
:wq!
[root@CentOS /test]# chmod 755 *.sh
[root@CentOS /test]# ./cpu2.sh

Xwindow 'gnome-system-monitor' 확인

root@CentOS /test]# ./cpu1.sh &  ---> 실행하고나서 다른명령어를 실행가능(백그라운드)
[2] 10107

 

@포그라운드 백그라운드

 

백그라운드 작업은 명령어 맨뒤에 & 를 추가하면 된다.

멀티태스킹 중에 활성화 되있는 창을 포어그라운드라고 하고, 활성화 되어있지 않지만 실행은 되고 있는 것을 백그라운드라고도 합니다.

fg : 백그라운드 작업을 포그라운드로 전환

$fg %작업번호

포그라운드 작업 종료는 Ctrl + C

@fg & bg 이해 I

[root@CentOS /test]# cat & // bg 상태로 프로세스 실행
[1] 15087
Job PID

[root@CentOS /test]# ps -ef | grep cat
root 15087 6499 0 11:27 pts/0 00:00:00 cat
root 15090 6499 0 11:27 pts/0 00:00:00 grep cat

[root@CentOS /test]# ls -ld /proc/15087
dr-xr-xr-x. 8 root root 0 2016-01-26 11:27 /proc/15087

[root@CentOS /test]# fg
cat
(ctrl+c) // fg 상태로 프로세스 종료


Ex2) fg & bg 이해 II

[root@CentOS /test]# sleep 1000 // fg 상태로 프로세스 실행
(ctrl+z) // 프로세스를 Stop 하고, 쉘 프롬프트로 나가기

[1]+ Stopped sleep 1000
[root@CentOS /test]# sleep 2000
(ctrl+z)

[2]+ Stopped sleep 2000
[root@CentOS /test]# sleep 3000
(ctrl+z)


[root@CentOS /test]# jobs

[11]   Stopped                 sleep 1000
[12]-  Stopped                 sleep 2000
[13]+  Stopped                 sleep 3000
[root@CentOS /test]# bg 11
[11] sleep 1000 &
[root@CentOS /test]# bg 12
[12]- sleep 2000 &
[root@CentOS /test]# bg 13
[13]+ sleep 3000 &
[root@CentOS /test]# jobs

[11]   Running                 sleep 1000 &
[12]   Running                 sleep 2000 &
[13]   Running                 sleep 3000 &

[root@CentOS /test]# fg 11
sleep 1000
^C
[root@CentOS /test]# fg 12
sleep 2000
^C
[root@CentOS /test]# fg 13
sleep 3000
^C

 


[root@CentOS /test]#

 

^C^C[root@CentOS /test]# ^C
[root@CentOS /test]# jobs
[root@CentOS /test]# sleep 1000
^Z
[1]+  Stopped                 sleep 1000
[root@CentOS /test]# sleep 2000
^Z
[2]+  Stopped                 sleep 2000
[root@CentOS /test]# sleep 3000
^Z
[3]+  Stopped                 sleep 3000
[root@CentOS /test]# jobs   - ->>> 작업 목록보기 : jobs

현재 실행중인 백그라운드 작업을 보는 명령어는 jobs이고, 배시 셸의 내부명령이다.

[1]   Stopped                 sleep 1000
[2]-  Stopped                 sleep 2000
[3]+  Stopped                 sleep 3000
[root@CentOS /test]# bg 1
[1] sleep 1000 &
[root@CentOS /test]# bg 2
[2]- sleep 2000 &
[root@CentOS /test]# bg 3
[3]+ sleep 3000 &
[root@CentOS /test]# fg 1
sleep 1000
^C
[root@CentOS /test]# jobs
[2]-  Running                 sleep 2000 &
[3]+  Running                 sleep 3000 &
[root@CentOS /test]# fg 3
sleep 3000
^C
[root@CentOS /test]# jobs
[2]+  Running                 sleep 2000 &


@프로세스 종료

[root@CentOS /test]# sleep 1000 &
[3] 9565
[root@CentOS /test]# sleep 2000 &
[4] 9570
[root@CentOS /test]# sleep 3000 &
[5] 9572
[root@CentOS /test]# ps
  PID TTY          TIME CMD
 4430 pts/3    00:00:00 bash
 9504 pts/3    00:00:00 sleep
 9565 pts/3    00:00:00 sleep
 9570 pts/3    00:00:00 sleep
 9572 pts/3    00:00:00 sleep
 9573 pts/3    00:00:00 ps

[root@CentOS /test]# kill -9 9565
[root@CentOS /test]# ps
  PID TTY          TIME CMD
 4430 pts/3    00:00:00 bash
 9504 pts/3    00:00:00 sleep
 9570 pts/3    00:00:00 sleep
 9572 pts/3    00:00:00 sleep
 9578 pts/3    00:00:00 ps
[3]   죽었음               sleep 1000
[root@CentOS /test]# kill 9504
[root@CentOS /test]# jobs
[2]   종료됨               sleep 2000
[4]-  Running                 sleep 2000 &
[5]+  Running                 sleep 3000 &
[root@CentOS /test]# ps
  PID TTY          TIME CMD
 4430 pts/3    00:00:00 bash
 9570 pts/3    00:00:00 sleep
 9572 pts/3    00:00:00 sleep
 9593 pts/3    00:00:00 ps
[root@CentOS /test]# kill 9570
[root@CentOS /test]# kill 9572
[4]-  종료됨               sleep 2000


[root@CentOS /test]# sleep 1000 &
[6] 9599
[5]   종료됨               sleep 3000
[root@CentOS /test]# sleep 2000 &
[7] 9601
[root@CentOS /test]# sleep 3000 &
[8] 9603
[root@CentOS /test]# jobs
[6]   Running                 sleep 1000 &
[7]-  Running                 sleep 2000 &
[8]+  Running                 sleep 3000 &
[root@CentOS /test]# killall -9 sleep
[6]   죽었음               sleep 1000
[7]-  죽었음               sleep 2000
[8]+  죽었음               sleep 3000
[root@CentOS /test]# jobs

 

3. 프로세스 제어

 

제13장 작업 관리


#>at 작업설정(한번만 실행)
service start atd(atd 데몬 실행)

>at -t <time> MMDDhhmm 월일시간분
       08032140
at now + 1minute
  (minutes,hours,days,weeks)
#>atq
-작업확인 (작업 내용은 안나옴)

#>atrm <num>
-작업삭제

 

[root@CentOS /test]# at 16:15
at> echo koreaIT kkkkk> /dev/pts/4
at> <EOT>
job 10 at 2017-04-20 16:15

user2@CentOS /home/user2]$ tty
/dev/pts/4
[user2@CentOS /home/user2]$


[root@CentOS /etc]# vi at.deny

  1 user2

[user2@CentOS /home/user2]$ at 16:21
You do not have permission to use at.

[root@CentOS /etc]# service crond status
crond (pid  2291)를 실행하고 있습니다..

crontap -e

cron은 at과 역할은 비슷하지만
주기적으로 반복하여 작업을 자동화 할 수 잇는 데몬
[사용방법]
#> crontab [option]

-e : 작업할 내용 작성하기
-ㅣ: 작업 확인하기
-r : 작업 삭제하기

* * * * *
분 시 일 월 요일

1. 분
2. 시
3. 일
4. 월(1~12)
5. 요일(0: 일요일 ~~~~~6: 토요일)
6. 명령어

crontab -l : list확인
crontab -r : 작업삭제하기
root@CentOS /etc]# crontab -e
  
no crontab for root - using an empty one

      1  * * * * * cat /etc/passwd | tail -n 5 > /dev/pts/2
      2
[user1@CentOS /home/user1]# tcpdump:x:72:72::/:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash

@root
vi/ etc/cron.deny
1 user1

@user1
crontab -e
You (user1) are not allowed to use this program (crontab)
See crontab(1) for more information