블로그 이미지
오정oI

카테고리

분류 전체보기 (119)
회사 - pj # 나라원 (1)
회사 - pj # 나라원 (2)
이직준비 (10)
국비-클라우드 (1)
학점은행제 (0)
취미 (0)
주식 (0)
외국어 (0)
자격증 (14)
BigData_On (1)
BigData_Off1 (74)
클라우드 (0)
언어_Framework (1)
언어-Server (2)
언어_Client (0)
업무 (1)
IT참고서적 (1)
IT 최신 트랜드 (0)
제테크 (1)
Study Plan (2)
동영상 및 자료 (5)
여행 (1)
git (0)
Total
Today
Yesterday
반응형
SMALL

* Review

1> 사용자 게정 생성

[사용형식]

# useradd 계정명

→ 계정을 생성하는데 기본설정을 토대로 생성이 됨

# useradd [option] [argument] 계정명

→ 계정을 생성시 옵션 사용하여 해당 값을 주어서 생성함

[option]

-u : uid를 지정

-g : gid를 지정(그룹 배운 후)

-c : comment 를 지정

-s : shell을 지정

-d : 사용자 계정의 홈 디렉터리 생성할 경로를 지정

-p:  사용자 계정을 생성할 때 비밀번호와 같이 부여하여 생성

 ex) useradd -p `openssl passwd 1` user6            // ` : 쿼터 (1앞에 키)

-m -k 또는 -mk : 사용자 지정 skel

 

 

* /etc/skel 디렉터리 하위에 파일들

 

 

 

(다시 말해 각 사용자 계정의 홈 디렉터리 하위)

 

.bash_logout

- 각각 사용자 계정이 로그아웃시 기록이 저장되는 파일

 

. bash_profile

- 각각 사용자 계정의 환경 변수 파일(PATH(경로) 설정)

cf) [root@localhost itbank]# ls -l /etc/profile        // 리눅스 전체
-rw-r--r--. 1 root root 1807  9월 25 15:27 /etc/profile

.bashrc

- 각각 사용자 계정의 alias 설정

 

[root@localhost itbank]# tail -8 /etc/passwd
linux1:x:1001:1001::/AS/Linux/linux1:/bin/bash
user1:x:1002:1002::/home/user1:/bin/bash
user2:x:1004:1004::/home/user2:/bin/bash
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user5:x:1007:1007::/bonwon/userfive:/bin/csh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# ls -la /home/user7
합계 12
drwx------.  3 user7 user7  91 12월 26 15:05 .
drwxr-xr-x. 10 root  root  165 12월 26 15:20 ..
-rw-r--r--.  1 user7 user7  18  9월  7 01:25 .bash_logout
-rw-r--r--.  1 user7 user7 193  9월  7 01:25 .bash_profile
-rw-r--r--.  1 user7 user7 231  9월  7 01:25 .bashrc
drwxr-xr-x.  4 user7 user7  39  9월 25 14:49 .mozilla

-rw-r--r--.  1 user7 user7   0 12월 26 15:01 junga
[root@localhost itbank]#
[root@localhost itbank]# ls /home
itbank  itbank2  user1  user2  user3  user4  user6  user7
[root@localhost itbank]#
[root@localhost itbank]# /usr/bin/ls /home            // 원래 이런방식으로 써야 함
itbank  itbank2  user1  user2  user3  user4  user6  user7
[root@localhost itbank]#
[root@localhost itbank]# ls -l /etc/pro
profile    profile.d/ protocols
[root@localhost itbank]# ls -l /etc/profile
-rw-r--r--. 1 root root 1807  9월 25 15:27 /etc/profile

// user6 에만 적용(alias)

[root@localhost itbank]# vi /home/user6/.bashrc
alias fresh='clear'                    // line1에 추가
echo "hello~ I_m user6!"

// 전체 적용 가능한 파일

[root@localhost itbank]# ls -l /etc/bashrc
-rw-r--r--. 1 root root 2853 11월  6  2016 /etc/bashrc
[root@localhost itbank]#
[root@localhost itbank]# ls -l /etc/profile
-rw-r--r--. 1 root root 1807  9월 25 15:27 /etc/profile


 

* /etc/default/useradd(파일) 와

  useradd -D (명령어)

useradd -D

- 사용자 계정 생성시 관련된 기본 설정값을 출력

 

[사용형식]

useradd -D [option] [argument] 계정명

 

