'unix basic commands'에 해당되는 글 1건

  1. 2008.07.19 Chapter 5. Unix Basic Commands
2008. 7. 19. 23:35

Chapter 5. Unix Basic Commands

Chapter 6.  Unix Basic Commands
________________________________

■ UNIX 명령어 형식

# command [option(s)] [argument(s)]


(명령어)
# ls
# cal
# uname

(명령어 + 옵션)
# uname -s
# uname -a
# ls -l

(명령어 + 인자)
# ls /var
# cal 2002

(명령어 + 옵션 + 인자)
# ls -l /var

[참고] 옵션에 대한 설명
# ls -a -l -F
# ls -al -F
# ls -alF
# ls -aFl                         // F   : 파일 성격에 따른 /  * @ 표시된다  디렉토리 실행파일 심볼릭 등등.

[참고] 옵션의 인자가 존재하는 경우의 예

# cmd -i -f arg1 (0)
# cmd -f arg1 -i (0)
# cmd -if arg1   (0)
# cmd -fi arg1   (X)

운영체제의 기본적인 정보 확인
- uname CMD
- date CMD
- cal CMD

uname CMD                     // 현 시스템의 정보
______________

print name of current system

     The uname utility prints information about the current  sys-
     tem on the standard output. When options are specified, sym-
     bols representing one or more system characteristics will be
     written to the standard output. If no options are specified,
     uname  prints  the  current  operating  system's  name.  The
     options  print  selected  information  returned by uname(2),
     sysinfo(2), or both.


 

- 운영체제의 종류와 버전 확인(OS + Version)
- 커널 패치 버전 확인(Kernel Patch Version, Kernel ID)
# uname -a           //all
SunOS nara 5.9 Generic_118559-11 i86pc i386 i86pc
# uanme -s         
SunOS           //os
# uname -r
5.9                 //release level
# uname -sr
SunOS 5.9
# uname -n      //hostname
nara
# uname -i      //architecture  or platform
i86pc
# uname -p     // process  type
i386
# uname -X      // 확장된 정보
System = SunOS
Node = nara
Release = 5.9
KernelID = Generic_118559-11
Machine = i86pc
BusType = <unknown>
Serial = <unknown>
Users = <unknown>
OEM# = 0
Origin# = 1
NumCPU = 2


(출력화면 해석) Solaris 9 x86 on VMWare
# uname -a
SunOS solaris254 5.9 Generic_118559-11 i86pc i386 i86pc

----------------------------------------------------------------
종류                설명
----------------------------------------------------------------
SunOS              : 운영체제 종류
solaris254         : 호스트 이름
5.9                  : 운영체제 릴리즈
Generic_118559-11 : 커널 아이디(커널 식별자)
i86pc             : 머신아키텍쳐 (예: sun4u, sun4m, sun4c, ...)
i386               : 프로세스 종류(예: sparc, i386, i686, .....)
i86pc             : 하드웨어 구현 플랫폼

----------------------------------------------------------------

(출력화면 해석) Solaris 9 Sparc (Ultra 10)
# uname -a
SunOS sun99 5.9 Generic sun4u sparc SUNW,Ultra-5_10


(출력화면 해석) Sun Enterprise 3500
# uname -a
SunOS sun02 5.9 Generic_118558-11 sun4u sparc SUNW,Ultra-Enterprise

# man uname
.....
OPTIONS
     -a    Prints basic information currently available from the
    system.

     -i    Prints the name of the hardware implementation  (platform).

     -m    Prints the machine hardware name (class). Use of  this
    option is discouraged; use uname -p instead. See NOTES
    section below.

     -n    Prints the nodename (the nodename is the name by which
    the system is known to a communications network).

     -p    Prints the current host's ISA or processor type.

     -r    Prints the operating system release level.

     -s    Prints the name of the operating system. This  is  the
    default.
     -X    Prints expanded system  information,  one  information
           element  per  line,  as  expected  by  SCO  UNIX.  The
           displayed information includes:

              o  system name, node,  release,  version,  machine,
                 and number of CPUs.

              o  BusType, Serial, and Users (set to "unknown"  in
                 Solaris)

              o  OEM# and Origin# (set to 0 and 1, respectively)
.....


