내밥줄/리눅스

[펌] Linux에서 Windows 파일시스템 사용하기 - Samba Server 사용하기

jjoell 2009. 1. 15. 09:57

Linux와 Windows간에 파일 공유를 위하여 Samba를 이용하는 방법에는 두가지가 있다

1. Windows에서 폴더 공유를 시킨 후 Linux에서 Samba-Client를 사용해서 접근


우선 윈도우즈에서 폴더를 공유시킨다.

User inserted image
User inserted image

공유이름 뒤에 $를 붙이면 다른 윈도우시스템에서 검색시
공유폴더가 표시되지 않아 아주 조금?이나마 안전하게 사용가능 하다.


다음은 Linux에서 작업해야 한다.

[root@localhost /]# yum install samba-client
Setting up Install Process
Parsing package install arguments
Package samba-client - 3.0.28a-0.fc8.i386 is already installed.
Nothing to do
[root@localhost /]#

이미 설치가 되어있다면 위와 같이 뜰것이고
설치되어 있지 않다면 알아서 설치가 될 것이다.



[root@localhost /]# smbclient -L 192.168.73.1 -U administrator%비밀번호
Domain=[5034-4] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

        Sharename       Type      Comment
        ---------       ----      -------
        E$              Disk      Default share
        pub$            Disk     
        IPC$            IPC       Remote IPC
        D$              Disk      Default share
        test$           Disk     
        ADMIN$          Disk      Remote Admin
        C$              Disk      Default share
session request to 192.168.73.1 failed (Called name not present)
session request to 192 failed (Called name not present)
Domain=[5034-4] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
[root@localhost media]#

윈도우에서 공유된 목록을 보여준다.
IP주소사용자 이름, 비밀번호는 알아서 바꿔 넣을 것



[root@localhost media]# mkdir aaa
[root@localhost media]# mount -t cifs //192.168.73.1/test$ /media/aaa -o username=administrator -o password=비밀번호 -o iocharset=cp949
[root@localhost media]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      19552940   4443984  14099704  24% /
/dev/sda1               194442     19073    165330  11% /boot
tmpfs                   192516        12    192504   1% /dev/shm
//192.168.73.1/test$  47688920     67608  47621312   1% /media/aaa
[root@localhost media]#

마운트 포인터로 사용할 디렉토리를 만들고 마운트를 한다.
df -k 명령어를 통해 마운트된 것을 확인 가능 하다.



[root@localhost media]# vi /etc/fstab
/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   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
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0
//192.168.73.1/test$  /media/aaa cifs username=administrator,password=비밀번호,iocharset=cp949 0 0
[root@localhost media]#

부팅시 자동으로 마운트되게 환경설정파일을 수정한다.
한줄에 이어서 써야 한다

※내경우

//192.168.xx.xx/doc$  /media/vmhost_doc cifs username=administrator,password=비밀번호,iochar=euc-kr,codepage=cp949 0 0


[root@localhost media]# mount -a
[root@localhost media]#

설정파일이 제대로 되었는지 확인.
아무 메세지가 없어야 정상이다.



[root@localhost aaa]# cd /media/aaa
[root@localhost aaa]# ls
[root@localhost aaa]# mkdir 하하하~
[root@localhost aaa]# ls -al
합계 8
drwxrwxrwx 1 root root    0 2008-04-12 00:01 .
drwxr-xr-x 4 root root 4096 2008-04-11 19:54 ..
drwxr-xr-x 2 root root    0 2008-04-12 00:01 하하하~
[root@localhost aaa]#

Linux에서 디렉토리를 만들면...

User inserted image

당연히 Windows에서도 폴더가 보인다.
파일도 마찬가지고
반대로 Windows에서 파일/폴더를 만들어도 Linux에서 접근 가능하다.

 

 

 

 



2. Linux에서 Samba-Server를 설치해서 공유시킨 후 Windows에서 접근하는 방법

이번에는 조금 깐깐 할 수도 있는 2번의 방법을 알아보자. (Fedora 8 기준)


< 프로그램 설치 >

# yum install system-config-samba
# yum install samba-swat       (Option)



< SWAT(Samba Web Administration Tool) 설정 (Option) >

# vi /etc/xinetd.d/swat
service swat
{
        port            = 901
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/sbin/swat
        log_on_failure  += USERID
        disable         = no
}
# /etc/init.d/xinetd restart



< Linux 사용자 추가 및 Samba 사용자 등록 >

# groupadd -g 102 user
# useradd -u 1001 -g 102 -d /home/han2g -s /bin/bash han2g
# passwd han2g
# smbpasswd -a han2g



< Samba 환경설정 >

# vi /etc/samba/smb.conf
[global]
dos charset = CP949         /// 윈도우와 한글깨짐을 방지
unix charset = EUC-KR
workgroup = MYTV
netbios name = BIT
server string = VM_Fedora
security = SHARE
passdb backend = tdbsam
unix password sync = Yes
log file = /var/log/samba/log.%m
max log size = 50
ldap ssl = no
cups options = raw

