一、安装samba服务
[root@docker ~]# yum install samba -y
二、修改 smb.conf
1、匿名用户登陆
[root@docker ~]# vim /etc/samba/smb.conf
1、在配置文件中找到security = user 修改成 security = share
2、在文件末尾追加如下配置:
[name]
comment = share directory
path = /redhat
public = yes
writable = yes
browseable = yes #browseable = no 时,在客户端是不能查看这共享名
printable = no
重启 samba
[root@docker ~]# service smb restart
关闭 SMB 服务: [失败]
启动 SMB 服务: [确定]
创建共享目录
[root@docker ~]# mkdir /redhat
[root@docker ~]# chmod 777 /redhat
[root@docker ~]# cd /redhat
[root@docker ~]# echo "hello world" > test
客户端查看共享目录
root@ubuntu:~# smbclient -L 172.24.0.4
WARNING: The security=share option is deprecated
Enter root's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]
Sharename Type Comment
--------- ---- -------
name Disk share directory
IPC$ IPC IPC Service (Samba Server Version 3.6.23-20.el6)
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]
Server Comment
--------- -------
Workgroup Master
--------- -------
#注意:security=share,且public=yes,所有用户都可以查看,查看时是不需要密码,直接确认
客户端登陆共享目录
root@ubuntu:~# smbclient //172.24.0.4/name
Enter root's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]
Server not using user level security and no password supplied.
smb: \> ls
. D 0 Sun Sep 20 12:00:46 2015
.. DR 0 Sun Sep 20 11:55:07 2015
test N 12 Sun Sep 20 12:00:46 2015
49086 blocks of size 1048576. 42088 blocks available
#注意:
1、security=share,且public=yes,所有用户都可以查看,登陆时是不需要密码,直接确认
2、若是redhat系统,涉及到selinux问题,还需:chcon -R -t samba_share_t /redhat
查看客户端访问信息
[root@docker ~]# smbstatus
Samba version 3.6.23-20.el6
PID Username Group Machine
-------------------------------------------------------------------
Service pid machine Connected at
-------------------------------------------------------
name 38000 172.24.0.3 Sun Sep 20 12:20:20 2015
No locked files
排错:如果在共享的文件夹不能创建文件,按如下步骤排错
1、配置文件里是否开启写权限;2、新创建的文件/redhat这个文件是否有写权限;3、selinux
2、用户密码登陆
[root@docker ~]# vim /etc/samba/smb.conf
1、在配置文件中找到security = share 修改成 security = user
2、在文件末尾追加如下配置:
[name]
comment = share directory
path = /redhat
public = no
writable = no
printable = no
hosts allow = 172.24.
write list = git
valid users = git
#注意:write list = git 允许写入权限的用户列表(只有和writeable = no 时才生效)
[root@docker ~]# service smb restart
关闭 SMB 服务: [失败]
启动 SMB 服务: [确定]
若配置用户登录时,
1、用户必须是系统用户,useradd git;echo git | passwd --stdin git
2、设置samba登录用户和密码 smbpasswd -a 用户名
[root@docker ~]# smbpasswd -a git
New SMB password:
Retype new SMB password:
Failed to add entry for user git.
客户端查看共享目录
root@ubuntu:~# smbclient -L //172.24.0.4/name -U git%git
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]
Sharename Type Comment
--------- ---- -------
name Disk share directory
IPC$ IPC IPC Service (Samba Server Version 3.6.23-20.el6)
git Disk Home Directories
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]
Server Comment
--------- -------
Workgroup Master
--------- -------
客户端登陆共享目录
root@ubuntu:~# smbclient //172.24.0.4/name -U git%git
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]
smb: \> ls
. D 0 Sun Sep 20 12:00:46 2015
.. DR 0 Sun Sep 20 11:55:07 2015
test N 12 Sun Sep 20 12:00:46 2015
49086 blocks of size 1048576. 42087 blocks available
smb: \>
把共享目录挂载到本地
root@ubuntu:~# mount -t cifs //172.24.0.4/name /mnt -o user=git,password=git
root@ubuntu:~# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 98G 4.2G 89G 5% /
none tmpfs 4.0K 0 4.0K 0% /sys/fs/cgroup
udev devtmpfs 483M 4.0K 483M 1% /dev
tmpfs tmpfs 99M 1.5M 98M 2% /run
//172.24.0.4/name cifs 48G 4.4G 42G 10% /mnt
在/etc/fstab上追加
//172.24.0.4/name /mnt cifs user=git,password=git 0 0
3、虚拟用户登陆
workgroup = MYGROUP
server string = Samba Server Version %v
在smb.conf文件中找到如上两列,在其下方添加如下一行:
username map = /etc/samba/smbusers
[root@docker ~]# vim /etc/samba/smbusers #追加如下行
git = vgit
[root@docker ~]# service smb restart
关闭 SMB 服务: [失败]
启动 SMB 服务: [确定]
客户端虚拟用户登陆
root@ubuntu:~# smbclient //172.24.0.4/name -U vgit%git
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.6.23-20.el6]
smb: \> ls
. D 0 Sun Sep 20 12:00:46 2015
.. DR 0 Sun Sep 20 11:55:07 2015
test N 12 Sun Sep 20 12:00:46 2015
49086 blocks of size 1048576. 42086 blocks available
smb: \>