Samba 是 SMB/CIFS 网络协议的重新实现, 它作为 NFS 的补充使得在 Linux、OS/2、DOS 和 Windows 系统中进行文件共享、打印机共享更容易实现。SMB协议是客户机/服务器型协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。通过设置“NetBIOS over TCP/IP”使得Samba不但能与局域网络主机分享资源,还能与全世界的电脑分享资源。

这里通过使用docker镜像的方式来简化samba的安装, 来实现不同系统之间共享目录。


sudo docker run -it -p 139:139 -p 445:445 -d dperson/samba


sudo docker run -it --name samba -p 139:139 -p 445:445 \
            -v /path/to/directory:/mount \
            -d dperson/samba


docker run -it --rm dperson/samba -h
Usage: [-opt] [command]
Options (fields in '[]' are optional, '<>' are required):
    -h          This help
    -c "<from:to>" setup character mapping for file/directory names
                required arg: "<from:to>" character mappings separated by ','
    -g "<parameter>" Provide global option for smb.conf
                    required arg: "<parameter>" - IE: -g "log level = 2"
    -i "<path>" Import smbpassword
                required arg: "<path>" - full file path in container
    -n          Start the 'nmbd' daemon to advertise the shares
    -p          Set ownership and permissions on the shares
    -r          Disable recycle bin for shares
    -S          Disable SMB2 minimum version
    -s "<name;/path>[;browse;readonly;guest;users;admins;writelist;comment]"
                Configure a share
                required arg: "<name>;</path>"
                <name> is how it's called for clients
                <path> path to share
                NOTE: for the default value, just leave blank
                [browsable] default:'yes' or 'no'
                [readonly] default:'yes' or 'no'
                [guest] allowed default:'yes' or 'no'
                [users] allowed default:'all' or list of allowed users
                [admins] allowed default:'none' or list of admin users
                [writelist] list of users that can write to a RO share
                [comment] description of share
    -u "<username;password>[;ID;group]"       Add a user
                required arg: "<username>;<passwd>"
                <username> for user
                <password> for user
                [ID] for user
                [group] for user
    -w "<workgroup>"       Configure the workgroup (domain) samba should use
                required arg: "<workgroup>"
                <workgroup> for samba
    -W          Allow access wide symbolic links
    -I          Add an include option at the end of the smb.conf
                required arg: "<include file path>"
                <include file path> in the container, e.g. a bind mount

The 'command' (if provided and valid) will be run instead of samba


现在要将目录xw_share, 通过139和445端口进行共享, 并创建用户xw(密码为:overkill),禁用匿名用户访问,并且允许用户xw读写操作,可以如下设置:

docker run -it --name samba -p 139:139 -p 445:445 \
    -v $PWD/nl_share:/mount -d dperson/samba -u "xw;overkill" -s "xw;/mount/;yes;no;no;all;xw;xw"


  1. Samba (简体中文)
  2. samba百度百科
  4. xwxwgo
posted @ 2019-03-08 16:34 墨梅 阅读(...) 评论(...) 编辑 收藏