Linux_Samba详解

Samba Server

Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,C/S架构,可用于用于Linux和Windows共享文件。SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。通过设置”NetBIOS over TCP/IP”使得Samba不但能与局域网络主机分享资源,还能与全世界的电脑分享资源。 
Samba:File share service(windows <–> linux),support edit(on-line) file’s content.Can be prevent the infection virus on windows OS. 
You can setup the Samba server on Window or Linux. 
Linux OS: 
Protocol:SMB(Server message Block) Protocol 
Port:TCP139 UDP137 
Window OS: 
Protocol:CIFS(Common Internet File System) Protocol 
Port: TCP445 UDP138

Parameter

Program: smbd(Commonly used)\umdbd(Rarely used) 
Software: 
samba-3.033-3.28.el5 
samba-common 
samba-client(Web GUI management samba service,Rarely used) 
configure file: 
/etc/samba/smb.conf 
Tools for Check configure:testparm

Configuration file explain

Vim /etc/samba/smb.conf

#Section:
[global]                 #Global Setting
workgroup =              #work group name
security = [share|user|server]            #select one out of three
                    #share --> don't need the authentication
                    #user --> login the samba server share directory by local samba user authentication
                    #server --> user authentication by network
log file =  #log file store url

[homes]              #share /home directory

[printers]           #Printers set

[userShare]          #user-defined share directory
comment =            #description of share directory
path =               #share directory path
browseable = [yes|no]           #samba service share directory whether show in the Network Neighborhood of windows OS.General the value is "yes"
guest ok = [yes|no]     #share directory whether can access by anonymous user
                         #yes --> support anonymous user access
                         #no --> access by authentication
valid users = userName,@groupName           #Allow user who can login share directory
writable = [yes|no]           #User whether have permission to write in the share directory
write list = userName,@groupName              #Allow user who have write permission in the share directory
public = [yes|no]             #whether support anonymous user to login the share directory
create mode = 0644            #Set the default permissions of file when you create a new file in the share directory
directory mode = 0755         #Set the default permissions of directory when you create a new sub-directory in the share directory
#Attention: If you want to write into the share directory, you have to meet two condition.
#        1.Set option "writable = yes" into the config file
#        2.The share directory have permissions of writable(rw-rw-rw-)
  • 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
  • 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

Check samba config file: 
1.Use command grep:

grep -V "^#" smb.conf | grep -V "^;" | grep -V ^$
  • 1
  • 1

2.Use command supported by samba service

testparm  #Check and read the config file
  • 1
  • 1

Setup the Samba Server

Step1. Install samba and check the config file

yum in stall -y samba samba-common samba-client
grep -V "^#" /etc/samba/samba.conf | grep -V "^;" | grep -V ^$    #Look up the configuration file
testparm
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

Step2. Edit samba service config file. 
vim /etc/samba/smb.conf

#Example:
        [global]
            security = user
            hosts allow = 127. 192.168.8. 10.20.0.  #limit access from IP address, Only allow access from network-segment with (127./192.168.8./10.20.0.)
            hosts deny = 172.16.8.                  #Deny every access from 172.16.8.
        [myshare]
            comment = Jmilk share driectory
            path = /tmp/myshare      #share dir with /tmp/myshare
            browseable = yes
            guest ok = no
            valid users = jmilk,@jmilkGroup
            writable = yes
            write list = jmilk,@jmilkGroup
            create mode = 0644
            public = no
            directory mode = 0755
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

**Step3.**change the permission for share directory

chmod 757 /tmp/myshare     #ensure the share directory have writable permissions
  • 1
  • 1

Step4. Create samba user in local, and setting not support login the OS for samba user. 
Precondition:samba userName have to the same as OS userName.

useradd -M -s /sbin/nologin jsamba
pdbedit -a -u jsamba
        #-a create
        #-u userName
smbpasswd jsamba    #change the password for samba user
pdbedit -Lv jsamba  #list samba user detailed info
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Step4. Start samba service

service smbd restart
  • 1
  • 1

Access the samba shareDirectory from other linux OS

Samba Server:Linux 
Samba Client:Linux 
Step1. List the share directory

smbclient -L SambaServerIP
  • 1
  • 1

Step2. Login the samba server’s share directory 
1.Anonymous user login

smbclient //sambaServerIP/shareDirectoryName
            #get --> download the file into local from samba server.
            #put --> upload the file into samba server from local
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

2.Samba user authentication login

smbclient //sambaServerIP/shareDirectoryName -u sambaUserName
mount -o userName=jsamba,passwd fanguiju //sambaServerIP/shareDirectory /mnt
  • 1
  • 2
  • 1
  • 2

Access the windows OS samba shareDirectory from Linux

**Samba Server**Windows 
Samba Client:Linux 
Step1.

smbclient -L sambaServerIP -u administrator   #login sambaServer(win) by adminstrator identity
smbclient -u administrator //sambaServerIP
  • 1
  • 2
  • 1
  • 2

step2. Mount share dirctory into local

mount -o userName=administrator //sambaServerIP(wim)/d$ /mnt/winShare
  • 1
  • 1

vim /etc/fstab #realize permanent mount

Attention:在同一个可以互通的网络中,只要有一台SambaSrever,那受到此SambaServer影响的LinuxOS和windowsOS都可以实现与sambaServer之间实现文件共享。

Access the samba shareDirectory of LinuxOS by winOS

**Server:**Linux 
**Client:**Windows

Ctrl+R(run) //LinuxSambaServerIP #And then enter the user authentication 
CMD.exe command below:

net use * /del /y   #clear the user login cache


转载:http://blog.csdn.net/jmilk/article/details/50384975

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值