본문 바로가기

Linux Server 구축/5-1. SAMBA Server

SAMBA Server


Samba Server
- 이종간의 운영체제와 자원 공유 프로토콜
- 리눅스 자원을 윈도우에서 공유
- 리눅스 프린터를 윈도우에서 공유

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

1. Samba 설치 & 환경 설정

[root@server3 ~]# rpm -qa | grep samba
samba-common-3.0.28-0.el5.8
samba-client-3.0.28-0.el5.8
samba-3.0.28-0.el5.8
system-config-samba-1.2.39-1.el5

[root@server3 ~]# system-config-packages
패키지 관리자 -> 서버 -> windows 파일 서버 -> samba

[root@server3 ~]# rpm -qi samba
Name        : samba                        Relocations: (not relocatable)
Version     : 3.0.28                            Vendor: CentOS
Release     : 0.el5.8                       Build Date:
Install Date:       Build Host: builder16.centos.org
Group       : System Environment/Daemons    Source RPM: samba-3.0.28-0.el5.8.src.rpm
Size        : 31428279                         License: GNU GPL Version 2
Signature   : DSA/SHA1, 2008년 06월 15일 (일) 오전 08시 40분 31초, Key ID a8a447dce8562897
URL         : http://www.samba.org/
Summary     : Samba SMB 서버.
Description :

Samba is the suite of programs by which a lot of PC-related machines
share files, printers, and other information (such as lists of
available files and printers). The Windows NT, OS/2, and Linux
operating systems support this natively, and add-on packages can
enable the same thing for DOS, Windows, VMS, UNIX of all kinds, MVS,
and more. This package provides an SMB server that can be used to
provide network services to SMB (sometimes called "Lan Manager")
clients. Samba uses NetBIOS over TCP/IP (NetBT) protocols and does NOT
need the NetBEUI (Microsoft Raw NetBIOS frame) protocol.
[root@server3 ~]#

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

2. Samba 설치 폴더 확인 & 환경설정 파일

[root@server3 ~]# cd /etc/samba
[root@server3 samba]# ls
lmhosts  smb.conf  smbusers
[root@server3 samba]# vi smb.conf

59 # ----------------------- Network Related Options -------------------------
60 #
61 # workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
62 #
63 # server string is the equivalent of the NT Description field
64 #
65 # netbios name can be used to specify a server name not tied to the hostname
66 #
67 # Interfaces lets you configure Samba to use multiple interfaces
68 # If you have multiple network interfaces then you can list the ones
69 # you want to listen on (never omit localhost)
70 #
71 # Hosts Allow/Hosts Deny lets you restrict who can connect, and you can
72 # specifiy it as a per share option as well
73 #
74         workgroup = MYGROUP
- 자신의 시스템이 속해 있는 workgroup을 설정한다.
- 윈도우의 경우 WORKGROUP 또는 MYHOME 으로 되어 있으니 윈도우나 삼바 둘중에서 하나를 변경해 통일 시켜준다.

75         server string = Samba Server Version %v - 삼바 서버에 대한 설명을 입력한다.
76
77 ;       netbios name = MYSERVER
78
79 ;       interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
80 ;       hosts allow = 127. 192.168.12. 192.168.13.
- 삼바서버에 접속하는 클라이언트 네트워크를 허용하는 설정이다.
- hosts deny, EXCEPT 지시자를 통해 접속 거부할 클라이언트 네트워크를 설정할수 있다.
예) hosts allow = 192.168.0.7 : 192.168.0.7 호스트에 대해 접속을 허용
예) hosts allow = 192.168.0. EXCEPT 192.168.1.4 : 192.168.1.4 호스트는 제외하고 192.168.0. 대역에 대해 허용하겠다.

93 # ----------------------- Standalone Server Options ------------------------
94 #
95 # Security can be set to user, share(deprecated) or server(deprecated)
96 #
97 # Backend to store user information in. New installations should
98 # use either tdbsam or ldapsam. smbpasswd is available for backwards
99 # compatibility. tdbsam requires no further configuration.
100
101         #security = user   - 클라이언트가 삼바서버에 접속할 때의 보안모드를 설정한다.
102         security = share
103         passdb backend = tdbsam

보안모드 4가지
user : 삼바서버에 접속하는 클라이언트는 사용자명/패스워드를 입력해야만 삼바서버에 접속이 가능하다.
share : 삼바서버에 사용자명/패스워드 인증없이 삼바서버에 접속이 가능하다.
server : 윈도우 NT와 같은 다은 삼바서버를 통해 사용자명/패스워드를 전달하여 유효한지 확인한다. 인증처리를 다른 서버를 통해 처리한다.
domain : 윈도우 NT서버가 존재해야 하며 사용자명/패스워드를 도메인 컨트롤러에 전달하여 유효한지 확인한다.

