图片 4

文件共享实践,下安装Samba文件共享服务器

1. 安装

安装前先关闭iptables和SELinux。

CentOS输入以下命令:

yum install samba samba-client

Ubuntu输入以下命令:

apt-get install samba
apt-get install samba-client

Samba文件共享服务可以让Linux和Linux系统、Linux和Windows系统之间共享文件

图片 1

2. 设置

创建一个文件夹:

mkdir /home/samba
chmod 777 /home/samba

编辑/etc/samba/smb.conf文件:

# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options (perhaps too
# many!) most of which are not shown in this example
#
# For a step to step guide on installing, configuring and using samba, 
# read the Samba-HOWTO-Collection. This may be obtained from:
#  http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
#
# Many working examples of smb.conf files can be found in the 
# Samba-Guide which is generated daily and can be downloaded from: 
#  http://www.samba.org/samba/docs/Samba-Guide.pdf
#
# Any line which starts with a ; (semi-colon) or a # (hash) 
# is a comment and is ignored. In this example we will use a #
# for commentry and a ; for parts of the config file that you
# may wish to enable
#
# NOTE: Whenever you modify this file you should run the command "testparm"
# to check that you have not made any basic syntactic errors. 
#
#---------------
# SELINUX NOTES:
#
# If you want to use the useradd/groupadd family of binaries please run:
# setsebool -P samba_domain_controller on
#
# If you want to share home directories via samba please run:
# setsebool -P samba_enable_home_dirs on
#
# If you create a new directory you want to share you should mark it as
# "samba_share_t" so that selinux will let you write into it.
# Make sure not to do that on system directories as they may already have
# been marked with othe SELinux labels.
#
# Use ls -ldZ /path to see which context a directory has
#
# Set labels only on directories you created!
# To set a label use the following: chcon -t samba_share_t /path
#
# If you need to share a system created directory you can use one of the
# following (read-only/read-write):
# setsebool -P samba_export_all_ro on
# or
# setsebool -P samba_export_all_rw on
#
# If you want to run scripts (preexec/root prexec/print command/...) please
# put them into the /var/lib/samba/scripts directory so that smbd will be
# allowed to run them.
# Make sure you COPY them and not MOVE them so that the right SELinux context
# is applied, to check all is ok use restorecon -R -v /var/lib/samba/scripts
#
#--------------
#
#======================= Global Settings =====================================

[global]

# ----------------------- Network Related Options -------------------------
#
# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
#
# server string is the equivalent of the NT Description field
#
# netbios name can be used to specify a server name not tied to the hostname
#
# Interfaces lets you configure Samba to use multiple interfaces
# If you have multiple network interfaces then you can list the ones
# you want to listen on (never omit localhost)
#
# Hosts Allow/Hosts Deny lets you restrict who can connect, and you can
# specifiy it as a per share option as well
#
    workgroup = MYGROUP
    server string = Samba Server Version %v

    netbios name = HZHISERVER
    map to guest = bad user

;    interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24 
;    hosts allow = 127. 192.168.12. 192.168.13. 192.168.1

# --------------------------- Logging Options -----------------------------
#
# Log File let you specify where to put logs and how to split them up.
#
# Max Log Size let you specify the max size log files should reach

    # logs split per machine
    log file = /var/log/samba/log.%m
    # max 50KB per log file, then rotate
    max log size = 50

# ----------------------- Standalone Server Options ------------------------
#
# Scurity can be set to user, share(deprecated) or server(deprecated)
#
# Backend to store user information in. New installations should 
# use either tdbsam or ldapsam. smbpasswd is available for backwards 
# compatibility. tdbsam requires no further configuration.

    security = user
    passdb backend = tdbsam


# ----------------------- Domain Members Options ------------------------
#
# Security must be set to domain or ads
#
# Use the realm option only with security = ads
# Specifies the Active Directory realm the host is part of
#
# Backend to store user information in. New installations should 
# use either tdbsam or ldapsam. smbpasswd is available for backwards 
# compatibility. tdbsam requires no further configuration.
#
# Use password server option only with security = server or if you can't
# use the DNS to locate Domain Controllers
# The argument list may include:
#   password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name]
# or to auto-locate the domain controller/s
#   password server = *


;    security = domain
;    passdb backend = tdbsam
;    realm = MY_REALM

