CentOS 7下Samba服务安装与配置详解(4)

创建文件夹

# 创建文件夹 [root@Linuxidc-Server storage]# cd /storage [root@Linuxidc-Server storage]# mkdir logger shared [root@Linuxidc-Server storage]# ls total 0 drwxr-xr-x. 2 root root 6 Aug 3 10:12 logger drwxr-xr-x. 2 root root 6 Aug 3 10:12 shared

创建用户

# 创建用户 [root@Linuxidc-Server storage]# useradd -s /sbin/nologin logadmin [root@Linuxidc-Server storage]# useradd -s /sbin/nologin admin [root@Linuxidc-Server storage]# useradd -g admin -s /sbin/nologin shared [root@Linuxidc-Server storage]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt nobody:x:99:99:Nobody:/:/sbin/nologin systemd-bus-proxy:x:999:998:systemd Bus Proxy:/:/sbin/nologin systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:998:997:User for polkitd:/:/sbin/nologin tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin logadmin:x:1000:1000::/home/logadmin:/sbin/nologin loguser:x:1001:1000::/home/loguser:/sbin/nologin admin:x:1002:1002::/home/admin:/sbin/nologin shared:x:1003:1002::/home/shared:/sbin/nologin [root@Linuxidc-Server storage]#

建立Samba用户

[root@Linuxidc-Server storage]# smbpasswd -a logadmin New SMB password: Retype new SMB password: Added user logadmin. [root@Linuxidc-Server storage]# smbpasswd -a loguser New SMB password: Retype new SMB password: Added user loguser. [root@Linuxidc-Server storage]# smbpasswd -a admin New SMB password: Retype new SMB password: Added user admin. [root@Linuxidc-Server storage]# smbpasswd -a shared New SMB password: Retype new SMB password: Added user shared.

更改目录属性

[root@Linuxidc-Server storage]# chown logadmin.logadmin logger [root@Linuxidc-Server storage]# chown admin.admin shared [root@Linuxidc-Server storage]# chmod -R 777 logger [root@Linuxidc-Server storage]# chmod -R 777 shared [root@Linuxidc-Server storage]#

配置Samba服务

[root@Linuxidc-Server storage]# vi /etc/samba/smb.conf [global] workgroup = SC.LOCAL server string = Samba Server Version %v netbios name = Linuxidc-Server log file = /var/log/samba/%m.log max log size = 10240 security = user passdb backend = tdbsam [logger] comment = Logs Directories path = /storage/logger/ public = no admin users = logadmin valid users = @logadmin browseable = yes writable = yes create mask = 0777 directory mask = 0777 force directory mode = 0777 force create mode = 0777 [shared] # 共享文件目录描述 comment = Shared Directories # 共享文件目录 path = /storage/shared/ # 是否允许guest访问 public = no # 指定管理用户 admin users = admin # 可访问的用户组、用户 valid users = @admin # 是否浏览权限 browseable = yes # 是否可写权限 writable = yes # 文件权限设置 create mask = 0777 directory mask = 0777 force directory mode = 0777 force create mode = 0777

修改完Samba配置文件后,需要重启Samba服务配置才能生效。

测试Samba服务

访问Samba服务

使用Windows客户机通过UNC路径访问Samba服务, 如: \\192.168.6.186, 此时会提示输入用户名和密码(在第2步中创建的用户和密码,如logadmin等)。

UNC路径访问


UNC路径访问

输入用户名和密码


输入用户名和密码

共享文件夹


共享文件夹

测试创建文件

拷贝客户机文件到Samba共享文件夹下, 测试文件拷贝是否成功。

将文件book.txt拷贝到Samba共享文件夹logger下, 查看文件是否成功拷贝。

成功拷贝文件


成功拷贝文件

3. 错误处理

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

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