209 # --------------------------- Printing Options -----------------------------
210 #
211 # Load Printers let you load automatically the list of printers rather
212 # than setting them up individually
213 #
214 # Cups Options let you pass the cups libs custom options, setting it to raw
215 # for example will let you use drivers on your Windows clients
216 #
217 # Printcap Name let you specify an alternative printcap file
218 #
219 # You can choose a non default printing system using the Printing option
220
221         load printers = yes - /etc/printcap 파일의 프린트 목록을 로딩될수 있도록 설정한다.
222         cups options = raw - cups 옵션으로 raster zed를 raw로 선택한다.
223
224 ;       printcap name = /etc/printcap - 삼바서버를 프린터 서버로 운영할 경우 프린터 설정 경로를 지정한다.
225         #obtain list of printers automatically on SystemV
226 ;       printcap name = lpstat
227 ;       printing = cups - 지원하는 프린터 시스템을 지정한다.

246 #============================ Share Definitions ==============================
247
248 [homes] - 삼바에 로그인한 사용자의 홈디렉토리와 관련된 설정이다. security = user로 설정되어 있다면 로그인한 사용자의 홈디렉토리가 공유목록에 나타난다.
249         comment = Home Directories
250         browseable = no
251         writable = yes
252 ;       valid users = %S
253 ;       valid users = MYDOMAIN\%S  
254
255 [printers] - 프린터와 관련된 설정이다.
256         comment = All Printers
257         path = /var/spool/samba
258         browseable = no
259         guest ok = no
260         writable = no
261         printable = yes
262
263 # Un-comment the following and create the netlogon directory for Domain Logons
264 ;       [netlogon]
265 ;       comment = Network Logon Service
266 ;       path = /var/lib/samba/netlogon
267 ;       guest ok = yes
268 ;       writable = no
269 ;       share modes = no
270
271
272 # Un-comment the following to provide a specific roving profile share
273 # the default is to use the user's home directory
274 ;       [Profiles]
275 ;       path = /var/lib/samba/profiles
276 ;       browseable = no
277 ;       guest ok = yes
278
279
280 # A publicly accessible directory, but read only, except for people in
281 # the "staff" group
282 ;       [public]
283 ;       comment = Public Stuff
284 ;       path = /home/samba
285 ;       public = yes
286 ;       writable = yes
287 ;       printable = no
288 ;       write list = +staff  - staff라는 그룹만 공유폴더를 사용할수 있다.

291 [server3_share]
292         comment = server3.co.kr_share
293         path = /share
294         guest ok = yes
295         writable = yes
296        #writable = no - 들어올수는 있지만 쓰기 기능은 없다.
297 ;       write list = +staff  - staff라는 그룹만 공유폴더를 사용할수 있다.
298 ;       valid users =movie  - movie 사용자만 공유 폴더에 접근 권한과 쓰기 기능을 쓸수 있고 다른 사용자들은 접근 권한과 쓰기 기능이 없다. 
    
-------------------------------------------------------------------

공유폴더의 퍼미션 설정

[root@server3 ~]# mkdir /share
[root@server3 ~]# chmod 757 /share or chmod 777 /share - 공유 폴더의 퍼미션 설정
[root@server3 ~]# ls -ld /share
drwxr-xrwx 2 root root 4096 12월 22 14:04 /share

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

3. Samba 서비스 시작

[root@server3 ~]# service smb start
SMB서비스를 시작 중:                                       [  OK  ]
NMB서비스를 시작 중:                                       [  OK  ]
[root@server3 ~]#

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

4. Samba 확인

4-1. 리눅스에서 확인
컴퓨터  -> 네트워크 ->  윈도우즈 네트워크 -> (설정한) workgroup

4-2. 윈도우즈에서 확인
시작 -> 실행 -> \\10.10.33.3 입력 또는 내 네트워크 환경 -> 작업그룹 컴퓨터 보기 -> (설정한) workgroup

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

5. 유저모드

- 윈도우에서 삼바서버의 경우 처음 패스워드가 인증이 되면  pc가 재부팅하기 전까지 계속 유지된다.

5-1. 삼바서버에서 사용할 패스워드 설정

삼바서버의 유저모드를 사용하기 전 삼바서버를 위한 새로운 계정과 패스워드가 필요하다.

[root@server3 ~]# smbpasswd -a guest   - guest의 samba용 패스워드를 새로 만들어 추가해준다.
New SMB password:
Retype new SMB password:
Added user guest.
[root@server3 ~]#

