Samba文件共享服务的实现(2)

[root@hejie ~]# mkdir /opt/zhengran
[root@hejie ~]# chown -R zhengran.zhengran /opt/zhengran/
[root@hejie ~]# ll /opt/
total 0
drwxr-xr-x. 2 zhengran zhengran 6 Aug 7 17:22 zhengran

7.配置共享

[root@hejie ~]# cat >> /etc/samba/smb.conf <<EOF
> [zhengran]    //共享名
> comment = zhengranwoaini    //注释信息
> path = /opt/zhengran                //共享目录路径
> browseable = yes                    //指定该共享是否可以浏览
> guest ok = yes                        //指定该共享是否允许guset账户访问
> writable = yes                          //指定目录是否可写
> write list = share          //允许写入该共享的用户,组要用@表示,例如:
                                                write list = root,@root     
> public = yes                          //是否允许匿名访问
> EOF

8.用testparm检查配置文件是否有语法错误,可显示最终生效的配置

[root@hejie ~]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Processing section "[zhengran]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
 workgroup = SAMBA
 printcap name = cups
 security = USER
 username map = /etc/samba/smbusers
 idmap config * : backend = tdb
 cups options = raw

[homes]
 comment = Home Directories
 browseable = No
 inherit acls = Yes
 read only = No
 valid users = %S %D%w%S

[printers]
 comment = All Printers
 path = /var/tmp
 browseable = No
 printable = Yes
 create mask = 0600

[print$]
 comment = Printer Drivers
 path = /var/lib/samba/drivers
 create mask = 0664
 directory mask = 0775
 write list = root

[zhengran]
 comment = zhengranwoaini
 path = /opt/zhengran
 guest ok = Yes
 read only = No
 write list = share

9.重启smb服务

[root@hejie ~]# systemctl restart smb

客户端上操作:
1.安装工具包

[root@hyj ~]#  yum install samba-client cifs-utils -y

在客户机查看samba服务端有哪些共享资源

[root@hyj ~]# smbclient -L 192.168.56.11 -U share
    Enter SAMBA\share's password:
    Sharename Type Comment
    --------- ---- -------
    print$ Disk Printer Drivers
    zhengran Disk zhengranwoaini
    IPC$ IPC IPC Service (Samba 4.6.2)
    Reconnecting with SMB1 for workgroup listing.
    Server Comment
    --------- -------
    Workgroup Master
    --------- -------

3.创建目录,并将samba服务器的共享资源zhengran挂载到客户机本地

[root@hyj ~]# mkdir /opt/ran
[root@hyj ~]# mount -t cifs //192.168.56.11/zhengran /opt/ran -o username=share,password=123
[root@hyj ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/CentOS-root 17G 1016M 16G 6% /
devtmpfs 982M 0 982M 0% /dev
tmpfs 993M 0 993M 0% /dev/shm
tmpfs 993M 8.5M 984M 1% /run
tmpfs 993M 0 993M 0% /sys/fs/cgroup
/dev/sda1 1014M 125M 890M 13% /boot
tmpfs 199M 0 199M 0% /run/user/0
//192.168.56.11/zhengran 47G 5.4G 42G 12% /opt/ran

4.在客户机挂载点创建新文件

[root@hyj ~]# cd /opt/ran/
[root@hyj ran]# touch 1 2 3
[root@hyj ran]# ls
1 2 3

5.在服务器上验证

[root@hejie ~]# cd /opt/zhengran/
[root@hejie zhengran]# ls
1 2 3

配置匿名共享
服务端
1.修改配置文件

[root@hejie ~]# vim /etc/samba/smb.conf
[global]
        workgroup = SAMBA
        security = user
        map to guest = Bad User  //添加此行

2.创建共享目录

[root@hejie ~]# mkdir /opt/ranran
[root@hejie ~]# chmod 777 /opt/ranran/
[root@hejie ~]# ll /opt/ranran/ -d
drwxrwxrwx. 2 root root 6 Aug 7 19:24 /opt/ranran/

3.配置共享

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/1badf7097248f7c29ae5f370e22028b9.html