我的 crontab(以用户身份运行)包含以下命令
00-59 00-23 * * * /usr/bin/smbget -R smb://192.168.10.32/Data -u USER -p PASSWORD
但我收到错误,因为您没有足够的权限访问smb://192.168.10.32/Data/
但是我可以从命令行执行(以用户身份运行)相同的命令。
如何授予 crontab 权限来解决这个问题。
我执行后捕获到的错误:
00-59 00-23 * * * /usr/bin/smbget -R smb://192.168.10.32/Data -u USER -p PASSWORD 2>> /path/to/samba.log
无法打开目录 smb://192.168.10.32/Data/a:权限被拒绝
无法打开目录 smb://192.168.10.32/Data/b:权限被拒绝
无法打开目录 smb://192.168.10.32/Data/c:权限被拒绝
您没有足够的权限访问 smb://192.168.10.32/Data/d
您没有足够的权限访问 smb://192.168.10.32/Data/e
DEBUG 语句
params.c:OpenConfFile() - Unable to open configuration file "/home/USER/.smb/smb.conf":
No such file or directory
params.c:OpenConfFile() - Unable to open configuration file "/home/USER/.smb/smb.conf.append":
No such file or directory
Using netbios name MACHINE_NAME1.
Using workgroup WORKGROUP.
parsed path: fname='smb://192.168.10.32/Data' server='192.168.10.32' share='Data' path='' options=''
SMBC_check_options(): server='192.168.10.32' share='Data' path='' options=''
SMBC_server: server_n=[192.168.10.32] server=[192.168.10.32]
-> server_n=[192.168.10.32] server=[192.168.10.32]
Connecting to 192.168.10.32 at port 445
session request ok
Doing spnego session setup (blob length=46)
got OID=1.3.6.1.4.1.311.2.2.10
got principal=<null>
Got challenge flags:
Got NTLMSSP neg_flags=0x628a8215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_TARGET_INFO
NTLMSSP_NEGOTIATE_VERSION
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP: Set final flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP Sign/Seal - Initialising with flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
session setup ok
tconx ok
Case sensitive: True
Server connect ok: //192.168.10.32/Data: 0x7f552dd6a290
received 10 entries (eos=1)
parsed path: fname='smb://192.168.10.32/Data/BSEEQ' server='192.168.10.32' share='Data' path='\BSEEQ' options=''
SMBC_check_options(): server='192.168.10.32' share='Data' path='\BSEEQ' options=''
SMBC_server: server_n=[192.168.10.32] server=[192.168.10.32]
-> server_n=[192.168.10.32] server=[192.168.10.32]
Connecting to 192.168.10.32 at port 445
session request ok
Doing spnego session setup (blob length=46)
got OID=1.3.6.1.4.1.311.2.2.10
got principal=<null>
Got challenge flags:
Got NTLMSSP neg_flags=0x628a8215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_TARGET_INFO
NTLMSSP_NEGOTIATE_VERSION
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP: Set final flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP Sign/Seal - Initialising with flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
SPNEGO login failed: Account disabled
session setup ok
parsed path: fname='smb://192.168.10.32/Data/MCX' server='192.168.10.32' share='Data' path='\MCX' options=''
SMBC_check_options(): server='192.168.10.32' share='Data' path='\MCX' options=''
SMBC_server: server_n=[192.168.10.32] server=[192.168.10.32]
-> server_n=[192.168.10.32] server=[192.168.10.32]
Connecting to 192.168.10.32 at port 445
session request ok
Doing spnego session setup (blob length=46)
got OID=1.3.6.1.4.1.311.2.2.10
got principal=<null>
Got challenge flags:
Got NTLMSSP neg_flags=0x628a8215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_TARGET_INFO
NTLMSSP_NEGOTIATE_VERSION
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP: Set final flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP Sign/Seal - Initialising with flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
SPNEGO login failed: Account disabled
session setup ok
parsed path: fname='smb://192.168.10.32/Data/NCDEX' server='192.168.10.32' share='Data' path='\NCDEX' options=''
SMBC_check_options(): server='192.168.10.32' share='Data' path='\NCDEX' options=''
SMBC_server: server_n=[192.168.10.32] server=[192.168.10.32]
-> server_n=[192.168.10.32] server=[192.168.10.32]
Connecting to 192.168.10.32 at port 445
session request ok
Doing spnego session setup (blob length=46)
got OID=1.3.6.1.4.1.311.2.2.10
got principal=<null>
Got challenge flags:
Got NTLMSSP neg_flags=0x628a8215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_TARGET_INFO
NTLMSSP_NEGOTIATE_VERSION
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP: Set final flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP Sign/Seal - Initialising with flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
SPNEGO login failed: Account disabled
session setup ok
parsed path: fname='smb://192.168.10.32/Data/NSEEQ' server='192.168.10.32' share='Data' path='\NSEEQ' options=''
SMBC_check_options(): server='192.168.10.32' share='Data' path='\NSEEQ' options=''
SMBC_server: server_n=[192.168.10.32] server=[192.168.10.32]
-> server_n=[192.168.10.32] server=[192.168.10.32]
Connecting to 192.168.10.32 at port 445
session request ok
Doing spnego session setup (blob length=46)
got OID=1.3.6.1.4.1.311.2.2.10
got principal=<null>
Got challenge flags:
Got NTLMSSP neg_flags=0x628a8215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_TARGET_INFO
NTLMSSP_NEGOTIATE_VERSION
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP: Set final flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP Sign/Seal - Initialising with flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
SPNEGO login failed: Account disabled
session setup ok
parsed path: fname='smb://192.168.10.32/Data/NSEFO' server='192.168.10.32' share='Data' path='\NSEFO' options=''
SMBC_check_options(): server='192.168.10.32' share='Data' path='\NSEFO' options=''
SMBC_server: server_n=[192.168.10.32] server=[192.168.10.32]
-> server_n=[192.168.10.32] server=[192.168.10.32]
Connecting to 192.168.10.32 at port 445
session request ok
Doing spnego session setup (blob length=46)
got OID=1.3.6.1.4.1.311.2.2.10
got principal=<null>
Got challenge flags:
Got NTLMSSP neg_flags=0x628a8215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_TARGET_INFO
NTLMSSP_NEGOTIATE_VERSION
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP: Set final flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP Sign/Seal - Initialising with flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
SPNEGO login failed: Account disabled
session setup ok
parsed path: fname='smb://192.168.10.32/Data/SCRIPMASTER' server='192.168.10.32' share='Data' path='\SCRIPMASTER' options=''
SMBC_check_options(): server='192.168.10.32' share='Data' path='\SCRIPMASTER' options=''
SMBC_server: server_n=[192.168.10.32] server=[192.168.10.32]
-> server_n=[192.168.10.32] server=[192.168.10.32]
Connecting to 192.168.10.32 at port 445
session request ok
Doing spnego session setup (blob length=46)
got OID=1.3.6.1.4.1.311.2.2.10
got principal=<null>
Got challenge flags:
Got NTLMSSP neg_flags=0x628a8215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_TARGET_INFO
NTLMSSP_NEGOTIATE_VERSION
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP: Set final flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP Sign/Seal - Initialising with flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
SPNEGO login failed: Account disabled
session setup ok
SMBC_server: server_n=[192.168.10.32] server=[192.168.10.32]
-> server_n=[192.168.10.32] server=[192.168.10.32]
Connecting to 192.168.10.32 at port 445
session request ok
Doing spnego session setup (blob length=46)
got OID=1.3.6.1.4.1.311.2.2.10
got principal=<null>
Got challenge flags:
Got NTLMSSP neg_flags=0x628a8215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_TARGET_INFO
NTLMSSP_NEGOTIATE_VERSION
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP: Set final flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP Sign/Seal - Initialising with flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
SPNEGO login failed: Account disabled
session setup ok
SMBC_server: server_n=[192.168.10.32] server=[192.168.10.32]
-> server_n=[192.168.10.32] server=[192.168.10.32]
Connecting to 192.168.10.32 at port 445
session request ok
Doing spnego session setup (blob length=46)
got OID=1.3.6.1.4.1.311.2.2.10
got principal=<null>
Got challenge flags:
Got NTLMSSP neg_flags=0x628a8215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_TARGET_INFO
NTLMSSP_NEGOTIATE_VERSION
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP: Set final flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
NTLMSSP Sign/Seal - Initialising with flags:
Got NTLMSSP neg_flags=0x60088215
NTLMSSP_NEGOTIATE_UNICODE
NTLMSSP_REQUEST_TARGET
NTLMSSP_NEGOTIATE_SIGN
NTLMSSP_NEGOTIATE_NTLM
NTLMSSP_NEGOTIATE_ALWAYS_SIGN
NTLMSSP_NEGOTIATE_NTLM2
NTLMSSP_NEGOTIATE_128
NTLMSSP_NEGOTIATE_KEY_EXCH
SPNEGO login failed: Account disabled
session setup ok
Using workgroup WORKGROUP, user USER
/home/USER
答案1
我遇到了类似的问题。显然,使用 smbget 抓取递归目录会使用当前的 $USER 环境变量。将此变量设置为传递给 smbget 的用户名可以解决这个问题,但对于 Cron Jobs 仍然不起作用。
此问题记录在此处:https://bugzilla.samba.org/show_bug.cgi?id=8400
以下是我的脚本片段
pUSER=$USER # store previous user
USER=$username # new username
smbget -R -v -U -u "$username" "smb://server/c$/directory"
USER=$pUSER # restore previous username
这可以通过命令行工作,但从 cron 调用时则不行,非常令人困惑。
希望这对某人有帮助。
编辑
重新审视这一点后,我意识到使用 smbmount 也可以实现同样的效果。下面的代码是一个即使从 crontab 调用也能正常工作的示例。
username=myuser
domain=corp #optional domain prefix
PASS=password123
smbmount \\\\fileserver\\sharename /mnt/somedir -o user=$username,password=$PASS,dom=$domain
cp -R -u -v /mnt/somedir/* /destination_directory
umount /mnt/somedir
答案2
我也在处理这个问题,并找到了解决方法 - 这似乎是该问题的相关错误:https://bugzilla.samba.org/show_bug.cgi?id=6482
在该错误报告中,它建议您将用户名和密码嵌入 SMB URI 中,例如:
smbget -Rr smb://user:pass@host/sharename
我遇到了权限被拒绝的问题,但是上述格式运行良好。
请注意:如果您在 crontab 中使用此方法,则任何有权访问该框的人都可以通过检查进程列表来获取凭据。不过,这对于私有系统来说可能是可以接受的。
答案3
请记住,在最近遇到许多不同但相似的问题后,cron 运行的是sh
,而不是您选择的 shell(可能是bash
)。因此,我强烈建议您仔细检查它,因为 的功能sh
与 bash 以及所有内置程序、命令和可用的环境变量相比受到很大限制。其次,请记住转义非字母数字字符总是很有趣。第三,当所有其他方法都失败时,让 cron 作业运行 smbget00-59 00-23 * * * /usr/bin/smbget -R smb://192.168.10.32/Data -u USER -p PASSWORD 2>&1 >> /path/to/samba.log
以获取更多详细信息。使用该信息更新此帖子可能会帮助我们缩小问题范围。抱歉,但每个用户的 cron 操作并不像看起来那么简单。