[root@localhost itbank]# useradd -D
GROUP=100                        ①
HOME=/home                     ②
INACTIVE=-1                       ③
EXPIRE=                             ④   
SHELL=/bin/bash                  ⑤   
SKEL=/etc/skel                     ⑥   
CREATE_MAIL_SPOOL=yes      ⑦

 

① GROUP=100

사용자 계정 생성시 기본 그룹을 지정-ㅠ

[option]

-g

 

② HOME=/home

- 사용자 계정 생성시 기본 생성 경로를 지정 

[option]

-b

 

③ INACTIVE=-1              

- 사용자 계정 생성시 만료 후 사용 불가능

값이 -1은 비활성화

값이 0은 사용 안 함

[option]

-f

 

④ EXPIRE=
- 만료일

값이 없으므로 무제한

[option]

-e

 

⑤ SHELL=/bin/bash

- 사용자 계정 생성시 기본 셸을 지정

[option]

-s

 

⑥ SKEL=/etc/skel
- 사용자 계정 생성시 기본 스켈을 지정

[option]

없음

옵션이 없으므로, # vi /etc/default/useradd 해서 수정!

 

⑦ CREATE_MAIL_SPOOL=yes

- 사용자 계정 생성시 사용자 관련 메일 파일 생성 허용 여부

(참고로 /var/spool/mail 디렉터리 하위에 사용자 계정 메일 파일이 존재함)

[option]

없음

 

// 작업 효율성 ↑

# vi /etc/default/useradd

다음 사항 수정

HOME=/bonwon

SHELL=/bin/tcsh

SKEL=/testskel

 

useradd -d /bonwon /test1 -s /bin/tcsh -m -k /testskel test2

대신

useradd test2

가능!

 

 

[root@localhost itbank]# tail /etc/passwd
user2:x:1004:1004::/home/user2:/bin/bash
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user5:x:1007:1007::/bonwon/userfive:/bin/csh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/home/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
test:x:1012:1012::/jongro/test:/bin/bash
test2:x:1013:1013::/jongno/test2:/bin/bash

[root@localhost itbank]# ls -l /etc/default/useradd
-rw-r--r--. 1 root root 119 11월  5  2016 /etc/default/useradd
[root@localhost itbank]#
[root@localhost itbank]# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

[root@localhost itbank]#
[root@localhost itbank]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

 

 

* 사용자 계정 수정

[사용형식]

usermod [option] [argument] 계정명

 

사용자 계정 수정은 사용형식

이 사용자 계정 생성과 동일함

 

[ption]

-u : uid를 수정할 때

-g : 그룹을 배운 후에

-G : 그룹을 배운 후에

-c : comment 를 수정할 때

-s : shell을 수정할 때

-l :  사용자 계정명을 수정할 때

-d :  사용자 계정의 홈 디렉터리 경로 또는 사용자 계정의 홈 디렉터리명을 수정할 때

(참고로 -d 옵션을 사용할 때 -m 옵션과 같이 사용할 수 있음)

 

 

 

[root@localhost ~]# tail /etc/passwd
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user5:x:1007:1007::/bonwon/userfive:/bin/csh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/home/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
test:x:1012:1012::/jongro/test:/bin/bash
test2:x:1013:1013::/jongno/test2:/bi
user9:x:1014:1014::/centos/user9:/bin/tcsh
[root@localhost ~]#

// uid 수정

[root@localhost ~]# usermod -u 2011 test2
[root@localhost ~]#
[root@localhost ~]# tail /etc/passwd
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user5:x:1007:1007::/bonwon/userfive:/bin/csh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/home/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
test:x:1012:1012::/jongro/test:/bin/bash
test2:x:2011:1013::/jongno/test2:/bin/bash
user9:x:1014:1014::/centos/user9:/bin/tcsh
[root@localhost ~]#

// comment 수정

[root@localhost ~]# usermod -c seoul test2
[root@localhost ~]#
[root@localhost ~]# tail /etc/passwd
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user5:x:1007:1007::/bonwon/userfive:/bin/csh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/home/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
test:x:1012:1012::/jongro/test:/bin/bash
test2:x:2011:1013:seoul:/jongno/test2:/bin/bash
user9:x:1014:1014::/centos/user9:/bin/tcsh

// 사용자 계정명 수정

[root@localhost ~]# usermod -l userfive user5
[root@localhost ~]#
[root@localhost ~]# tail /etc/passwd
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/home/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
test:x:1012:1012::/jongro/test:/bin/bash
test2:x:2011:1013:seoul:/jongno/test2:/bin/sh
user9:x:1014:1014::/centos/user9:/bin/tcsh
userfive:x:1007:1007::/bonwon/userfive:/bin/csh
[root@localhost ~]#