[참고] 호스트 이름 변경
호스트이름은 부팅시에 /etc/rcS.d/S30network.sh 스크립트안에서 uname 명령어를 사
용하여 설정되고, 이때 /etc/nodename 파일의 내용을 호스트 이름으로 설정한다.

솔라리스 호스트 이름 변경 형식
# uname -S knitXXX (/etc/rcS.d/S30network.sh)
# hostname knitXXX

[EX] Hostname Change
# hostname
# hostname knitXXX

# uname -n
# uname -S solarisXXX


[참고] 프로세서(CPU)에 대한 정보

psrinfo
- displays information about processors

[EX] 프로세스 정보 확인
# psrinfo
# psrinfo -p     // process #
# psrinfo -v     // verbose

# psrinfo -pv


[참고] 서버의 운영체제 종류와 버전 확인
# cat /etc/release (Intel Platform on VMWare)
                         Solaris 9 9/05 s9x_u8wos_05 x86
           Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
                        Use is subject to license terms.
                            Assembled 01 August 2005

# cat /etc/release (E3500)
                        Solaris 9 9/05 s9s_u8wos_05 SPARC
           Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
                        Use is subject to license terms.
                            Assembled 04 August 2005


[참고] 운영체제의 전반적인 정보를 확인
/root/docs/Reference/SolarisSystemInformation.txt
/root/docs/Reference/SystemInformationVerification.txt



dtterm CMD
______________

emulate a terminal window

     The dtterm utility provides runtime support of legacy appli-
     cations written for terminals conforming to ANSI X3.64-1979
     and ISO 6429:1992(E), such as the DEC VT220.

# echo $TERM
dtterm
# dtterm &


[참고] 실행이 안되는 경우(PATH 변수 확인)
# /usr/dt/bin/dtterm &
or
# export PATH=$PATH:/usr/dt/bin
# dtterm &
netscape CMD
________________

start Netscape Communicator for Solaris

     Netscape  Communicator  for  Solaris  is  comprised   of   a
     comprehensive  set  of  components that integrates browsing,
     email, web-based word processing, chat, and group scheduling
     to  allow  users  to  easily communicate, share, and  access
     information.


# sun_netscape &
# netscape &