;    password server = <NT-Server-Name>

# ----------------------- Domain Controller Options ------------------------
#
# Security must be set to user for domain controllers
#
# Backend to store user information in. New installations should 
# use either tdbsam or ldapsam. smbpasswd is available for backwards 
# compatibility. tdbsam requires no further configuration.
#
# Domain Master specifies Samba to be the Domain Master Browser. This
# allows Samba to collate browse lists between subnets. Don't use this
# if you already have a Windows NT domain controller doing this job
#
# Domain Logons let Samba be a domain logon server for Windows workstations. 
#
# Logon Scrpit let yuou specify a script to be run at login time on the client
# You need to provide it in a share called NETLOGON
#
# Logon Path let you specify where user profiles are stored (UNC path)
#
# Various scripts can be used on a domain controller or stand-alone
# machine to add or delete corresponding unix accounts
#
;    security = user
;    passdb backend = tdbsam

;    domain master = yes 
;    domain logons = yes

    # the login script name depends on the machine name
;    logon script = %m.bat
    # the login script name depends on the unix user used
;    logon script = %u.bat
;    logon path = \\%L\Profiles\%u
    # disables profiles support by specifing an empty path
;    logon path =          

;    add user script = /usr/sbin/useradd "%u" -n -g users
;    add group script = /usr/sbin/groupadd "%g"
;    add machine script = /usr/sbin/useradd -n -c "Workstation (%u)" -M -d /nohome -s /bin/false "%u"
;    delete user script = /usr/sbin/userdel "%u"
;    delete user from group script = /usr/sbin/userdel "%u" "%g"
;    delete group script = /usr/sbin/groupdel "%g"


# ----------------------- Browser Control Options ----------------------------
#
# set local master to no if you don't want Samba to become a master
# browser on your network. Otherwise the normal election rules apply
#
# OS Level determines the precedence of this server in master browser
# elections. The default value should be reasonable
#
# Preferred Master causes Samba to force a local browser election on startup
# and gives it a slightly higher chance of winning the election
;    local master = no
;    os level = 33
;    preferred master = yes

#----------------------------- Name Resolution -------------------------------
# Windows Internet Name Serving Support Section:
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
#
# - WINS Support: Tells the NMBD component of Samba to enable it's WINS Server
#
# - WINS Server: Tells the NMBD components of Samba to be a WINS Client
#
# - WINS Proxy: Tells Samba to answer name resolution queries on
#   behalf of a non WINS capable client, for this to work there must be
#   at least one    WINS Server on the network. The default is NO.
#
# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups.

;    wins support = yes
;    wins server = w.x.y.z
;    wins proxy = yes

;    dns proxy = yes

# --------------------------- Printing Options -----------------------------
#
# Load Printers let you load automatically the list of printers rather
# than setting them up individually
#
# Cups Options let you pass the cups libs custom options, setting it to raw
# for example will let you use drivers on your Windows clients
#
# Printcap Name let you specify an alternative printcap file
#
# You can choose a non default printing system using the Printing option

    load printers = yes
    cups options = raw

;    printcap name = /etc/printcap
    #obtain list of printers automatically on SystemV
;    printcap name = lpstat
;    printing = cups

# --------------------------- Filesystem Options ---------------------------
#
# The following options can be uncommented if the filesystem supports
# Extended Attributes and they are enabled (usually by the mount option
# user_xattr). Thess options will let the admin store the DOS attributes
# in an EA and make samba not mess with the permission bits.
#
# Note: these options can also be set just per share, setting them in global
# makes them the default for all shares

;    map archive = no
;    map hidden = no
;    map read only = no
;    map system = no
;    store dos attributes = yes


#============================ Share Definitions ==============================

[homes]
    comment = Home Directories
    browseable = yes
    writable = yes
;    valid users = %S
;    valid users = MYDOMAIN\%S

[printers]
    comment = All Printers
    path = /var/spool/samba
    browseable = no
    guest ok = no
    writable = no
    printable = yes

# Un-comment the following and create the netlogon directory for Domain Logons
;    [netlogon]
;    comment = Network Logon Service
;    path = /var/lib/samba/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 = /var/lib/samba/profiles
;    browseable = no
;    guest ok = yes