// 사용자 계정 홈 디렉터리 수정

[root@localhost itbank]# usermod -d /jongno/user8 user8
[root@localhost itbank]#
[root@localhost itbank]# tail -12 /etc/passwd
user1:x:1002:1002::/home/user1:/bin/bash
user2:x:1004:1004::/home/user2:/bin/bash
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/jongno/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
test:x:1012:1012::/jongro/test:/bin/bash
test2:x:2011:1013:seoul:/jongno/test2:/bin/sh
user9:x:1014:1014::/centos/user9:/bin/tcsh
userfive:x:1007:1007::/bonwon/userfive:/bin/csh
[root@localhost itbank]#
[root@localhost itbank]# ls -l /jongno/   //재 위치에 없으면 로긴시 bash셸이 borne 셸 처럼 깨짐
합계 0
drwx------. 4 test2 test2 92 12월 27 13:54 test2

[root@localhost itbank]# mv /home/user8 /jongno
[root@localhost itbank]#
[root@localhost itbank]# ls -l /jongno/
합계 0
drwx------. 4 test2 test2 92 12월 27 13:54 test2
drwx------. 3 user8 user8 78 12월 27 13:06 user8

 

// useradd -D 기본값 복원

[root@localhost itbank]# vi /etc/default/useradd

SKEL=/etc/skel

:wq
[root@localhost itbank]#
[root@localhost itbank]# useradd -D -b /home -s /bin/bash
[root@localhost itbank]#
[root@localhost itbank]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

[root@localhost itbank]# useradd user11
[root@localhost itbank]#
[root@localhost itbank]# tail -1 /etc/passwd
user11:x:2013:2013::/home/user11:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# ls /home
itbank  itbank2  user1  user11  user2  user3  user4  user6  user7  user88

// /home/user11 → /bonwon/user11

[root@localhost itbank]# usermod -d /bonwon/user11 user11
[root@localhost itbank]#
[root@localhost itbank]# tail -1 /etc/passwd
user11:x:2013:2013::/bonwon/user11:/bin/bash
[root@localhost itbank]# ls -l /bonwon/
합계 0
drwx------. 3 userfive user5 94 12월 26 15:00 userfive
[root@localhost itbank]#
[root@localhost itbank]# mv /home/user11 /bonwon
[root@localhost itbank]#
[root@localhost itbank]# ls /home /bonwon/
/bonwon/:
user11  userfive

/home:
itbank  itbank2  user1  user2  user3  user4  user6  user7  user88

// 한번에 home dir. 변경하는 방법

[root@localhost itbank]# tail -1 /etc/passwd
user11:x:2013:2013::/bonwon/user11:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# usermod -m -d /home/user11 user11
[root@localhost itbank]#
[root@localhost itbank]# tail -1 /etc/passwd
user11:x:2013:2013::/home/user11:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# ls /bonwon
userfive
[root@localhost itbank]# ls /home
itbank  itbank2  user1  user11  user2  user3  user4  user6  user7  user88
[root@localhost itbank]#
[root@localhost itbank]#


 

* 사용자 삭제

[사용형식]

# userdel 계정명

/etc/passwd, /etc/shadow, /etc/group 파일에 삭제한 계정의 정보가 없어짐  // 공통점

삭제한 사용자 계정의 홈 디렉터리는 남아있음

삭제한 사용자 계정의 메일파일이 남아있음

=> 나중에 복구할 수 있음

 

# userdel [option] 계정명

-r : 사용자 계정의 모든 것들

/etc/passwd, /etc/shadow, /etc/group 파일에 삭제한 계정의 정보가 없어짐  // 공통점

삭제한 사용자 계정의 홈 디렉터리는 남아있지 않음

삭제한 사용자 계정의 메일파일이 남아있지 않음

=> 나중에 복구할 수 없음

 

 

// 준비물

[root@localhost itbank]# useradd -d /bonwon/user12 user12
[root@localhost itbank]#
[root@localhost itbank]# tail -1 /etc/passwd
user12:x:2014:2014::/bonwon/user12:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# useradd -d /bonwon/user13 user13
[root@localhost itbank]#
[root@localhost itbank]# tail -2 /etc/passwd
user12:x:2014:2014::/bonwon/user12:/bin/bash
user13:x:2015:2015::/bonwon/user13:/bin/bash

// userdel user12        => 해당 사용자 관련 복구 정보는 남아 있음(home dir. mail)