- 참고
[root@server3 samba]#smbpasswd -x guest - guest 사용자의 삼바 사용자 계정을 삭제한다.
Deleted user guest.
[root@server3 samba]#smbpasswd -d guest - guest  사용자의 삼사 사용자 계정을 사용중지한다.
Disabled user guest.

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

5-2. samba 환경설정

[root@server3 ~]# vi /etc/samba/smb.conf

101         security = user  - 공유폴더의 권한을 user 로 변경해 준다.
102 #       security = share
103         passdb backend = tdbsam

- 참고
guest사용자로 로그인을 하면 /etc/samba/smb.conf에서 다음의 설정에 의해

249 [homes]
250         comment = Home Directories
251         browseable = no
252         writable = yes
253 ;       valid users = %S
254 ;       valid users = MYDOMAIN\%S

- guest의 홈디렉토리도 같이 공유가 된다. 즉, 내가 공유한 디렉토리 + guest의 홈디렉토리가 같이 공유가 된다.

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

5-3. 서비스 재시작 & 확인

[root@server3 ~]# service smb restart
SMB 서비스를 종료 중:                                      [  OK  ]
NMB 서비스를 종료 중:                                      [  OK  ]
SMB서비스를 시작 중:                                       [  OK  ]
NMB서비스를 시작 중:                                       [  OK  ]


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

5-4. Samba 서버 확인



- 이제 공유된 폴더로 접근시에는 samba ID와 password를 물어보게 된다.

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

6. 유저모드의 예제

사용자 : tset1, test2, test3, admin
폴   더 : insa, edu, man

insa - test1 // edu - test2 // man - test3 // admin은 모든 폴더에 접속가능하게 설정하시오.

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

6-1. 사용자 생성 및 패스워드 설정

6-1-1. 사용자 생성

[root@sever3.co.kr ~]# useradd test1
[root@sever3.co.kr ~]# useradd test2
[root@sever3.co.kr ~]# useradd test3
[root@sever3.co.kr ~]# useradd admin

6-1-2. 사용자 패스워드 지정 & 삼바 패스워드 지정

[root@bban2 ~]# passwd test1
Changing password for user test1.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@bban2 ~]# passwd test2
Changing password for user test2.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@bban2 ~]# passwd test3
Changing password for user test3.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@bban2 ~]# passwd admin
Changing password for user admin.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

smb 패스워드 지정

[root@bban2 ~]# smbpasswd -a test1
New SMB password:
Retype new SMB password:
Added user test1.
[root@bban2 ~]# smbpasswd -a test2
New SMB password:
Retype new SMB password:
Added user test2.
[root@bban2 ~]# smbpasswd -a test3
New SMB password:
Retype new SMB password:
Added user test3.
[root@bban2 ~]# smbpasswd -a admin
New SMB password:
Retype new SMB password:
Added user admin.

6-1-3. 공유 폴더 생성 및 퍼미션 설정


[root@server3 ~]# mkdir /insa
[root@server3 ~]# mkdir /edu
[root@server3 ~]# mkdir /man
[root@server3 ~]# chmod 757 /insa  -
퍼미션 757 or 777 로 수정
[root@server3 ~]# chmod 757 /edu
[root@server3 ~]# chmod 757 /man

[root@bban2 /]# ll

drwxr-xrwx   2 root root  4096 12월 27 17:18 edu
drwxr-xrwx   2 root root  4096 12월 27 17:18 insa
drwxr-xrwx   2 root root  4096 12월 27 17:19 man

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

6-2. 삼바의 환경 설정 - 유저모드

# vi /etc/samba/smb.conf

    101         security = user
    102 #       security = share

    291 [share]  
- 공동으로 사용하는 공유폴더 설정
    292         comment = bban2_share
    293         path = /Download
    294         guest ok = yes
    295         writable = yes
    296
    297 [insa_share]   - insa 공유 폴더 설정

    298         comment = insa_share
    299         path = /insa
    300         writable = yes
    301         valid users = test1 admin   - test1, admin만 접속하도록 설정한다.

    302
    303 [edu_share]
    304         comment = edu_share
    305         path = /edu
    306         writable = yes
    307         valid users = test2 admin
    308 
    309 [man_share]
    310         comment = man_share
    311         path = /man
    312         writable = yes
    313         valid users = test3 admin

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

6-3. testparm

- /etc/samba/smb.conf 설정에 대한 구문을 체크하거나 samba서버의 공유설정을 확인할때 사용한다.

[root@bban2 ~]# testparm
Load smb config files from /etc/samba/smb.conf
Processing section "[homes]"
Processing section "[printers]"
Processing section "[share]"
Processing section "[insa_share]"
Processing section "[edu_share]"
Processing section "[man_share]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

[global]
        workgroup = BBAN2
        server string = Samba Server Version %v
        passdb backend = tdbsam
        cups options = raw

