1. 安装samba
sudo yum install samba samba-client -y
2. 创建用户和权限
sudo adduser samba
mkdir /var/mirror
sudo chmod 777 /var/mirror
3. samba添加用户
sudo smbpasswd -a samba
按照提示输入秘密
New SMB password:
Retype new SMB password:
4. smb配置
sudo vim /etc/samba/smb.conf
[global]
workgroup = YOURGROUP
security = user
passdb backend = smbpasswd
printing = cups
printcap name = cups
load printers = yes
cups options = raw
[share]
comment = Smbhome
path = /var/mirror
read only = No
writeable = yes
public = yes
browsable = yes
全局配置:
- workgroup = YOURGROUP 你的工作组
- security = user 安全级别,user时访问需要输入用户名和密码
- passdb backend = smbpasswd 使用密码
- 其他默认
其他打印机配置和home共享没用,直接注释掉。
共享配置:
- path 是共享的目录
- read only 只读设置false
- writeable = yes 允许写如
- browsable = yes 可以浏览
- comment 注释
- share 远程访问的路径
可以使用工具校验配置是否正确
$ testparm -t /etc/samba/smb.conf
Load smb config files from /etc/samba/smb.conf
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
[global]
passdb backend = smbpasswd
printcap name = cups
security = USER
workgroup = TENCENT
idmap config * : backend = tdb
cups options = raw
[share]
comment = Smbhome
guest ok = Yes
path = /var/mirror
read only = No
5. 防火墙
linux默认开启防火墙并且不允许smb访问,需要开启
sudo setenforce 0
sudo firewall-cmd --permanent --add-service=samba
sudo firewall-cmd --reload
6.启动samba
sudo service smb start
sudo service smb status
sudo systemctl enable smb
output
Redirecting to /bin/systemctl status smb.service
● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2021-12-09 21:46:48 HKT; 7min ago
Docs: man:smbd(8)
man:samba(7)
man:smb.conf(5)
Main PID: 17114 (smbd)
Status: "smbd: ready to serve connections..."
Tasks: 5
Memory: 5.0M
CGroup: /system.slice/smb.service
├─17114 /usr/sbin/smbd --foreground --no-process-group
├─17116 /usr/sbin/smbd --foreground --no-process-group
├─17117 /usr/sbin/smbd --foreground --no-process-group
├─17119 /usr/sbin/smbd --foreground --no-process-group
└─17132 /usr/sbin/smbd --foreground --no-process-group
Dec 09 21:46:47 192.168.1.5 systemd[1]: Starting Samba SMB Daemon...
Dec 09 21:46:48 192.168.1.5 smbd[17114]: [2021/12/09 21:46:48.072968, 0] ../../lib/util/become_daemon.c...ady)
Dec 09 21:46:48 192.168.1.5 smbd[17114]: daemon_ready: daemon 'smbd' finished starting up and ready to...ions
Dec 09 21:46:48 192.168.1.5 systemd[1]: Started Samba SMB Daemon.
Hint: Some lines were ellipsized, use -l to show in full.
7. 本地测试
$ sudo smbclient //localhost/share -U samba
Enter TENCENT\samba's password:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Thu Dec 9 22:11:04 2021
.. D 0 Thu Dec 9 22:07:04 2021
测试成功,如果报错 smb: > ls NT_STATUS_ACCESS_DENIED listing * 则目录没有是访问权限,增加权限
8. windows7访问
CentOS7执行ifconfig 查看网卡的本地IP : 192.168.1.8 随便打开一个目录,然后在最上层的地址栏里输入:\\192.168.1.8\share ,等待片刻会弹出对话框让输入用户和密码,然后就打开了共享目录。 如果提示无访问权限,修改Centos共享目录权限即可。
9. 一定要在同一个WIFI下!!!
|