[root@localhost itbank]# userdel user12
[root@localhost itbank]#
[root@localhost itbank]# tail -2 /etc/passwd
user11:x:2013:2013::/home/user11:/bin/bash
user13:x:2015:2015::/bonwon/user13:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# tail -2 /etc/shadow
user11:!!:17528:0:99999:7:::
user13:!!:17528:0:99999:7:::
[root@localhost itbank]#
[root@localhost itbank]# tail -2 /etc/group
user11:x:2013:
user13:x:2015:
[root@localhost itbank]#
[root@localhost itbank]# ls -l /bonwon/
합계 0
drwx------. 4     2014   2014 92 12월 28 13:15 user12    // 2014 : user12가 사용했던 uid. 헬스장 키 번호
drwx------. 4 user13   user13 92 12월 28 13:16 user13
drwx------. 3 userfive user5  94 12월 26 15:00 userfive
[root@localhost itbank]#
[root@localhost itbank]# ls -l /var/spool/mail/
합계 0
-rw-rw----. 1 itbank   mail 0  9월 25 15:30 itbank
-rw-rw----. 1 linux1   mail 0 12월 22 14:01 linux1
-rw-rw----. 1 rpc      mail 0  9월 25 14:53 rpc
-rw-rw----. 1 test     mail 0 12월 27 13:39 test
-rw-rw----. 1 test2    mail 0 12월 27 13:54 test2
-rw-rw----. 1 user1    mail 0 12월 26 14:17 user1
-rw-rw----. 1 user10   mail 0 12월 28 12:51 user10
-rw-rw----. 1 user11   mail 0 12월 28 12:58 user11
-rw-rw----. 1     2014 mail 0 12월 28 13:15 user12        // 2014 : user12가 사용했던 uid
-rw-rw----. 1 user13   mail 0 12월 28 13:16 user13
-rw-rw----. 1 user2    mail 0 12월 26 14:24 user2
-rw-rw----. 1 user3    mail 0 12월 26 14:26 user3
-rw-rw----. 1 user4    mail 0 12월 26 14:29 user4
-rw-rw----. 1 user6    mail 0 12월 26 14:42 user6
-rw-rw----. 1 user7    mail 0 12월 26 15:05 user7
-rw-rw----. 1 user8    mail 0 12월 27 13:06 user8
-rw-rw----. 1 user88   mail 0 12월 27 13:25 user88
-rw-rw----. 1 user9    mail 0 12월 27 14:31 user9
-rw-rw----. 1 userfive mail 0 12월 26 14:33 userfive
[root@localhost itbank]#

// userdel -r user13

[root@localhost itbank]# tail -1 /etc/passwd
user13:x:2015:2015::/bonwon/user13:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# userdel -r user13
[root@localhost itbank]#
[root@localhost itbank]# tail -1 /etc/passwd
user11:x:2013:2013::/home/user11:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# tail -1 /etc/shadow
user11:!!:17528:0:99999:7:::
[root@localhost itbank]#
[root@localhost itbank]# tail -1 /etc/group
user11:x:2013:
[root@localhost itbank]#
[root@localhost itbank]# ls -l /bonwon
합계 0
drwx------. 4     2014  2014 92 12월 28 13:15 user12
drwx------. 3 userfive user5 94 12월 26 15:00 userfive
[root@localhost itbank]#
[root@localhost itbank]# ls -l /var/spool/mail/user13
ls: cannot access /var/spool/mail/user13: 그런 파일이나 디렉터리가 없습니다
[root@localhost itbank]#
[root@localhost itbank]#

// 작업했던 user들 모두 삭제

 

[root@localhost itbank]# tail -19 /etc/passwd
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
itbank:x:1000:1000:dust:/home/itbank:/bin/bash
linux1:x:1001:1001::/AS/Linux/linux1:/bin/bash
user1:x:1002:1002::/home/user1:/bin/bash
user2:x:1004:1004::/home/user2:/bin/bash
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/jongno/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
test:x:1012:1012::/jongro/test:/bin/bash
test2:x:2011:1013:seoul:/jongno/test2:/bin/sh
user9:x:1014:1014::/centos/user9:/bin/tcsh
userfive:x:1007:1007::/bonwon/userfive:/bin/csh
user10:x:2012:2012::/centos/user10:/bin/tcsh
user11:x:2013:2013::/home/user11:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# userdel -r user1
[root@localhost itbank]# userdel -r user2
[root@localhost itbank]# userdel -r user3
[root@localhost itbank]# userdel -r user4
[root@localhost itbank]# userdel -r userfive
[root@localhost itbank]# userdel -r user6
[root@localhost itbank]# userdel -r user7
[root@localhost itbank]# userdel -r user8
[root@localhost itbank]# userdel -r user88
[root@localhost itbank]# userdel -r test
[root@localhost itbank]# userdel -r test2
[root@localhost itbank]# userdel -r user9
[root@localhost itbank]# userdel -r user10
[root@localhost itbank]# userdel -r user11
[root@localhost itbank]#