[homes]
        comment = Home Directories
        read only = No
        browseable = No

[printers]
        comment = All Printers
        path = /var/spool/samba
        printable = Yes
        browseable = No

[share]
        comment = bban2_share
        path = /Download
        read only = No
        guest ok = Yes

[insa_share]
        comment = insa_share
        path = /insa
        valid users = test1, admin
        read only = No

[edu_share]
        comment = edu_share
        path = /edu
        valid users = test2, admin
        read only = No

[man_share]
        comment = man_share
        path = /man
        valid users = test3, admin
        read only = No

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

6-4. 서비스 재시작

[root@server3 ~]# service smb restart
SMB 서비스를 종료 중:                                      [  OK  ]
NMB 서비스를 종료 중:                                      [  OK  ]
SMB서비스를 시작 중:                                       [  OK  ]
NMB서비스를 시작 중:                                       [  OK  ]


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

6-5. Samba 서버 확인





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

7. 유저모드 - 그룹접근 설정의 예


linux 공유 폴더에 linux 그룹만 접근가능하고 나머지 사용자들은 볼수는 있지만 쓰기 기능은 없게 설정하시오.

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

7-1. 그룹 생성 및 퍼미션 설정


[root@server3 home]# groupadd linux
[root@bban2 ~]# mkdir /linux
[root@bban2 /]# chmod 770 linux  - linux 폴더의 퍼미션을 root와 그룹만 접근하도록 수정한다.
[root@bban2 /]# ll
drwxrwx---   2 root root  4096 12월 27 17:42 linux

[root@bban2 /]# chown root.linux linux  - linux 폴더에 linux 그룹이 접근할 수 있도록 수정해준다.
[root@bban2 /]# ll
drwxrwx---   2 root linux  4096 12월 27 17:42 linux

[root@server3 home]# vi /etc/group - linux 그룹에 test1, test2, test3, admin 사용자를 추가해준다.

linux:x:505:test1,test2,test3,admin

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

7-2. Samba 환경 설정


[root@server3 samba]# vi smb.conf

    315 [linux_share]
    316         comment = Linux_Group
    317         path = /linux
    318         write list=@linux

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

7-3. testparm


[root@bban2 /]# testparm
Load smb config files from /etc/samba/smb.conf
Processing section "[homes]"
Processing section "[printers]"
Processing section "[share]"
Processing section "[insa_share]"
Processing section "[edu_share]"
Processing section "[man_share]"
Processing section "[linux_share]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

[global]
        workgroup = BBAN2
        server string = Samba Server Version %v
        passdb backend = tdbsam
        cups options = raw

[homes]
        comment = Home Directories
        read only = No
        browseable = No

[printers]
        comment = All Printers
        path = /var/spool/samba
        printable = Yes
        browseable = No

[share]
        comment = bban2_share
        path = /Download
        read only = No
        guest ok = Yes

[insa_share]
        comment = insa_share
        path = /insa
        valid users = test1, admin
        read only = No

[edu_share]
        comment = edu_share
        path = /edu
        valid users = test2, admin
        read only = No

[man_share]
        comment = man_share
        path = /man
        valid users = test3, admin
        read only = No

[linux_share]
        comment = Linux_Group
        path = /linux
        write list = @linux

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

7-4. Samba 서비스 재시작


[root@server3 samba]# service smb restart
SMB 서비스를 종료 중:                                      [  OK  ]
NMB 서비스를 종료 중:                                      [  OK  ]
SMB서비스를 시작 중:                                       [  OK  ]
NMB서비스를 시작 중:                                       [  OK  ]

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

7-5. Samba 서버 확인






- linux 폴더에 접근하려고 하면 권한이 없다고 나온다.

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

8. Smbclient


삼바 클라이언트 명령으로 삼바 서버로 접글 할때 FTP 형식으로 접근한다.

[root@server3 ~]# smbclient -L 192.168.0.7 - 192.168.0.7 삼바 서버의 상태를 출력한다.
Password:
Anonymous login successful
Domain=[BBAN2] OS=[Unix] Server=[Samba 3.0.28-0.el5.8]

        Sharename       Type      Comment
        ---------       ----      -------
        share           Disk      bban2_share
        insa_share      Disk      insa_share
        edu_share       Disk      edu_share
        man_share       Disk      man_share
        linux_share     Disk      Linux_Group
        IPC$            IPC       IPC Service (Samba Server Version 3.0.28-0.el5.8)
Anonymous login successful
Domain=[BBAN2] OS=[Unix] Server=[Samba 3.0.28-0.el5.8]

        Server               Comment
        ---------            -------
        BBAN2                Samba Server Version 3.0.28-0.el5.8

        Workgroup            Master
        ---------            -------
        BBAN2