[Han2g$]        /// 공유폴더명 뒤에 $를 붙이면, 사용은 가능하지만 검색되지 않음
path = /home/han2g
username = han2g
read only = No


< 서비스 시작 >

# /etc/rc.d/init.d/smb start
# /etc/rc.d/init.d/nmb start


< 공유폴더 접근 >

User inserted image

< Windows에서 네트웍 드라이브 설정 >
User inserted image


User inserted image


"smbpasswd"로 추가한 사용자명과 Password를 입력
User inserted image


User inserted image


Linux의 디렉토리를 Windows에서
일반 디스크처럼 마음대로 사용 가능하다
User inserted image

 

출처: http://cafe.daum.net/giois/FkVj/43

 

 

1. 다운로드.
*SAMBA 사이트 : http://www.samba.org/
*SAMBA 소스 : Download : http://us1.samba.org/samba/ftp/ , 한국 미러 사이트 : http://kr.samba.org/samba/ftp/

2. 설치
시스템에 삼바 프로그램이 설치되어 있는지 확인한다
#rpm -qa | grep samba

*RPM 파일 설치
#rpm -Uvh samba-2.x.x-x.i386.rpm
#rpm -Uvh samba-client-2.x.x-x.i386.rpm
#rpm -Uvh samba-common-2.x.x-x.i386.rpm

*소스 파일 설치
# tar xvzf samba-2.x.x.tar.gz -c src/
# cd src/samba-2.x.x/source
#./configure --prefix=/usr --libdir=/etc --localstatedir=/var --with-smbmount --with-automount
# make
# make install

3. smb.conf 파일 설정
#================================= Global Settings =================================
[global]

# workgroup = NT-Domain-Name or Workgroup-Name
workgroup = MYGROUP

/* 신의 시스템이 속해있는 작업 그룹을 설정하는 부분 - 대충 암꺼나 적어요.. */
# server string is the equivalent of the NT Description field
server string = Samba Server

/* samba server 에 대한 설명을 - 리눅스 박스 호스트 네임을 적어주세요. (클라이언트에서 이 이름으로 접속) */
# This option is import!ant for security. It allows you to restrict connections to machines
# which are on your local network. The following example restricts access to two C
# class networks and the "loopback" interface. For more examples of the syntax see
# the smb.conf man page

; hosts allow = 192.168.1. 192.168.2. 127. (보안상필수 - 꼭 필요한 아이피 대역만 설정)

/* 삼바 서버에 접속이 가능한 호스트를 지정한다. default 설정은 192.168.1.0과 192.168.2.0의 두 개의 C class network address 와 loopback 에 대해서만 접근을 허락한 경우이다. network address 는 마지막에 점(dot) 으로 표현한다. */

# 프린터부분 주석은 삭제 했슴 - 사용해보실분은 더 자세한 문서를 참고하세요..

# Uncomment this if you want a guest account, you must add this to /etc/passwd
# otherwise the user "nobody" is used
; guest account = pcguest
/* samba server 에 Guest 계정으로 접근을 허락하기를 원한다면 주석(;)을 제거해 준다.- 절대 사용금지. 꼭 막을것*/

# this tells Samba to use a separate log file for each machine that connects
log file = /var/log/samba/%m.log
/* samba log file 위치를 지정해주는 부분이다. */

# Put a capping on the size of the log files (in Kb).
max log size = 0
/* log file 의 최대 크기를 지정하는 것으로 단위는 KB 이다. */

# Security mode. Most people will want user level security. See security_level.txt for details.
security = share
/*
클라이언트가 삼바서버에 접속할때 보안 모드를 설정하는 부분이다. 보안 레벨은 user, share, server, domain level 로 네 가지로 나누어진다.

user level 의 경우는 리눅스 계정과 윈도우 사용자가 동일하다면 user level 로 설정한다.
user level 은 samba server 접속 시 한 번 인증에 성공하게되면 다음 접속 부터 패스워드를 묻지 않는다.
따라서, Win 사용자가 여러명일 경우 다소 문제가 될 수 있다. default 로 이 user level mode 를 사용한다.

-> 임시 방편으로 모든 네트웤 클라이언트의 로그인시 사용자 이름을 통일하는 방법도 가능하다.. -.-;;


share level 의 경우는 공유자원/패스워드 방식으로 samba server 에 인증을 하는 방식이다.
Linux 계정과 Win 사용자가 다를 경우, 다시말하면 리눅스 사용자/패스워드와 윈도우 사용자/패스워드가 서로 다를 경우 share level 으로 설정한다.server level 의 경우는 NT server 가 필수적으로 필요한 security level 이다.

server level은 기본적으로 user모드뫄 동일한데, 단지 사용자 계정의 인증 처리를 현재 시스템에서 하는것이아니라 SMB 프로토콜을 지원하는 다른서버를 통해 처리하는 방식이다.

domain level 은 아예 Windows NT 도메인으로 삼바 서버를 참가시키는 방법을 사용한다. 이 보안 모드에서는 삼바 서버가 WIndows NT의 PDC나 BDC(Backup Domain Controller)에 사용자 계정과 암호의 쌍을 전송하여 인증을 위임하게 된다.

-> 대부분의 경우 한대 삼바서버에 여러대의 윈도우 클라이언트 환경이므로 레벨은 share 가 된다.
추후 smbusers 파일에서 여러개의 클라이언트 로그인 아이디를 하나의 삼바 아이디에 매핑 시켜 준다.
*/
-> 이하 주석은 생략.. 특별한 상황이 없다면 기본값으로 사용해도 무방합니다.
-> 공유 디렉토리는 외부 접속이 불가능한 내부 네트웤이 아니면 운영하지 않을것을 권합니다.