// passwd에 관한 정보는 지워지는데

// 에러 뜨는 경우는 (userdel -r 계정명 (home dir, mail까지 다 날림))

=> E1. user100 의 소유가 아닙니다.(root꺼 useradd시 home dir. 설정 안 해줌)

 

=> E2. not found(useradd 잘 해줬는데, 이미 home dir.을 rm -rf 로 날려버림)

// home dir.에 관한 거임

 

 

<실습 1>

/etc/skel 디렉터리 하위에 존재하는 모든 것들을 /testskel 디렉터리에 복사를 한 후 사용자를 생성하시오

(조건1. /etc/skel 디렉터리 자체를 복사하지 마시오

조건2. /etc/skel 디렉터리를 이름 바꾸어서 복사하지 마시오

조건3. /testskel 디렉터리 하위에 another 디렉터리를 생성하시오)

 

사용자 계정명은 user8

 

[준비물]

[root@localhost itbank]# rm -rf /etc/skel/junga
[root@localhost itbank]#
[root@localhost itbank]# ls -la /etc/skel/
합계 24
drwxr-xr-x.   3 root root   78 12월 27 12:53 .
drwxr-xr-x. 135 root root 8192 12월 27 12:36 ..
-rw-r--r--.   1 root root   18  9월  7 01:25 .bash_logout
-rw-r--r--.   1 root root  193  9월  7 01:25 .bash_profile
-rw-r--r--.   1 root root  231  9월  7 01:25 .bashrc
drwxr-xr-x.   4 root root   39  9월 25 14:49 .mozilla

// sol>

# mkdir /testskel

[root@localhost itbank]# ls -la /testskel/
합계 12
drwxr-xr-x.  4 root root  93 12월 27 13:05 .            // 현재 위치   /testskel
dr-xr-xr-x. 21 root root 278 12월 27 12:55 ..           // 최상위       /    (root)  

# cp -r /etc/skel/.bash_logout /etc/skel/.bash_profile /etc/skel/.bashrc /etc/skel/.mozilla /testskel

# cp /etc/skel/.* /testskel        // 안보이는 모든 것 copy /etc/skel의

                       // -r 옵션을 쓰면.  .. 까지 복사되므로 여기까지..,

# ls -la /testskel                    

파일까지만 됨

# cp -r /etc/skel/.mozila /testskel            // testskel skel dir.

[root@localhost itbank]# ls -la /testskel/
합계 12
drwxr-xr-x.  4 root root  93 12월 27 13:05 .
dr-xr-xr-x. 21 root root 278 12월 27 12:55 ..
-rw-r--r--.  1 root root  18 12월 27 13:02 .bash_logout
-rw-r--r--.  1 root root 193 12월 27 13:04 .bash_profile
-rw-r--r--.  1 root root 231 12월 27 13:02 .bashrc
drwxr-xr-x.  4 root root  39 12월 27 13:05 .mozilla
drwxr-xr-x.  2 root root   6 12월 27 12:56 another

// skel 지정 등록 (/testskel을 skel dir로 지정하겠다)
[root@localhost itbank]# useradd -mk /testskel user88            

[root@localhost itbank]# tail -10 /etc/passwd
linux1:x:1001:1001::/AS/Linux/linux1:/bin/bash
user1:x:1002:1002::/home/user1:/bin/bash
user2:x:1004:1004::/home/user2:/bin/bash
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user5:x:1007:1007::/bonwon/userfive:/bin/csh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/home/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# ls -la /home/user88
합계 12
drwx------.  4 user88 user88  93 12월 27 13:25 .
drwxr-xr-x. 12 root   root   192 12월 27 13:25 ..
-rw-r--r--.  1 user88 user88  18 12월 27 13:02 .bash_logout
-rw-r--r--.  1 user88 user88 193 12월 27 13:04 .bash_profile
-rw-r--r--.  1 user88 user88 231 12월 27 13:02 .bashrc
drwxr-xr-x.  4 user88 user88  39 12월 27 13:05 .mozilla
drwxr-xr-x.  2 user88 user88   6 12월 27 12:56 another        // 자동생성 dir.

 

<실습 2>

/jongro/test(사용자)/public(자동 생성 디렉터리)

      ↑ home dir. 

