首页 > 其他分享 >samba报错NT_STATUS_ACCESS_DENIED making remote directory xxx

samba报错NT_STATUS_ACCESS_DENIED making remote directory xxx

时间:2023-01-02 11:34:31浏览次数:67  
标签:STATUS samba Jun Tue barney 报错 txt root smb

目录

samba简单示例及参数解释

问题描述

[root@servera ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.1 (Ootpa)


[root@servera ~]# yum -y install samba samba-client


[root@servera ~]# mkdir /groupdir
[root@servera ~]# semanage fcontext -a -t samba_share_t "/groupdir(/.*)?"
[root@servera ~]# restorecon -Rv /groupdir/
[root@servera ~]# ll -dZ /groupdir/
drwxr-xr-x. 2 root root unconfined_u:object_r:samba_share_t:s0 6 Jun  2 09:24 /groupdir/


[root@servera ~]# firewall-cmd --permanent --add-service=samba
[root@servera ~]# firewall-cmd --reload 


# 配置
[root@servera ~]# cp -p /etc/samba/smb.conf{,-bak}
[root@servera ~]# vim /etc/samba/smb.conf
[global]
        workgroup = STAFF
        security = user
....
  ....
[common]
        path = /groupdir
        browseable = Yes
        hosts allow = 172.25.250.0/24
        write list = barney
        writable = Yes


[root@servera ~]# testparm
[root@servera ~]# systemctl enable --now smb


[root@servera ~]# smbclient -U barney //localhost/common
Enter STAFF\barney's password: 
Try "help" to get a list of possible commands.
smb: \> pwd
Current directory is \\localhost\common\
smb: \> mkdir opop
NT_STATUS_ACCESS_DENIED making remote directory \opop
smb: \> q

解决

# 参考地址
https://unix.stackexchange.com/questions/519403/nt-status-access-denied-listing-when-moving-home-directories-to-another-locat

[root@servera ~]# setfacl -m u:barney:rwX /groupdir/
[root@servera ~]# smbclient -U barney //localhost/common
Enter STAFF\barney's password: 
Try "help" to get a list of possible commands.
smb: \> mkdir opop
smb: \> ls 
  .                                   D        0  Tue Jun  2 10:41:55 2020
  ..                                  D        0  Tue Jun  2 09:24:11 2020
  opop                                D        0  Tue Jun  2 10:41:55 2020

		10474476 blocks of size 1024. 8168980 blocks available


# 不能直接写入/创建文件,即使下面直接写入文件没报错,但在共享目录中不会存在
smb: \> echo "12345" >> 1.txt



# 客户端使用同用户登录samba测试下
[root@serverb ~]# yum -y install samba-client
[root@serverb ~]# mkdir /mnt/opop
[root@serverb ~]# mount -t cifs -o username=barney,password=redhat //172.25.250.10/common /mnt/opop
[root@serverb ~]# df -Th /mnt/opop
Filesystem             Type  Size  Used Avail Use% Mounted on
//172.25.250.10/common cifs   10G  2.2G  7.8G  23% /mnt/opop

[root@serverb ~]# smbclient -U barney //172.25.250.10/common
Enter SAMBA\barney's password: 
Try "help" to get a list of possible commands.
smb: \> mkdir kkkk
smb: \> ls
  .                                   D        0  Tue Jun  2 10:51:20 2020
  ..                                  D        0  Tue Jun  2 09:24:11 2020
  opop                                D        0  Tue Jun  2 10:41:55 2020
  kkkk                                D        0  Tue Jun  2 10:51:20 2020


smb: \> q
[root@serverb ~]# ll /mnt/opop/                        # 在客户端查看挂载点中新创建的目录           
total 0
drwxr-xr-x. 2 root root 0 Jun  2 10:51 kkkk            # 注意这里的权限属主和属组都是root用户
drwxr-xr-x. 2 root root 0 Jun  2 10:41 opop


[root@servera ~]# ll /groupdir/                        # 在服务段查看共享目录
total 0
drwxr-xr-x. 2 barney barney 6 Jun  2 10:51 kkkk        # 在共享目录中新创建的属主和属组都是barney用户
drwxr-xr-x. 2 barney barney 6 Jun  2 10:41 opop


[root@serverb ~]# ll
total 16
-rw-------. 1 root root 6971 Oct 30  2019 anaconda-ks.cfg
-rw-------. 1 root root 6774 Oct 30  2019 original-ks.cfg

[root@serverb ~]# smbclient -U barney //172.25.250.10/common
Enter SAMBA\barney's password: 
Try "help" to get a list of possible commands.
smb: \> put /root/anaconda-ks.cfg                           # 记住该报错,下面会有说明
NT_STATUS_OBJECT_PATH_NOT_FOUND opening remote file \root\anaconda-ks.cfg


# 解决
[root@serverb ~]# useradd barney
[root@serverb ~]# yum -y install samba
[root@serverb ~]# smbpasswd -a barney
New SMB password:              # 密码都是redhat
Retype new SMB password:
Added user barney.


[barney@serverb ~]$ echo "123456" >> 1.txt
[barney@serverb ~]$ ll
total 4
-rw-rw-r--. 1 barney barney 7 Jun  2 11:07 1.txt

# 再来登录并上传新创建的1.txt
[barney@serverb ~]$ smbclient -U barney //172.25.250.10/common
Unable to initialize messaging context
Enter SAMBA\barney's password: 
Try "help" to get a list of possible commands.
# 报错了
smb: \> put /home/barney/1.txt
NT_STATUS_OBJECT_PATH_NOT_FOUND opening remote file \home\barney\1.txt
smb: \> q
[barney@serverb ~]$ ll         # 该路径下确实有1.txt但依旧不能上传,实际上该流程并没有问题
total 4
-rw-rw-r--. 1 barney barney 7 Jun  2 11:07 1.txt

# 再来上传一次,这次不使用绝对路径
[barney@serverb ~]$ smbclient -U barney //172.25.250.10/common
Unable to initialize messaging context
Enter SAMBA\barney's password: 
Try "help" to get a list of possible commands.
smb: \> put 1.txt                      =======> 上传时必须在文件所在目录中登录samba且不要使用绝对路径
putting file 1.txt as \1.txt (3.4 kb/s) (average 3.4 kb/s)
smb: \> ls
  .                                   D        0  Tue Jun  2 11:10:39 2020
  ..                                  D        0  Tue Jun  2 09:24:11 2020
  opop                                D        0  Tue Jun  2 10:41:55 2020
  kkkk                                D        0  Tue Jun  2 10:51:20 2020
  1.txt                               A        7  Tue Jun  2 11:10:39 2020

		10474476 blocks of size 1024. 8168952 blocks available

smb: \> q


# 测试多文件上传
[barney@serverb ~]$ touch {2..5}.txt
[barney@serverb ~]$ ll
total 4
-rw-rw-r--. 1 barney barney 7 Jun  2 11:07 1.txt
-rw-rw-r--. 1 barney barney 0 Jun  2 11:14 2.txt
-rw-rw-r--. 1 barney barney 0 Jun  2 11:14 3.txt
-rw-rw-r--. 1 barney barney 0 Jun  2 11:14 4.txt
-rw-rw-r--. 1 barney barney 0 Jun  2 11:14 5.txt


[barney@serverb ~]$ smbclient -U barney //172.25.250.10/common
smb: \> ?          =====> 查看所有可用命令
?              allinfo        altname        archive        backup         
blocksize      cancel         case_sensitive cd             chmod          
chown          close          del            deltree        dir            
du             echo           exit           get            getfacl        
geteas         hardlink       help           history        iosize         
lcd            link           lock           lowercase      ls             
l              mask           md             mget           mkdir          
more           mput           newer          notify         open           
posix          posix_encrypt  posix_open     posix_mkdir    posix_rmdir    
posix_unlink   posix_whoami   print          prompt         put            
pwd            q              queue          quit           readlink       
rd             recurse        reget          rename         reput          
rm             rmdir          showacls       setea          setmode        
scopy          stat           symlink        tar            tarmode        
timeout        translate      unlock         volume         vuid           
wdel           logon          listconnect    showconnect    tcon           
tdis           tid            utimes         logoff         ..             
!              

smb: \> mput 2.txt 3.txt 4.txt            ===> 换成mput命令即可,多文件之间用空格分隔,多文件下载用mget
Put file 2.txt? y                         ===> 这里仅做测试,因为该文件已经存在所以会有该提示
putting file 2.txt as \2.txt (0.0 kb/s) (average 0.0 kb/s)
Put file 3.txt? y
putting file 3.txt as \3.txt (0.0 kb/s) (average 0.0 kb/s)
Put file 4.txt? y
putting file 4.txt as \4.txt (0.0 kb/s) (average 0.0 kb/s)
smb: \> ls
  .                                   D        0  Tue Jun  2 11:18:34 2020
  ..                                  D        0  Tue Jun  2 09:24:11 2020
  opop                                D        0  Tue Jun  2 10:41:55 2020
  kkkk                                D        0  Tue Jun  2 10:51:20 2020
  1.txt                               A        7  Tue Jun  2 11:10:39 2020
  3.txt                               A        0  Tue Jun  2 11:18:32 2020
  2.txt                               A        0  Tue Jun  2 11:18:30 2020
  4.txt                               A        0  Tue Jun  2 11:18:34 2020

		10474476 blocks of size 1024. 8169032 blocks available


标签:STATUS,samba,Jun,Tue,barney,报错,txt,root,smb
From: https://www.cnblogs.com/smlile-you-me/p/17019470.html

相关文章