3.2.2 공유 정의 설정-Share Definitions
#================================ Share Definitions ================================
[homes]
comment = Home Directories
/* Home directory 에 대한 comment 를 설정하는 부분이다. server string 과 유사 */
browseable = no
/* home 이라는 공유 이름을 borwser 에 표시할 수 있도록 하는 설정이다. */
writable = yes
/* 쓰기 허용을 설정하는 부분이다. */

# Un-comment the following and create the netlogon directory for Domain Logons
; [netlogon]
; comment = Network Logon Service
; path = /usr/local/samba/lib/netlogon
; guest ok = yes
; writable = no
; share modes = no
/* 도메인 로그온을 사용자하고자 할 때 사용하는 부분으로 윈도우 사용자들은 대부분 설정할 필요가 없다. */


# Un-comment the following to provide a specific roving profile share the default is to use the user's home directory
;[Profiles]
; path = /usr/local/samba/profiles
; browseable = no
; guest ok = yes
/* 특정한 roving profile을 지정할 때 사용한다 */

# NOTE: If you have a BSD-style print system there is no need to specifically define each individual printer
[printers]
comment = All Printers
path = /var/spool/samba
browseable = no

# Set public = yes to allow user 'guest account' to print
guest ok = yes
/* guest 계정 으로 지정한 사용자, 즉 nobody 들이 printing 을 할 수 있다. */

writable = no
printable = yes
/* 대부분의 Linux system 에서 각각의 printer 를 정의해 줄 필요 없이 위에서 정한 방식으로 자동으로 이루어 진다. */

# This one is useful for people to share files
;[tmp]
; comment = Temporary file space
; path = /tmp
; read only = no
; public = yes
/* 여러사람이 공유할 디렉토리를 지정한다.*/

# A publicly accessible directory, but read only, except for people in the "staff" group
;[public]
; comment = Public Stuff
; path = /home/samba
; public = yes
; writable = yes
; printable = no
; write list = @staff
/* 공개적으로 접근이 가능한 디렉토리를 지정하는 것으로 staff 그룹에 있는 사용자들을 제외한 사용자들을 오직 읽기만 사용 가능하도록 지정한 것을 보여주고 있다. 공유 디렉토리를 지정할 때 사용하는 옵션들은 다음과 같다
- read only : 공유 디렉토리를 읽기만 가능하다
- writeble users : 공유 디렉토리를 쓰기 가능하다
- valid users : 공유 디렉토리에 로그인 할 수 있도록 한다
- public, guest ok : 다른 사용자들이 이용할 수 있도록 한다
- browseable : 공유 디렉토리의 리스트를 보여준다
- printable : 공유 디렉토리에 스풀 파일을 저장할 것인지를 지정한다
- path : 공유할 디렉토리의 절대 경로이다
- comment : 코멘트를 뜻한다
- create mask, creat mode : 파일을 생성할 때 사용되는 모드를 의미한다
- write list : 쓰기가 가능한 특정 사용자를 지정한다

4. SMB서버 작동 확인


1) 삼바 실행
# /etc/init.d/smb start

2) 삼바 사용자 추가
삼바 서버 계정은 smbadduser 명령을 사용한다.
-> 클라이언트의 한글이름은 아직 지원되지 않는거 같다..
즉 삼바서비스를 이용하려면 윈도우 로그인시 영문계정을 사용.영문 계정이 관리상 여러모로 정신건강상 유리하다.
#smbadduser wooky:wooky

앞에 계정은 리눅스 사용자 계정이고 뒤에 계저은 윈도우 사용자 계정이다. 수정하려면 smbpasswd 명령을 사용한다.
#smbpasswd wooky:wooky

3) /etc/samba/smbusers 예
-> 삼바 서버 계정 samba 에 윈도우 클라이언트가. aaa, bbb, ccc 로 로그인 한 경우
samba = aaa bbb ccc

출처: http://cafe.daum.net/giois/FkVj/44