0) /testskel2 생성

1) /testskel2에 /public dir 생성

2) test사용자 /jongro 홈 디렉터리로 지정하고. /testskel2 skel로 지정해서 useradd 'test'

 

// 쌤 풀이

[root@localhost itbank]# mkdir /etc/skel/public
[root@localhost itbank]#
[root@localhost itbank]# ls -la /etc/skel
합계 24
drwxr-xr-x.   4 root root   92 12월 27 13:52 .
drwxr-xr-x. 135 root root 8192 12월 27 13:39 ..
-rw-r--r--.   1 root root   18  9월  7 01:25 .bash_logout
-rw-r--r--.   1 root root  193  9월  7 01:25 .bash_profile
-rw-r--r--.   1 root root  231  9월  7 01:25 .bashrc
drwxr-xr-x.   4 root root   39  9월 25 14:49 .mozilla
drwxr-xr-x.   2 root root    6 12월 27 13:52 public
[root@localhost itbank]# mkdir /jongno
[root@localhost itbank]#
[root@localhost itbank]# ls -l /jongno
합계 0
[root@localhost itbank]#
[root@localhost itbank]# useradd -d /jongno/test2 test2
[root@localhost itbank]#
[root@localhost itbank]# tail /etc/passwd
user2:x:1004:1004::/home/user2:/bin/bash
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user5:x:1007:1007::/bonwon/userfive:/bin/csh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/home/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
test:x:1012:1012::/jongro/test:/bin/bash
test2:x:1013:1013::/jongno/test2:/bin/bash
[root@localhost itbank]#
[root@localhost itbank]# ls -la /jongno/test2
합계 12
drwx------. 4 test2 test2  92 12월 27 13:54 .
drwxr-xr-x. 3 root  root   19 12월 27 13:54 ..
-rw-r--r--. 1 test2 test2  18  9월  7 01:25 .bash_logout
-rw-r--r--. 1 test2 test2 193  9월  7 01:25 .bash_profile
-rw-r--r--. 1 test2 test2 231  9월  7 01:25 .bashrc
drwxr-xr-x. 4 test2 test2  39  9월 25 14:49 .mozilla
drwxr-xr-x. 2 test2 test2   6 12월 27 13:52 public
[root@localhost itbank]#

 

// 내가 한거

