主要参考了这个https://www.right.com.cn/forum/thread-363866-1-1.html,感谢作者
第一步:opkg install samba4-server samba4-admin samba4-libs samba4-utils
第二步:修改配置文件vi /opt/etc/samba/smb.conf
[global]
netbios name=Entware-SMB4
server string = Samba on Entware
workgroup = WORKGROUP
guest account = nobody
security = user
map to guest = Bad User
unix charset=UTF=8
dos charset=ASCII
preserve case = yes
short preserve case = yes
log level = 0
timestamp logs=yes
passdb backend = smbpasswd
smb encrypt = disabled
smb passwd file = /opt/etc/samba/smbpasswd
load printers = no
printcap name = /dev/null
[math]
path=/math
valid users=root
write list=root
public =yes
read only =no
guest ok =yes
guest only=no
writable =yes
通过testparm后给出的smb.conf的内容如下:
[global]
dos charset = ASCII
load printers = No
map to guest = Bad User
netbios name = ENTWARE-SMB4
passdb backend = smbpasswd
printcap name = /dev/null
security = USER
server string = Samba on Entware
unix charset = UTF=8
idmap config * : backend = tdb
[math]
guest ok = Yes
path = /math
read only = No
valid users = root
write list = root
---------------加粗样式---------------------------
下面math这一节是我自己的内容,前面内容没有改动。
通过testparm命令可以查看配置文件情况。
文件夹权限问题`
S91smb启动时将新建一些文件夹和文件,该文件内容:
mkdir -p /opt/var/log/samba
mkdir -p /opt/var/lib/samba/private
mkdir -p /opt/var/cache/samba
mkdir -p /opt/var/run/samba/ncalrpc
很多时候因为权限的问题导致启动失败(testparm和smbd得知,有些文件夹权限要0700,有些要有写权限0755,),总结可以将下面设置成0755。如果有错应通过日志文件 来确定哪里文件夹应是0700
chmod -R 0755 /opt/var/log
chmod -R 0755 /opt/var/lib
chmod -R 0755 /opt/var/cache
第三步,添加samba用户,samba用户必须是系统用户,
smbpasswd -a root,然后两次输入密码(你想用的密码)虽然提示用户已经添加,但是
出现错误代码:
startsmbfilepwent_internal: file /opt/etc/samba/smbpasswd did not exist. File successfully created.
directory_create_or_exist: mkdir failed on directory /opt/var/lib/samba: No such file or directory
Failed to initialise tdb mapping backend
failed to initialize group mapping
directory_create_or_exist: mkdir failed on directory /opt/var/lib/samba: No such file or directory
Failed to initialise tdb mapping backend
failed to initialize group mapping
directory_create_or_exist: mkdir failed on directory /opt/var/lib/samba: No such file or directory
directory_create_or_exist: mkdir failed on directory /opt/var/lib/samba: No such file or directory
directory_create_or_exist: mkdir failed on directory /opt/var/lib/samba: No such file or directory
第四步:启动/opt/etc/init.d/S91smb start(restart,stop)
通过netstat -ntl查看是否出现139,445端口,结果没有出现,又转到/opt/var/log/samba下查看smbd的日志,看到如下 问题:
smbd version 4.18.8 started.
Copyright Andrew Tridgell and the Samba Team 1992-2023
SamInfo3_for_guest: Unable to locate guest account [nobody]!
get_guest_info3 failed with NT_STATUS_NO_SUCH_USER
ERROR: failed to setup guest info.
于是又百度,原来系统中没有nobody guest 用户,用useradd nobody,结果提示command not found,
又折腾了很久,结果无意中输入adduser nobody竟然成功,于是马上百度,这两个命令功能是一样的。
于是
adduser nobody
adduser guest
smbd restart
netstart -ntl
终于出现了139,445字眼:
-bash-4.3# netstat -ntl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8001 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:5900 0.0.0.0:* LISTEN
netstat: /proc/net/tcp6: No such file or directory
通过smbstatus可以查看samba连接状态