[참고] 모질라 / 파이어폭스(http://www.sunfreeware.com)
firefox - 172.16.8.254:/root/packages/firefox
mozilla - 172.16.8.254:/root/packages/mozilla

firefox, mozilla가 필요한 경우 172.16.8.254 서버에서도 다운로드 받을수 있다.
# rcp -r 172.16.8.254:/root/packages/firefox  .



oclock CMD
_____________

round X clock

     Oclock  simply  displays  the  current  time  on  an  analog
     display.

     The xclock program displays the time in  analog  or  digital
     form.  The time is continuously updated at a frequency which
     may be specified by the user.


# oclock &   (# /usr/openwin/bin/oclock &)
# xclock &   (# /usr/openwin/bin/xclock &)

[참고] oclock & xclock


date CMD
_____________

write the date and time

     The date utility writes the date and time to standard output
     or attempts to set the system date and time. By default, the
     current date and time will be written.

     Specifications of native language translations of month  and
     weekday  names  are  supported.  The month and weekday names
     used for a language are based on the locale specified by the
     environment variable LC_TIME. See environ(5).

운영체제의 시간을 확인하거나 설정할수 있다.
- root 사용자: 현재 시간을 설정 및 확인 할 수 있다.
- 일반사용자 : 현재 시간만 확인 할 수 있다.


# date
# date 08161300 (8월 16일 13:00)

[참고] 소프트웨어 클락 & 하드웨어 클락
시간의 종류(Clock Type)
- Software Clock (운영체제의 시간)
- Hardware Clock (펌웨어의 시간)


[EX] 운영체제 시간 변경 예
# date 08201300      (예: 08201300, 운영체제 시간을 root 사용자가 바꾼다.)
# rdate 172.16.8.254 (운영체제 시간을 다른 서버에 동기화 시킨다.)
or                    
# rdate time.bora.net(NTP-Network Time Protocol)


[참고] date 명령어의 출력 형태 변경
# date +'%m%d'
# date +'%m%d_%H%M'

[EX] 로그 파일 이름 형식(Log Filename Format)
유닉스에서의 대부분의 프로그램은 하루에 한번씩 로그 파일을 만들도록 하는 경우가 많이
존재한다. 이런 경우 date 명령어를 아래와 같이 응용하여 사용하는 경우가 많다.

로그 파일 이름 형식: file_1211.log
# touch file_`date +'%m%d'`.log



cal CMD
_____________

display a calendar

     The cal utility writes a Gregorian calendar to standard out-
     put.  If  the year operand is specified, a calendar for that
     year is written. If no operands are  specified,  a  calendar
     for the current month is written.

# cal
# cal 2004
# cal 8 2004



디렉토리 이동 관련 명령어
■ pwd CMD
■ cd CMD


pwd CMD
_____________

return working directory name

     Returns the path name of the current working directory.

# pwd

[참고] PS1 변수설정
pwd 명령어를 디렉토리 변경할때 마다 치는 것은 불편하다. 따라서 PS1 변수를 환경변수에
선언하여 사용하면 pwd 명령어를 궂이 사용하지 않아도 된다.

# PS1='[$PWD]# '
# export PS1

[EX] PS1 실습
# PS1='a '
# PS1='[$PWD]# '



cd CMD
_____________

Change Directory

     Change the current working directory to dirName, or  to  the
     home  directory  (as specified in the HOME environment vari-
     able) if dirName is not given.  Returns an empty string.


cd 명령어는 디렉토리를 변경하는 명령어이다. cd 명령어를 사용하여 디렉토리 경로를 변
경하는 경우 상대경로(Relative Path)나 절대경로(Absolute Path)를 사용할수 있다.

경로(PATH)
- 상대경로 (Relative Path, 현재디렉토리를 기준)
- 절대경로 (Absolute Path, / 디렉토리를 기준)

 

               /

               |

----+----------+----------+-----------+-----

    |          |          |           |

  data1       export       etc        .......

                |

               home

                |

               user01

[EX] 상대경로 사용 예제
# pwd
# cd export
# cd ..

# cd export/home
# cd ../../


[EX] 절대경로 사용 예제
# cd /etc
# cd /export/home
# cd /usr


[참고] /export/home/user01
       A      A    A
       |      |    |
      (a)    (b)  (c)

(a)     => /(root) 디렉토리
(b),(c) => 디렉토리의 구분자


[참고] user01 사용자의 홈디렉토리로 이동하는 방법
root 사용자의 홈디렉토리 : /(root)
일반 사용자의 홈디렉토리 : /export/home/user01

Home Directory Changing for user01
$ ksh
$ cd
$ cd ~
$ cd ~user01 ($ cd ~/user01)
$ cd $HOME   ($ echo $HOME)
$ cd /export/home/user01


[참고] 편리한 기능(Tip)
# cd -
# cd ../dir2

[EX]
"cd - " 사용한 이전 디렉토리로 이동
(시나리오) 사용자가 /etc 디렉토리에서 작업을 하다가 /export/home/user01 디렉토리로
이동하는 경우 상대경로나 절대경로를 사용하는 경우는 불편하게 된다. 이런 경우 이전
디렉토리로 바로 이동하기 위해서 "cd - " 명령어를 사용한다.

/etc <------> /export/home/user01

# cd /etc
작업
# cd /export/home/user01
작업
# cd /etc
작업
# cd -
# cd -
# cd -

                   /

                   |

------------+------+-------+--------+------

    ....    |    .....   export    etc

          test

            |

    ---+----+----+-------

       |         |   .....

      dir1      dir2

현재 디렉토리 : dir2
목적 디렉토리 : dir1

# cd ..
# cd dir1

# cd ../dir1


[EX] ../dir1 활용 예
# cd /
# cd /export
# cd ../etc



파일의 종류(File Types)
------------------------

■ 일반 파일(Regular File)
■ 디렉토리 파일(Directory File)
■ 링크 파일(Link File : Hard Link File, Symbolic Link File)
■ 디바이스 파일(Device File : Block Device File, Charater Device File)

[참고] 기타 파일의 종류(Other File Types)
- Pipe, Socket, Door


                 +-------------------+

filename ====>   | Inode             |

                 +-------------------+

                 |                   |

                 | Data Block        |

                 |                   |

                 +-------------------+

 

       [그림] 파일의 기본 구조

 

 

 

(1). 일반 파일(Regular File)

                   +-------------------+

file1    ====>     | inode(450)        |

                   +-------------------+

                   |                   |

                   | Data Block        |

                   |                   |

                   +-------------------+

Data : Text, Binary data, Images, Application data, Databases
Creation Methods : Text editors, Compilers, Application programs,
                   Database programs, Command(EX: touch, cat, vi)


(2). 디렉토리 파일(Directory File)

                   +-------------------+

dir1     ====>     | inode(451)        |

                   +-------------------+

                   | .(451)            |

                   | ..(440)           |

                   | file1(452)        |

                   | dir2(453)         |

                   | .....             |

                   |                   |

                   +-------------------+


 
Data : Directory information
Creation Methods : mkdir dirname


(3). 링크 파일(Link File)
"ln CMD" 참고


(4). 디바이스 파일(Device File)

                   +-------------------+

dad@0,0:a ====>    | inode(451)        |

                   +-------------------+

                   |                   |

                   | 136, 0            |

                   |                   |

                   +-------------------+

  
Data : Major/Minor device number
Creation Methods : mknod, drvconfig, devfsadm

주 디바이스 번호(Major Device Number) : 136 (/etc/name_to_major)
부 디바이스 번호(Minor Device Number) : 0   (Slice Number)             //?


[EX] Intel Platform(VMWare)
# grep cmdk /etc/name_to_major 
cmdk 102

# ls -l /devices/pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0:a
brw-r-----  1 root   sys  102,0  1월 7 12:22 /devices/pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0:a

[EX] Sparc Platform(Ultra 10)

# grep dad /etc/name_to_major

dad 136

 

# ls -l /devices/pci@1f,0/pci@1,1/ide@3/dad@0,0:a

brw-r-----   1 root     sys      136,  0  2  2 16:05 /devices/pci@1f,0/pci@1,1/ide@3/dad@0,0:a


<Disk Structure>                                 <Operating System>

| DISK Device | <=== Device Driver ===> dad@0,0:a  |   kernel   |

| - Sector    |                        Device File |            |

| - Track     |                                    |            |

| - Cylinder  |                                    |            |

 

  

 

디스크 디바이스 파일(Disk Device File, Special Device File)

- Charater Device File     : I/O : 512bytes

  = Raw Device File

- Block Device File        : I/O : 8Kbytes (512 * 16)

 

| DISK Device | <=== Device ===> Block Device File    | OS(kernel) |

| - Sector    |      Driver      Charater Device File |            |

| - Track     |                                       |            |

| - Cylinder  |                                       |            |



[EX] 블럭디바이스 사용예제
# mount /dev/dsk/c0t0d0s7 /export/home

[EX] 캐릭터디바이스 사용예제
# newfs /dev/rdsk/c0t0d0s7
# fsck /dev/rdsk/c0t0d0s7

[EX] 블럭 / 캐릭터디바이스 사용예제
# prtvtoc /dev/rdsk/c0t0d0s2
# prtvtoc /dev/dsk/c0t0d0s2

// 블럭 과 캐릭터디바이스의 사용이유는 성능상의 이유로 쓰이며 rdsk를 쓰는 경우는
// 저수준의 whole 작업인경우에 쓰인다 예로 filesystem create or check


파일/디렉토리 이름 규칙(Filename Convention)
____________________________________________

Filename / Directory Name Length : 1-255 char(s)

(1). 파일의 이름에 "-"(Dash), "_"(Underbar), "."(Dot) 사용가능
# touch file1_1202.log
# touch dir-file.sh

(2). 파일이름에 공백, 점(Dot)는 되도록 사용하지 말자.
이런 파일 이름들은 주로 해커들에 의해 악의적으로 사용되는 경우가 많다.
# touch "    "
# touch ".   "
# touch /dev/rdsk/c0t0e0s0

(3). 파일이름에 대문자와 소문자는 구별한다.(Case Sensitive)
# touch file1
# touch FILE1

(4). 파일이름에 앞에 .(Dot)으로 시작하는 파일은 환경파일이다.
# touch .filename
# ls -l /.profile
# ls -l /.kshrc



Wild Card(Special Character)      //  하나의 문자가 여러개의 문자를 포함하는 문자.
______________________________

(1) . (Dot, Period)         // 현재의~ 디렉토리
Current Directory
# ./ENV.sh
# vi ./file.txt

(2) .. (Dot Dot)             // 상위의 디렉토리
# cd ../
# cd ../dir2

(3) ~ (tilde)                // 계정의 HOME 디렉토리
# cd ~user01

(4) * (0 or more)         // 하나의 문자 이상의 모든 캐릭터
# mkdir /test
# cd /test
# touch file1 file2 file3
# ls -l file*

# touch file           
# ls -l file*

(5) ? (Question Mark)      //한글자의 모든? 캐릭터    ,
# ls -l file?

(6) [ ] (Square Bracket)     // 선택적인 한글자
# ls -l file[123]        // 1,2,3 중하나
# ls -l file[1-3]       //     "



■ man CMD
■ passwd CMD


man CMD
_____________

find and display reference manual pages

     The man command  displays  information  from  the  reference
     manuals.  It  displays complete manual pages that you select
     by name, or one-line summaries selected  either  by  keyword
     (-k),  or  by  the  name  of  an associated file (-f). If no
     manual page is located, man prints an error message.

# man ls
# man -k calendar  // keyword 에 의한 ~찾기
# man -l passwd   // list 에 의한 찾기   , 메뉴얼 페이지의 리스트 보기
# man -s section_number CMD      //section 정보로 찾기


[EX] man ls 형식 실습
# man ls
------------------------man ls 출력 결과-----------------------------
User Commands                                               ls(1)

NAME
     ls - list contents of directory

SYNOPSIS
     /usr/bin/ls [-aAbcCdfFghilLmnopqrRstux1@] [file...]

     /usr/xpg4/bin/ls [-aAbcCdfFghilLmnopqrRstux1@] [file...]

DESCRIPTION
     For each file that is a directory, ls lists the contents  of
     the  directory.  For  each file that is an ordinary file, ls
     repeats its name and any other  information  requested.  The
     output is sorted alphabetically by default. When no argument
--More--(4%)
------------------------man ls 출력 결과-----------------------------

Enter   -> 한개의 라인씩 이동
Space   -> 한페이지 단위로 이동
/문자열 -> /-a
           /OPTIONS
    /EXAMPLE
h       -> help
q       -> 매뉴얼 종료


[EX] man -k calendar 형식 실습

(시나리오) 사용자가 cal 명령어를 모르는 상태에서 명령어나 파일을 검색하기 위해서 사용

windex (/usr/share/man/windex) - Table of contents and keyword database

# man -k calendar
/usr/share/man/windex: No such file or directory
/usr/man/windex: No such file or directory
/usr/openwin/share/man/windex: No such file or directory
// 처음 keyword에 대한 DB화 되어 있지 않아 검색에러가 난다.

# catman -w        //DB 목록화
# man -k calendar
cal             cal (1)         - display a calendar
calendar        calendar (1)    - reminder service
difftime        difftime (3c)   - computes the difference between two calendar times
mktime          mktime (3c)     - converts a tm structure to a calendar time
cal             cal (1)         - display a calendar
calendar        calendar (1)    - reminder service
difftime        difftime (3c)   - computes the difference between two calendar times
mktime          mktime (3c)     - converts a tm structure to a calendar time


[EX] man -l passwd 형식 실습
# man -l passwd
passwd (1)      -M /usr/share/man
passwd (4)      -M /usr/share/man
passwd (1)      -M /usr/man
passwd (4)      -M /usr/man

매뉴얼 섹션 참고 사항
위의 예에서 passwd의 매뉴얼이 (1) 섹션과 (4) 섹션에 존재 한다는 것을 확인 할 수 있 다. man 명령어는 -s 옵션이 없다면 여러개의 섹션에 매뉴얼이 존재하는 경우 가장  먼저 검색이 되는 매뉴얼 페이지를 출력하게 된다. (1) 섹션의 passwd  명령어의  매뉴얼지가 아닌 (4) 섹션의 /etc/passwd 파일의 매뉴얼을 확인 하기 위해서는
-s 옵션이 필
요하다
# man passwd

# man -l passwd
# man -s 1 passwd (/usr/bin/passwd)
# man -s 4 passwd (/etc/passwd)


[EX] man -s 1M passwd 형식 실습
# man find
..... (중략) .....
/SEE ALSO      // 연관된 ~ 더 찾아보기
.....
SEE ALSO
     chmod(1),  cpio(1),   ls(1B),   sh(1),   test(1),   stat(2),
     umask(2),   attributes(5),   environ(5),  fsattr(5),  large-
     file(5), standards(5)
.....

# man -s 1B ls
# man -s 5 environ


[참고] man 명령어안에서의 하위(Sub) 명령어
Keys to Ctrl Scrolling in Man Pages.
_________________________________________________________________________________

Spacebar Displays the next screen of a man page.
Return  Displays the next line of a man page.
b  Moves back one full screen.     // 전 페이지
f  Moves forward one full screen.  // 다음 페이지
:f  Print current filename and line number.
/pattern Searches forward for a pattern.
n  Finds the next occurrence of a pattern after you have used   //다음 패턴
  /pattern
h  Provides a description of all scrolling capabilities.     //도움말
q  Quits the man command.    //종료
_________________________________________________________________________________


# man man
.....
OPTIONS
.....
     -k keyword ...
           Prints out one-line summaries from the windex database
           (table of contents) that contain any of the given key-
           words.  The   windex   database   is   created   using
           catman(1M).

     -l    Lists all manual pages found matching name within  the
           search path.

     -s section ...
           Specifies sections of the manual for  man  to  search.
           The directories searched for name are limited to those
           specified by  section.  section  can  be  a  numerical
           digit,  perhaps  followed  by  one  or more letters to
           match the desired section of the manual, for  example,
           "3libucb".   Also, section can be a word, for example,
           local, new, old, public. section can also be a letter.
           To  specify  multiple  sections, separate each section
           with  a  comma.  This  option  overrides  the  MANPATH
           environment  variable  and the man.cf file. See Search
           Path below for an explanation of how man conducts  its
           search.


# cd /usr/share/man
# ls


Unix Manual Section
________________________________________________

Section 1 Command
Section 2 Library for System Programming
Section 3 Library for C Programming
Section 4 System Configuration File Format
Section 5 Standard, Macro etc
Section 6 Games, Demo etc
Section 7 Device File


Sun 9 Reference Manual Collection
____________________________________

section 1: User Commands
section 1M: System Administration Commands     //관리자용 명령어
section 2: System Calls
section 3: Library Interfaces and Headers
section 3: Basic Library Functions
section 3: Networking Library Functions
section 3: Threads and Realtime Library Functions
section 3: Extended Library Functions
section 3: Curses Library Functions
section 4: File Formats
section 5: Standards, Environments, and Macros
section 6: Demos
section 7: Device and Network Interfaces
section 9: DDI and DKI Driver Entry Points
section 9: DDI and DKI Kernel Functions
section 9: DDI and DKI Properties and Data Structures

[참고] DDI / DKI
DDI(Device Driver Interface)
DKI(Driver-Kernel Interface)


Section 1, 4 -> 관리자
Section 2, 3 -> 시스템 프로그램머
Section 7, 9 -> Device Driver 개발자



[참고] Manual Information Structure
- NAME
- SYNOPSIS
- DESCRITPION
- OPTIONS
- OPERANDS
- OUTPUT
- RETURN VALUES
- ERRORS
- USAGE
- EXAMPLES
- ENVIRONMENT VARIABLES
- EXIT STATUS
- FILES
- ATTRIBUTES
- SEE ALSO
- DIAGNOSTICS
- WARNINGS
- NOTES
- BUGS

[EX] Manual Information Structure 사용 예
# man ls
/문자열
-> /OPTIONS
-> /EXAMPLES
-> /SEE ALSO


[참고] 매뉴얼 페이지를 텍스트 파일로 변환
매뉴얼 페이지를 텍스트 파일로 저장하는 경우 다음과 같은 명령어를 사용하면 된다.

Manual.TXT File
# man find | col -b > find.txt

# man col
.....
reverse line-feeds filter      // 하나의 문자에 두가지 이상의 문자가 표현 되었을때 제거하는것
.....
     -b    Assume that the output device in use is not capable of
           backspacing.  In  this case, if two or more characters
           are to appear in the same place,  only  the  last  one
           read will be output.
.....



passwd CMD
_____________

change login password and password attributes
사용자 패스워드을 변경하거나 패스워드의 속성 정보를 변경하는 명령어이다.

     The passwd command computes the hash of a password typed at
     run-time or the hash of each password in a list.  The
     password list is taken from the named file for option -in
     file, from stdin for option -stdin, or from the command
     line, or from the terminal otherwise.  The Unix standard
     algorithm crypt and the MD5-based BSD password algorithm 1
     and its Apache variant apr1 are available.

root 사용자가 일반사용자의 암호를 변경하는 경우 사용자의 암호를 물어 보지 않고
바로 변경이 가능하다. 하지만 일반사용자가 자신의 암호를 변경하는 경우에는 이전
암호를 반드시 맞추어야만 새로운 암호로 변경할수 있고, 이때 사용자 암호 변경 규
칙이 적용된다.

- root 사용자 : 모든 사용자의 암호를 변경가능
- 일반 사용자 : 자신의 암호만 변경 가능

root># passwd
root># passwd username

user01># passwd
user01># passwd user01


[EX] 사용자 암호 변경 실습

(root 사용자 암호 변경 실습)
# passwd
passwd: Changing password for root
New Password:          <----- 새로운 암호 입력(암호: 123user)
Re-enter new Password: <----- 암호 재 입력(암호: 123user)
passwd: password successfully changed for root

# passwd root
New Password:          <----- 새로운 암호 입력(암호: knit)
Re-enter new Password: <----- 암호 재 입력(암호: knit)
passwd: password successfully changed for root

(일반 사용자 암호 변경 실습)
# passwd user01
New Password:          <----- 새로운 암호 입력(암호: solaris)
Re-enter new Password: <----- 암호 재 입력(암호: solaris)
passwd: password successfully changed for user01

# telnet localhost
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

SunOS 5.9

login: user01
Password:              <----- 사용자 암호 입력(암호: solaris)
Last login: Thu Jan 31 12:23:33 from localhost
Sun Microsystems Inc.   SunOS 5.9       Generic January 2003

$ id
uid=100(user01) gid=1(other)

$ passwd
passwd: Changing password for user01
Enter existing login password: <----- 기존의 암호 입력(암호: solaris)
New Password:                  <----- 새로운 암호 입력(암호: 123user)
Re-enter new Password:         <----- 암호 재 입력(암호: 123user)
passwd: password successfully changed for user01


[참고] 사용자 암호 변경 규칙
# man passwd
.....
     Passwords must be constructed to meet the following require-ments:
    o Each password must have PASSLENGTH  characters,  where
      PASSLENGTH  is  defined  in /etc/default/passwd and is
      set to 6. Only the first eight characters are signifi-cant.
    o Each password must contain  at  least  two  alphabetic
      characters and at least one numeric or special charac-ter.
      In this case, "alphabetic" refers to all upper or lower case
      letters.
    o Each password must differ  from the user's  login name
      and  any reverse or circular shift of that login name.
      corresponding lower case letter are equivalent.
    o New passwords must differ from the old by at least
      three  characters.  For comparison purposes, an upper
      case letter and its corresponding lower case letter
      are equivalent.
.....

암호 변경 규칙

- 암호의 길이는 6-8 글자 사이값이어야 한다.
- 암호는 2개의 문자와 한개의 숫자 또는 특수 문자가 포함 되어야 한다.
- 사용자 이름과 암호는 틀려야 한다.
- 사용자 로그인 이름과 암호는 reverse, circular shift 형태는 안된다.
- 사용자의 암호는 이전 암호와는 3글자 이상 틀려야 한다.


[EX] 암호 변경 규칙 테스트
# telnet localhost
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

SunOS 5.9

login: user01
Password:     <----- 사용자 암호 입력(암호: 123user)
Last login: Thu Jan 31 18:51:20 from localhost
Sun Microsystems Inc.   SunOS 5.9       Generic January 2003

$ id
$ passwd
passwd: Changing password for user01
Enter existing login password: <----- 기존의 암호 입력(암호: 123user)
New Password:                  <----- 짧은 암호 입력(암호: end01)
passwd: Password too short - must be at least 6 characters.

Please try again
New Password:                  <----- 기존의 암호와 같은 암호 입력(암호: 123user)
passwd: Old and new passwords must differ by at least 3 positions.

Please try again
New Password:                  <----- 새로운 암호 입력(암호: solaris1)
Re-enter new Password:         <----- 암호 재 입력(암호: solaris1)
passwd: password successfully changed for user01

-> user01 사용자 복원

 
출처 : http://cafe.daum.net/bscsolaris