[root@localhost itbank]# mkdir /testskel2
[root@localhost itbank]#
[root@localhost itbank]# ls -la /etc/skel/
합계 24
drwxr-xr-x.   3 root root   78 12월 27 12:53 .            
drwxr-xr-x. 135 root root 8192 12월 27 13:25 ..
-rw-r--r--.   1 root root   18  9월  7 01:25 .bash_logout
-rw-r--r--.   1 root root  193  9월  7 01:25 .bash_profile
-rw-r--r--.   1 root root  231  9월  7 01:25 .bashrc
drwxr-xr-x.   4 root root   39  9월 25 14:49 .mozilla
[root@localhost itbank]#
[root@localhost itbank]# cp /etc/skel/.* /testskel2
cp: omitting directory `/etc/skel/.'
cp: omitting directory `/etc/skel/..'
cp: omitting directory `/etc/skel/.mozilla'
[root@localhost itbank]#
[root@localhost itbank]# ls -la /testskel2
합계 16
drwxr-xr-x.  2 root root   62 12월 27 13:37 .
dr-xr-xr-x. 22 root root 4096 12월 27 13:36 ..
-rw-r--r--.  1 root root   18 12월 27 13:37 .bash_logout
-rw-r--r--.  1 root root  193 12월 27 13:37 .bash_profile
-rw-r--r--.  1 root root  231 12월 27 13:37 .bashrc
[root@localhost itbank]#
[root@localhost itbank]# cp -r /etc/skel/.mozilla /testskel2
[root@localhost itbank]#
[root@localhost itbank]# ls -la /testskel2
합계 16
drwxr-xr-x.  3 root root   78 12월 27 13:37 .
dr-xr-xr-x. 22 root root 4096 12월 27 13:36 ..
-rw-r--r--.  1 root root   18 12월 27 13:37 .bash_logout
-rw-r--r--.  1 root root  193 12월 27 13:37 .bash_profile
-rw-r--r--.  1 root root  231 12월 27 13:37 .bashrc
drwxr-xr-x.  4 root root   39 12월 27 13:37 .mozilla
[root@localhost itbank]#
[root@localhost itbank]# mkdir /testskel2/public
[root@localhost itbank]#
[root@localhost itbank]# ls -la /testskel2
합계 16
drwxr-xr-x.  4 root root   92 12월 27 13:37 .
dr-xr-xr-x. 22 root root 4096 12월 27 13:36 ..
-rw-r--r--.  1 root root   18 12월 27 13:37 .bash_logout
-rw-r--r--.  1 root root  193 12월 27 13:37 .bash_profile
-rw-r--r--.  1 root root  231 12월 27 13:37 .bashrc
drwxr-xr-x.  4 root root   39 12월 27 13:37 .mozilla
drwxr-xr-x.  2 root root    6 12월 27 13:37 public

[root@localhost itbank]#
[root@localhost itbank]# mkdir /jongro
[root@localhost itbank]#
[root@localhost itbank]# ls /
AS      bonwon  etc     lib    mnt   root  srv       testskel2  var
backup  boot    home    lib64  opt   run   sys       tmp
bin     dev     jongro  media  proc  sbin  testskel  usr
[root@localhost itbank]#
[root@localhost itbank]# useradd -d /jongro/test -m -k /testskel2 test

또는

[root@localhost itbank]# useradd -m -k /testskel2 -d /jongro/test  test
[root@localhost itbank]#
[root@localhost itbank]# ls -la /jongro/test
합계 12
drwx------. 4 test test  92 12월 27 13:39 .
drwxr-xr-x. 3 root root  18 12월 27 13:39 ..
-rw-r--r--. 1 test test  18 12월 27 13:37 .bash_logout
-rw-r--r--. 1 test test 193 12월 27 13:37 .bash_profile
-rw-r--r--. 1 test test 231 12월 27 13:37 .bashrc
drwxr-xr-x. 4 test test  39 12월 27 13:37 .mozilla
drwxr-xr-x. 2 test test   6 12월 27 13:37 public
[root@localhost itbank]#
[root@localhost itbank]# tail -11 /etc/passwd
linux1:x:1001:1001::/AS/Linux/linux1:/bin/bash
user1:x:1002:1002::/home/user1:/bin/bash
user2:x:1004:1004::/home/user2:/bin/bash
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user5:x:1007:1007::/bonwon/userfive:/bin/csh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/home/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
test:x:1012:1012::/jongro/test:/bin/bash

 

<실습 3>

/etc/default/useradd

 

SHELL : /bin/tcsh : 문서를 이용한 변경

HOME : /centos : 명령어 이용한 변경

SKEL : /skel/test : 문서를 이용한 변경

User : user9

(조건! 사용자 계정을 생성할 대 옵션 쓰지 않고 생성하시오)

 // 백업

[root@localhost ~]# vi /etc/default/useradd

# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

 

// 쌤

#  useradd -D -b /centos

# vi /etc/default/useradd

SHELL

SKELL

편집

[root@localhost ~]# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/centos
INACTIVE=-1
EXPIRE=
SHELL=/bin/tcsh
SKEL=/skel/test
CREATE_MAIL_SPOOL=yes

[root@localhost ~]#
[root@localhost ~]# useradd -D
GROUP=100
HOME=/centos
INACTIVE=-1
EXPIRE=
SHELL=/bin/tcsh
SKEL=/skel/test
CREATE_MAIL_SPOOL=yes

 

# mkdir /centos

# ls -l /centos

#

// /skel/test 중    /skel

# mkdir /skel

# ls -l /skel

# cp -r /etc/skel /skel/test

# ls -la /skel/test

 

// /skel/test 중   

# cp -r /etc/skel /skel/test

# ls -la /skel/test

/test/ 안에 /skel 생성됨

# cp -r /etc/skel. /skel/test

# ls -la /skel/test

# rm -rf /etc/skel/public

#

# useradd user99

# tail -1 /etc/passwd

# ls -a /centos/user99

# ls -a /skel/test

 

cf. skel 만드는 법

/skel

cp -r /etc/skel /skel/test

 

/skel/test

cp -r /etc/skel/. /skel/test                // . : 현재 위치;  .* 을 쓰면 etc까지 들어가버려서 안됨!!!

 

 

// 내가 한거

[root@localhost ~]# cat /etc/shells  // shell 검색
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
[root@localhost ~]# mkdir /centos
[root@localhost ~]#
[root@localhost ~]# mkdir -p /skel/test            ////////////
[root@localhost ~]#
[root@localhost ~]# ls -la /etc/skel
합계 24
drwxr-xr-x.   4 root root   92 12월 27 13:52 .
drwxr-xr-x. 135 root root 8192 12월 27 14:12 ..
-rw-r--r--.   1 root root   18  9월  7 01:25 .bash_logout
-rw-r--r--.   1 root root  193  9월  7 01:25 .bash_profile
-rw-r--r--.   1 root root  231  9월  7 01:25 .bashrc
drwxr-xr-x.   4 root root   39  9월 25 14:49 .mozilla
drwxr-xr-x.   2 root root    6 12월 27 13:52 public
[root@localhost ~]#
[root@localhost ~]# cp /etc/skel/.* /skel
cp: omitting directory `/etc/skel/.'
cp: omitting directory `/etc/skel/..'
cp: omitting directory `/etc/skel/.mozilla'
[root@localhost ~]#
[root@localhost ~]# ls -la /skel/
합계 16
drwxr-xr-x.  3 root root   74 12월 27 14:29 .
dr-xr-xr-x. 26 root root 4096 12월 27 14:28 ..
-rw-r--r--.  1 root root   18 12월 27 14:29 .bash_logout
-rw-r--r--.  1 root root  193 12월 27 14:29 .bash_profile
-rw-r--r--.  1 root root  231 12월 27 14:29 .bashrc
drwxr-xr-x.  2 root root    6 12월 27 14:28 test
[root@localhost ~]#
[root@localhost ~]# cp -r /etc/skel/.mozilla /skel
[root@localhost ~]#
[root@localhost ~]# ls -la /skel/
합계 16
drwxr-xr-x.  4 root root   90 12월 27 14:29 .
dr-xr-xr-x. 26 root root 4096 12월 27 14:28 ..
-rw-r--r--.  1 root root   18 12월 27 14:29 .bash_logout
-rw-r--r--.  1 root root  193 12월 27 14:29 .bash_profile
-rw-r--r--.  1 root root  231 12월 27 14:29 .bashrc
drwxr-xr-x.  4 root root   39 12월 27 14:29 .mozilla
drwxr-xr-x.  2 root root    6 12월 27 14:28 test
[root@localhost ~]#
[root@localhost ~]# useradd -D -b /centos
[root@localhost ~]#
[root@localhost ~]# vi /etc/default/useradd
[root@localhost ~]#
[root@localhost ~]# useradd user9
[root@localhost ~]#
[root@localhost ~]# tail /etc/passwd
user3:x:1005:1005:testuser:/home/user3:/bin/bash
user4:x:1006:1006::/home/user4:/bin/sh
user5:x:1007:1007::/bonwon/userfive:/bin/csh
user6:x:1008:1008::/home/user6:/bin/bash
user7:x:1009:1009::/home/user7:/bin/bash
user8:x:1010:1010::/home/user8:/bin/bash
user88:x:1011:1011::/home/user88:/bin/bash
test:x:1012:1012::/jongro/test:/bin/bash
test2:x:1013:1013::/jongno/test2:/bin/bash
user9:x:1014:1014::/centos/user9:/bin/tcsh
[root@localhost ~]#
[root@localhost ~]# ls -la /centos/user9
합계 0
drwx------. 2 user9 user9  6 12월 27 14:31 .
drwxr-xr-x. 3 root  root  19 12월 27 14:31 ..
[root@localhost ~]#
[root@localhost ~]# ls -la /skel/test
합계 0
drwxr-xr-x. 2 root root  6 12월 27 14:28 .
drwxr-xr-x. 4 root root 90 12월 27 14:29 ..
[root@localhost ~]#
[root@localhost ~]# ls -la /skel
합계 16
drwxr-xr-x.  4 root root   90 12월 27 14:29 .
dr-xr-xr-x. 26 root root 4096 12월 27 14:28 ..
-rw-r--r--.  1 root root   18 12월 27 14:29 .bash_logout
-rw-r--r--.  1 root root  193 12월 27 14:29 .bash_profile
-rw-r--r--.  1 root root  231 12월 27 14:29 .bashrc
drwxr-xr-x.  4 root root   39 12월 27 14:29 .mozilla
drwxr-xr-x.  2 root root    6 12월 27 14:28 test
[root@localhost ~]#
[root@localhost ~]#

 

 

 

 

반응형
LIST

'BigData_Off1 > 리눅스1' 카테고리의 다른 글

리눅스1> 2017.12.29_13일차 - 권한> 1.허가권(Permission)  (0) 2017.12.29
리눅스1> 2017.12.28_12일차 - 그룹  (0) 2017.12.28
리눅스1> 2017.12.26_10일차- 사용자, shell  (0) 2017.12.22
VI (2)  (0) 2017.12.21
VI (1)  (0) 2017.12.19
Posted by 오정oI
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함