# A publicly accessible directory, but read only, except for people in
# the "staff" group
    [public]
    comment = Public Stuff
    path = /home/samba
    public = yes
    browseable = yes
    writable = yes
    printable = no
    write list = +staff

服务查询 默认情况下,Linux系统在默认安装中已经安装了Samba服务包的一部分,为了对整个过程有一个完整的了解,在此先将这部分卸载掉。使用命令
rpm -qa | grep samba,默认情况下可以查询到两个已经存在的包:
samba-client-xxx-xxx
samba-common-xxx.xxx

 

3. 运行

CentOS下运行:

service smb start
service nmb start

Ubuntu下运行:

/etc/init.d/samba start

卸载Samba
用rpm -e
将两个包卸载掉。对于samba-common-xxx.xxx,因为与其它rpm包之间存在依赖关系,所以必须加参数-f和–nodeps,-f是指强制,–nodeps是指不检查依赖关系,具体完整命令为:
rpm -e samba-common-xxx -f –nodeps
rpm -e samba-client-xxx -f –nodeps

前言

一直以来都以为FTP和NFS是局域网文件共享的常用方式,但是在最近接触Samba之后,了解到一些用户需要简化访问学习成本,满足基础的权限控制管理,并支持实时编辑和保存文件,我才明白这些需求使用之前的方法都是很难满足的,而Samba却可以完美的支持上述需求,虽然在开始接触时花了一些时间学习,但把配置和语法梳理清楚之后就很简单了。

Unix与Windows文件共享的最佳方式之一

 

4. Windows7访问Samba

因为Samba使用NTLM认证,而Windows7使用的是NTLMv2认证,所以要先设置一下才能访问。

开始->运行->secpol.msc,这时会出错,提示“试图引用不存在的令牌。”,到C:\Windows\System32下找到secpol.msc,复制到桌面上再运行,选择本地策略->安全选项->网络安全:LAN管理器身份验证级别,改成“发送
LM 和 NTLMv2 ,如果已协商,则使用NTLMv2 会话安全”。

图片 2

图片 3

点击开始,在搜索对话框中输入“//Samba服务器IP”,就可以访问Samba服务器了,并且复制粘贴文件了,非常方便。

图片 4

————————————分割线————————————

如何在Ubuntu 14.04中使用Samba共享文件 
http://www.linuxidc.com/Linux/2014-07/104894.htm

VMWare 虚拟机 Ubuntu 双网卡 访问 samba 速度 翻倍
http://www.linuxidc.com/Linux/2013-06/85445.htm

Ubuntu 15.04安装Samba服务
http://www.linuxidc.com/Linux/2016-03/129201.htm

samba安装使用图解 
http://www.linuxidc.com/Linux/2017-03/141254.htm

CentOS 7.2 安装配置Samba服务器
http://www.linuxidc.com/Linux/2017-03/141390.htm

CentOS部署Samba企业文件共享服务
http://www.linuxidc.com/Linux/2016-06/132609.htm

怎样设置Samba文件服务器以使用Windows客户端 
http://www.linuxidc.com/Linux/2014-08/105786.htm

CentOS 6.7下 Samba服务器的搭建与配置(share共享模式) 
http://www.linuxidc.com/Linux/2016-12/138220.htm

Ubuntu 16.04下Samba相关配置 
http://www.linuxidc.com/Linux/2016-12/138498.htm

————————————分割线————————————

Samba
的详细介绍
:请点这里
Samba
的下载地址
:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141523.htm

图片 5

挂在镜像文件

安装samba

各个平台的安装都蛮简单的,略过

 

因为安装samba你需要下载对应的安装包,一般系统盘就有这些软件,所以可以直接挂载上去

配置samba

建议合理规划目录和用户权限,可以利用用户组来简化授权管理,参见扩展阅读

创建目录(举例)

  1. mkdir -p /data2/sm
  2. chmod -R 777/data2/sm

添加用户(举例)

  1. groupadd dengling
  2. useradd -g dengling -s /sbin/nologin dengling
  3. smbpasswd -a dengling

