![Ubuntu 22.04 Samba 服务器 / 用户无法登录 / Windows PC 无法访问](https://linux22.com/image/946624/Ubuntu%2022.04%20Samba%20%E6%9C%8D%E5%8A%A1%E5%99%A8%20%2F%20%E7%94%A8%E6%88%B7%E6%97%A0%E6%B3%95%E7%99%BB%E5%BD%95%20%2F%20Windows%20PC%20%E6%97%A0%E6%B3%95%E8%AE%BF%E9%97%AE.png)
首先,抱歉我的英语不好。
我对 Ubuntu 上的 Samba 有几个问题
我只是 Linux 系统新手,我的新公司希望我将我们的服务团队文件服务器从 Debian Bullseye samba 升级到 Ubuntu 22.04 LTS,我尝试在 Debian 中安装和设置设置,作为练习,花了很多时间在 Debian Bullseye 和 Linux mint cinnamon 中设置 Samba 服务器,并且 Debian 和 Linux Mint 中的 Samba 运行良好,可以在 Windows XP、7、10、11 机器和 Linux 机器上访问。
但使用相同的设置,我尝试在装有 Ubuntu 22.04 LTS 的新电脑上安装和设置 Samba,服务正在运行,但其他用户无法访问(即使在 Ubuntu 机器上的网络文件夹中,我也无法访问共享文件)
现在我面临的问题是:
- 与我在 Debian 机器上工作一样,我使用在线找到的以下命令添加用户:
@sudo useradd --system --no-create-home -s /bin/false 用户名
(网络上的完整命令是@sudo useradd --system --no-create-home --group "groupname" -s /bin/false "username" /但由于我们只有少数工人,而且我们只需要存储个人工作文件,所以我把团体命令所以我们不需要管理组而只需专注于用户就可以了,而且我已经在 Debian 和 Linux Mint 上测试了这个命令,运行良好)
- 我还通过以下命令在 smbpasswd 中添加用户:
@sudo smbpasswd -a 用户名
并为用户提供以下功能:
@sudo smbpasswd -e 用户名
- 我还启用了所有用户公开读写和执行命令的功能,以便所有人都可以完全控制该文件夹,但随后通过使用 samba 用户控制和访问来限制访问。
@sudo chmod ugo+rwx /home/charles/share/用户名
- 我已经更新系统并安装了 samba 服务,然后再次更新系统。
然后我尝试设置 Samba smb.confi 并重新启动 samba 服务并让其运行。
由于我的所有工作都按照我在 Debian Samba 服务器上的步骤进行,所以它运行正常,但在 Ubuntu 上,它开始失败。
失败问题:
A. 所有设置与 Debian 中的相同,我已经测试过运行正常,但在 Ubuntu 中,共享文件可以由添加的用户可以访问,我尝试通过单击网络图标登录同一 Ubuntu Samba 服务器上的文件,并使用我已添加的用户(例如我使用 useradd 命令添加的用户 john)在电脑上登录,但登录失败。
所有添加的用户示例:John,Jenny,Sally,Puki 无法登录访问他们的文件夹,这些文件夹通常在 Debian Samba 服务器上运行良好,但在 Ubuntu 中却无法工作。
在 Ubuntu PC 上,在网络图标登录时只有主用户“charles:”是在格式化期间创建的,主用户可以访问所有文件夹(charles 是我的帐户,作为管理员,我可以访问所有用户文件夹,以防出现任何问题,我可以帮助其他用户备份)但除此之外,安装后添加的所有其他用户都不起作用。
B. 我怀疑是 Useradd 问题,因此我尝试干净格式化 Ubuntu 并重置所有内容以清理并重新设置所有用户,仅使用:
@sudo useradd username - 完全添加用户
@sudo passwd 用户名-设置密码
@sudo smbpasswd -a 用户名 - 设置 samba 密码
@sudo smbpasswd -e 用户名-启用
并将用户逐个登录到 Ubuntu PC,确认一切正常并重新测试 samba 服务,也是同样的情况,其他用户无法访问,只有 charles 主管理员帐户可以访问该文件夹。
C. 我测试过在网络上的其他机器上登录文件夹,但情况更糟。所有基于 Windows 的 PC XP、7、8、10、11 都无法访问该文件夹,我可以看到该文件夹,但单击它时,它请求登录,(好的,这是正确的,需要用户登录才能访问,这就是我想要的,在 Debian 上一切正常,但在 Ubuntu Samba 服务器上仍然失败)我尝试逐个用户登录,但都无法访问,更糟糕的是主管理员帐户也无法访问 Windows 机器上的文件夹。我也在 Linux 机器上尝试(debian、Ubuntu、Linux Mint),所有其他用户也无法登录,但感谢上帝在 Linux 机器上,管理员帐户仍然可以登录。只有 Windows 机器无法在 Ubuntu 中运行 Samba。
我尝试从网络上进行检查,为了测试如何绕过 Windows 中的防火墙,我还尝试完全禁用防火墙,禁用防病毒软件,按照说明修改注册表,尝试重新设置,并在注册表中设置允许不安全的来宾身份验证,还尝试将 Windows 用户和密码设置为与 samba 服务器相同,但仍然无法访问,还尝试将 samba 服务器密码和用户设置为与 Windows 用户相同,但仍然无法访问,
我还看到 Ubuntu 用户有实际用户来访问 samba,我也尝试要求我们的域管理员创建一个测试域,其中的所有 Ubuntu,以及其中的几台 Windows PC 和 Linux PC,都有实际帐户和运行良好的实际用户,但仍然一样,无法访问该文件夹。
以下是我使用的实际 samba 配置,在 Debian 中运行良好,但在 Ubuntu 中出现问题
smb配置文件
**
#
# Sample configuration file for the Samba suite for Debian GNU/Linux.
#
#
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options most of which
# are not shown in this example
#
# Some options that are often worth tuning have been included as
# commented-out examples in this file.
# - When such options are commented with ";", the proposed setting
# differs from the default Samba behaviour
# - When commented with "#", the proposed setting is the default
# behaviour of Samba but the option is considered important
# enough to be mentioned here
#
# NOTE: Whenever you modify this file you should run the command
# "testparm" to check that you have not made any basic syntactic
# errors.
#======================= Global Settings =======================
## Browsing/Identification ###
# Change this to the workgroup/NT-domain name your Samba server will part of
# server string is the equivalent of the NT Description field
#### Networking ####
# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
; interfaces = 127.0.0.0/8 eth0
# Only bind to the named interfaces and/or networks; you must use the
# 'interfaces' option above to use this.
# It is recommended that you enable this feature if your Samba machine is
# not protected by a firewall or is a firewall itself. However, this
# option cannot handle dynamic or non-broadcast interfaces correctly.
; bind interfaces only = yes
#### Debugging/Accounting ####
# This tells Samba to use a separate log file for each machine
# that connects
log file = /var/log/samba/log.%m
# Cap the size of the individual log files (in KiB).
max log size = 1000
# We want Samba to only log to /var/log/samba/log.{smbd,nmbd}.
# Append syslog@1 if you want important messages to be sent to syslog too.
logging = file
# Do something sensible when Samba crashes: mail the admin a backtrace
panic action = /usr/share/samba/panic-action %d
####### Authentication #######
# Server role. Defines in which mode Samba will operate. Possible
# values are "standalone server", "member server", "classic primary
# domain controller", "classic backup domain controller", "active
# directory domain controller".
#
# Most people will want "standalone server" or "member server".
# Running as "active directory domain controller" will require first
# running "samba-tool domain provision" to wipe databases and create a
# new domain.
server role = standalone server
obey pam restrictions = yes
# This boolean parameter controls whether Samba attempts to sync the Unix
# password with the SMB password when the encrypted SMB password in the
# passdb is changed.
unix password sync = yes
# For Unix password sync to work on a Debian GNU/Linux system, the following
# parameters must be set (thanks to Ian Kahan <<[email protected]> for
# sending the correct chat script for the passwd program in Debian Sarge).
passwd program = /usr/bin/passwd %u
passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
# This boolean controls whether PAM will be used for password changes
# when requested by an SMB client instead of the program listed in
# 'passwd program'. The default is 'no'.
pam password change = yes
# This option controls how unsuccessful authentication attempts are mapped
# to anonymous connections
########## Domains ###########
#
# The following settings only takes effect if 'server role = classic
# primary domain controller', 'server role = classic backup domain controller'
# or 'domain logons' is set
#
# It specifies the location of the user's
# profile directory from the client point of view) The following
# required a [profiles] share to be setup on the samba server (see
# below)
; logon path = \\%N\profiles\%U
# Another common choice is storing the profile in the user's home directory
# (this is Samba's default)
# logon path = \\%N\%U\profile
# The following setting only takes effect if 'domain logons' is set
# It specifies the location of a user's home directory (from the client
# point of view)
; logon drive = H:
# logon home = \\%N\%U
# The following setting only takes effect if 'domain logons' is set
# It specifies the script to run during logon. The script must be stored
# in the [netlogon] share
# NOTE: Must be store in 'DOS' file format convention
; logon script = logon.cmd
# This allows Unix users to be created on the domain controller via the SAMR
# RPC pipe. The example command creates a user account with a disabled Unix
# password; please adapt to your needs
; add user script = /usr/sbin/adduser --quiet --disabled-password --gecos "" %u
# This allows machine accounts to be created on the domain controller via the
# SAMR RPC pipe.
# The following assumes a "machines" group exists on the system
; add machine script = /usr/sbin/useradd -g machines -c "%u machine account" -d /var/lib/samba -s /bin/false %u
# This allows Unix groups to be created on the domain controller via the SAMR
# RPC pipe.
; add group script = /usr/sbin/addgroup --force-badname %g
############ Misc ############
# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting
; include = /home/samba/etc/smb.conf.%m
# Some defaults for winbind (make sure you're not using the ranges
# for something else.)
; idmap config * : backend = tdb
; idmap config * : range = 3000-7999
; idmap config YOURDOMAINHERE : backend = tdb
; idmap config YOURDOMAINHERE : range = 100000-999999
; template shell = /bin/bash
# Setup usershare options to enable non-root users to share folders
# with the net usershare command.
# Maximum number of usershare. 0 means that usershare is disabled.
# usershare max shares = 100
# Allow users who've been granted usershare privileges to create
# public shares, not just authenticated ones
usershare allow guests = no
#======================= Share Definitions =======================
# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each
# user's home directory as \\server\username
;[homes]
; comment = Home Directories
; browseable = no
# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.
; read only = yes
# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
; create mask = 0700
# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
; directory mask = 0700
# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# Un-comment the following parameter to make sure that only "username"
# can connect to \\server\username
# This might need tweaking when using external authentication schemes
; valid users = %S
# Un-comment the following and create the netlogon directory for Domain Logons
# (you need to configure Samba to act as a domain controller too.)
;[netlogon]
; comment = Network Logon Service
; path = /home/samba/netlogon
; guest ok = yes
; read only = yes
# Un-comment the following and create the profiles directory to store
# users profiles (see the "logon path" option above)
# (you need to configure Samba to act as a domain controller too.)
# The path below should be writable by all users so that their
# profile directory may be created the first time they log on
;[profiles]
; comment = Users profiles
; path = /home/samba/profiles
; guest ok = no
; browseable = no
; create mask = 0600
; directory mask = 0700
[printers]
comment = All Printers
browseable = no
path = /var/spool/samba
printable = no
guest ok = no
read only = yes
create mask = 0700
# Windows clients look for this share name as a source of downloadable
# printer drivers
[print$]
comment = Printer Drivers
path = /var/lib/samba/printers
browseable = no
read only = yes
guest ok = no
# Uncomment to allow remote administration of Windows print drivers.
# You may need to replace 'lpadmin' with the name of the group your
# admin users are members of.
# Please note that you also need to set appropriate Unix permissions
# to the drivers directory for these users to have write rights in it
; write list = root, @lpadmin
##################################################
[global]
server string = Samba Server
workgroup = SERVICETEAM
netbios name = FILESERVER
security = user
map to guest = Bad User
name resolve order = bcast host
# include = /etc/samba/smbshare.conf
# Dont remove the "include" line, for record and future use
##################################################
[Chalres]
path = /home/charles/share/charles
read only = no
browseable = yes
writeable = yes
valid users = charles
force users = charles
create mask = 0640
directory mask = 0750
[Christine]
path = /home/charles/share/christine
read only = no
browseable = yes
writeable = yes
valid users = christine
force users = christine
create mask = 0640
directory mask = 0750
[Cindy]
path = /home/charles/share/cindy
read only = no
browseable = yes
writeable = yes
valid users = cindy
force users = cindy
create mask = 0640
directory mask = 0750
[Jenny]
path = /home/charles/share/jenny
read only = no
browseable = yes
writeable = yes
valid users = jenny
force users = jenny
create mask = 0640
directory mask = 0750
[Joan]
path = /home/charles/share/joan
read only = no
browseable = yes
writeable = yes
valid users = joan
force users = joan
create mask = 0640
directory mask = 0750
[Puki]
path = /home/charles/share/puki
read only = no
browseable = yes
writeable = yes
valid users = puki
force users = puki
create mask = 0640
directory mask = 0750
[Public]
path = /home/charles/share/public
browseable = yes
read only = no
writeable = yes
valid users = charles, christine, cindy jenny, joan, puki
force users = charles, christine, cindy jenny, joan, puki
create mask = 0645
directory mask = 0755
**
我已经没有选择,也没有主意了,我想要的很简单,我只想从运行 Samba 的 Ubuntu 中共享文件夹,我只希望它与旧的 Debian Bullseye 系统通过 Samba 共享相同,可以通过网络上的 Windows 和 Linux 系统访问,并限制用户的访问权限只能访问他们自己的文件夹或公共共享文件夹,请各位专业人士帮助我,这样我就可以设置系统并保持系统运行。提前致谢
答案1
默认情况下,Debian 会创建一个权限为 755 的主目录。
这允许所有者拥有完全访问权限,并允许其他所有人遍历(打开)文件夹以查看其中的内容。
从 Ubuntu 22.04 开始,主目录的默认权限更改为 750。只有文件夹的所有者才能访问甚至遍历该文件夹。
像这样的路径的问题在于:/home/charles/share/username
是查尔斯。
您需要允许 samba 访问共享资源的完整路径:
将其改回旧的 Ubuntu 默认设置:
chmod o+rx /home/charles
或者甚至只是将文件夹设置为可供其他人遍历:
chmod o+x /home/charles
答案2
我从 20 升级到 22.04 后出现了这个问题。我无法从 windows11 等访问我的网络共享位置。我意识到共享不在 smb.conf 文件中。当我将它们添加到那里时,它们又可以正常工作了。
上述描述(conf 文件)中的共享是有效的。我使用整个驱动器作为共享,而不是文件夹,因此我的路径是 /mnt/DRIVExxxname/folder
我重启了 sambashare,一切正常