备份smb配置文件并编辑

  1. cd /etc/samba
  2. cp smb.conf smb.conf.bakvi smb.conf

  1. #全局参数
  2. [global]
  3. security = share
  4. lanman auth =Yes
  5. log file =/var/log/samba/log.%m
  6. idmap config *: backend = tdb
  7. guest ok =Yes
  8. hosts allow =127.,172.,192.168.1.,192.168.3.
  9. cups options = raw
  10. #共享参数
  11. #常用选项
  12. #[shared_name]
  13. # path = # 文件系统路径
  14. # browseable = {yes|no} # 是否可以被查看到
  15. # public = {yes|no} # 是否可被所有人读
  16. # guest ok = {yes|no} # 与 public 相同
  17. # read only = yes # 是否只读
  18. # writeable = yes # 是否可写
  19. # write list = user1, user2 # 可写用户列表
  20. # @group, +group # 可写组列表
  21. # valid users = # 白名单
  22. # invalid users = # 黑名单
  23. [homes]
  24. comment =HomeDirectories
  25. read only =No
  26. browseable =No
  27. [sheji]
  28. comment = sheji
  29. path =/data2/sm/sheji
  30. valid users = share, shenwei, xuwei, shenjiamei, humengchu, rensiqiang, yeting, tongying, jinbo, zengfanan, fengpeisi
  31. read only =No
  32. create mask =0775
  33. directory mask =0775

 

mount -o loop /home/rhel-server-6.2-x86_64-dvd.iso /media/OS

启动samba

检查语法

  1. testparm

重启smb服务查看状态

  1. service smb restart
  2. smbstatus

 

这样就将系统盘挂载到指定的OS目录了,在OS目录下的Packages下有很多安装包可以使用。

Windows客户端访问

1.Windows上访问samba

在“计算机”中输入:\\xxx.xxx.xxx.xxx\

2.Windows断开samba共享连接,实在不行可以选择注销或者重启

在【开始】→【运行】→【CMD】回车中输入:net use * /del /y

3.将samba共享的Linux目录映射成Windows的一个驱动器盘符

在【右键计算机】→【映射网络驱动器】→【文件夹\XX.XX.XX.XX\】

————————————分割线————————————

如何在Ubuntu
14.04中使用Samba共享文件 
http://www.linuxidc.com/Linux/2014-07/104894.htm

VMWare 虚拟机 Ubuntu 双网卡 访问 samba 速度 翻倍
http://www.linuxidc.com/Linux/2013-06/85445.htm

Samba文件共享服务器加入Windows Server 2003域
http://www.linuxidc.com/Linux/2013-06/86391.htm

Samba安装配置
http://www.linuxidc.com/Linux/2013-06/86101.htm

CentOS 6.2 下Samba
服务的配置
http://www.linuxidc.com/Linux/2013-01/78390.htm

Samba服务器安装和配置 
http://www.linuxidc.com/Linux/2014-12/110459.htm

Win7+VMware+Fedora18
Samba服务器的搭建图解
http://www.linuxidc.com/Linux/2013-01/78234.htm

————————————分割线————————————

Samba
的详细介绍
:请点这里
Samba
的下载地址
:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-07/119845.htm

图片 6

安装Samba
用以下命令安装:
rpm -ivh samba-xxx.rpm -f –nodeps
rpm -ivh samba-client-xxx.rpm  -f –nodeps
rpm -ivh samba-common-xxx.rpm -f –nodeps
安装完成后,使用命令rpm -qa | grep
samba进行查询,发现搭建samba服务器所依赖的所有服务器都已经安装好了即可。

安装完成后配置/etc/samba/smb.conf配置文件,你可以备份原来的配置,把下面的配置覆盖当前配置即可:

[global]

    workgroup=takecar

    netbios name=Linux-108.12

    server string=Linux Samba Server TestServer

    #security=share

    security=user

    map to guest=Bad User

[takecar]

    path=/opt/takecar

    writable=yes

    browseable=yes 

    guest ok=yes

以上就是配置匿名用户共享目录/opt/takecar

其中writable是写入权限、browseable是浏览权限、guest是贵宾用户

建立相应目录并授权
[root@localhost ~]# mkdir -p /opt/linuxsir
[root@localhost ~]# id nobody
uid=99(nobody) gid=99(nobody) groups=99(nobody)
[root@localhost ~]# chown -R nobody:nobody /opt/linuxsir
注释:关于授权nobody,我们先用id命令查看了nobody用户的信息,发现他的用户组也是nobody,我们要以这个为准。有些系统nobody用户组并非是nobody

发表评论

电子邮件地址不会被公开。 必填项已用*标注