cifs文件系统

1:安装所需软件,打开smb,用本机登陆查看

[root@localhost ~]# yum install samba samba-common samba-client -y
[root@localhost ~]# systemctl start smb
[root@localhost ~]# systemctl status smb
smb.service - Samba SMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled)
   Active: active (running) since Mon 2017-08-21 05:58:50 EDT; 1s ago
 Main PID: 2480 (smbd)
   Status: "smbd: ready to serve connections..."
   CGroup: /system.slice/smb.service
           ├─2480 /usr/sbin/smbd
           └─2482 /usr/sbin/smbd

Aug 21 05:58:50 localhost smbd[2480]: [2017/08/21 05:58:50.093740,  0] ../l...y)
Aug 21 05:58:50 localhost smbd[2480]: STATUS=daemon 'smbd' finished startin...ns
Aug 21 05:58:50 localhost systemd[1]: Started Samba SMB Daemon.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# smbclient -L //172.25.254.111
Enter root's password: 
Anonymous login successful
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Sharename       Type      Comment
    ---------       ----      -------
    IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
Anonymous login successful
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------

2:共享某个用户,用student登陆并查看

[root@localhost ~]# pdbedit -L
[root@localhost ~]# pdbedit -a student
new password:
retype new password:
Unix username:        student
[root@localhost ~]# pdbedit -L
student:1000:Student User
[root@localhost ~]# smbpasswd -a lee   #添加lee
New SMB password:
Retype new SMB password:
Added user lee.
[root@localhost ~]# pdbedit -L    #查看共享用户
student:1000:Student User
lee:1001:
[root@localhost ~]# smbpasswd -x lee   #删除用户
Deleted user lee.
[root@localhost ~]# pdbedit -L
student:1000:Student User
[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter student's password: 
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Sharename       Type      Comment
    ---------       ----      -------
    IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
    student         Disk      Home Directories
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------
[root@localhost ~]# smbclient //172.25.254.111/student -U student
Enter student's password: 
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*
smb: \> quit
[root@localhost ~]# getenforce 
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# smbclient //172.25.254.111/student -U student
Enter student's password: 
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \> ls
  .                                   D        0  Thu Jul 10 19:06:52 2014
  ..                                  D        0  Thu Jul 10 18:19:09 2014
  .bash_logout                        H       18  Wed Jan 29 07:45:18 2014
  .bash_profile                       H      193  Wed Jan 29 07:45:18 2014
  .bashrc                             H      231  Wed Jan 29 07:45:18 2014
  .ssh                               DH        0  Thu Jul 10 18:19:10 2014
  .config                            DH        0  Thu Jul 10 19:06:53 2014

        10473900 blocks of size 1024. 7269980 blocks available
smb: \> 

3:用另一台电脑挂载并查看

[root@localhost ~]# mount -o username=student,password=student //172.25.254.111/student /mnt
[root@localhost ~]# df
Filesystem               1K-blocks    Used Available Use% Mounted on
/dev/vda1                 10473900 7593244   2880656  73% /
devtmpfs                    927072       0    927072   0% /dev
tmpfs                       942660      84    942576   1% /dev/shm
tmpfs                       942660   17052    925608   2% /run
tmpfs                       942660       0    942660   0% /sys/fs/cgroup
/dev/mapper/vg0-vo          483670    2377    451802   1% /home
/dev/loop0                 3947824 3947824         0 100% /var/www/html/rhel7.2
//172.25.254.111/student  10473900 3203912   7269988  31% /mnt
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
[root@localhost mnt]# ls -a
.  ..  .bash_logout  .bash_profile  .bashrc  .config  .ssh
[root@localhost ~]# umount /mnt    ##取消挂载
[root@localhost ~]# df
Filesystem         1K-blocks    Used Available Use% Mounted on
/dev/vda1           10473900 7593244   2880656  73% /
devtmpfs              927072       0    927072   0% /dev
tmpfs                 942660      84    942576   1% /dev/shm
tmpfs                 942660   17052    925608   2% /run
tmpfs                 942660       0    942660   0% /sys/fs/cgroup
/dev/mapper/vg0-vo    483670    2377    451802   1% /home
/dev/loop0           3947824 3947824         0 100% /var/www/html/rhel7.2

4:sebool值的授权

[root@localhost ~]# smbclient //172.25.254.111/student -U student
Enter student's password: 
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \> ls
NT_STATUS_ACCESS_DENIED listing \*
smb: \> quit
[root@localhost ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> off
samba_export_all_ro --> off
samba_export_all_rw --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
use_samba_home_dirs --> off
virt_sandbox_use_samba --> off
virt_use_samba --> off
[root@localhost ~]# setsebool -P samba_enable_home_dirs 1
[root@localhost ~]# smbclient //172.25.254.111/student -U student
Enter student's password: 
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \> ls
  .                                   D        0  Thu Jul 10 19:06:52 2014
  ..                                  D        0  Thu Jul 10 18:19:09 2014
  .bash_logout                        H       18  Wed Jan 29 07:45:18 2014
  .bash_profile                       H      193  Wed Jan 29 07:45:18 2014
  .bashrc                             H      231  Wed Jan 29 07:45:18 2014
  .ssh                               DH        0  Thu Jul 10 18:19:10 2014
  .config                            DH        0  Thu Jul 10 19:06:53 2014

        10473900 blocks of size 1024. 7261228 blocks available
smb: \> 

5:修改student Domain值

[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter student's password: 
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Sharename       Type      Comment
    ---------       ----      -------
    IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
    student         Disk      Home Directories
Domain=[MYGROUP] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------
[root@localhost ~]# vim /etc/samba/smb.conf 

这里写图片描述

[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter student's password: 
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Sharename       Type      Comment
    ---------       ----      -------
    IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
    student         Disk      Home Directories
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------

6:设置黑白名单

[root@localhost ~]# vim /etc/samba/smb.conf 

这里写图片描述
测试172.25.254.111

[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter student's password: 
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Sharename       Type      Comment
    ---------       ----      -------
    IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
    student         Disk      Home Directories
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------

用另一台电脑试

[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter student's password: 
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]
tree connect failed: NT_STATUS_ACCESS_DENIED

共享自己创建的目录

[root@localhost ~]# vim /etc/samba/smb.conf 
[root@localhost ~]# smbclient -L //172.25.254.111 -U student
Enter student's password: 
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Sharename       Type      Comment
    ---------       ----      -------
    DATA            Disk      local directory /westos
    IPC$            IPC       IPC Service (Samba Server Version 4.2.3)
    student         Disk      Home Directories
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------

这里写图片描述

7:登陆自己建立的共享目录

[root@localhost ~]# mkdir /westos
[root@localhost ~]# touch /westos/westosfile{1..4}
[root@localhost ~]# ls -Zd /westos
drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 /westos
[root@localhost ~]# semanage fcontext -a -t samba_share_t '/westos(/.*)?'
[root@localhost ~]# restorecon -RvvF /westos/
restorecon reset /westos context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/westosfile1 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/westosfile2 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/westosfile3 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
restorecon reset /westos/westosfile4 context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
[root@localhost ~]# smbclient //172.25.254.111/DATA -U student
Enter student's password: 
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \> ls
  .                                   D        0  Mon Aug 21 06:34:01 2017
  ..                                  D        0  Mon Aug 21 06:33:46 2017
  westosfile1                         N        0  Mon Aug 21 06:34:01 2017
  westosfile2                         N        0  Mon Aug 21 06:34:01 2017
  westosfile3                         N        0  Mon Aug 21 06:34:01 2017
  westosfile4                         N        0  Mon Aug 21 06:34:01 2017

        10473900 blocks of size 1024. 7261064 blocks available
smb: \> 
[root@localhost ~]# vim /etc/samba/smb.conf 

这里写图片描述

[root@localhost ~]# ls -Zd /etc      #配置文件不用改标签
drwxr-xr-x. root root system_u:object_r:etc_t:s0       /etc
[root@localhost ~]# smbclient //172.25.254.111/CONFIG -U student
Enter student's password: 
Domain=[WESTOS] OS=[Windows 6.1] Server=[Samba 4.2.3]
smb: \> ls
  .                                   D        0  Mon Aug 21 05:56:58 2017
  ..                                  D        0  Mon Aug 21 06:33:46 2017
  fstab                               N      313  Tue May  6 21:22:57 2014
  crypttab                            N        0  Tue May  6 21:22:57 2014
  mtab                                R        0  Mon Aug 21 06:45:40 2017
  pki                                 D        0  Tue May  6 21:27:13 2014
  rpm                                 D        0  Thu Jul 10 18:36:36 2014
  yum                                 D        0  Tue May  6 21:24:49 2014
  issue                               N       23  Tue Apr  1 09:28:10 2014
  binfmt.d                            D        0  Wed Apr  2 09:30:23 2014
  issue.net                           N       22  Tue Apr  1 09:28:10 2014
  modules-load.d                      D        0  Wed Apr  2 09:30:23 2014
  os-release                          N      493  Tue Apr  1 09:28:10 2014
  fonts                               D        0  Thu Jul 10 18:22:37

8:让异地电脑有上传文件权限

[root@localhost ~]# chmod 777 /westos
[root@localhost ~]# getsebool -a | grep samba
samba_create_home_dirs --> off
samba_domain_controller --> off
samba_enable_home_dirs --> on
samba_export_all_ro --> on
samba_export_all_rw --> off
samba_portmapper --> off
samba_run_unconfined --> off
samba_share_fusefs --> off
samba_share_nfs --> off
sanlock_use_samba --> off
use_samba_home_dirs --> off
virt_sandbox_use_samba --> off
virt_use_samba --> off
[root@localhost ~]# vim /etc/samba/smb.conf

这里写图片描述

[root@localhost ~]# mount -o username=student,password=student //172.25.254.111/DATA /mnt
[root@localhost ~]# cd /mnt
[root@localhost mnt]# ls
westosfile1  westosfile2  westosfile3  westosfile4
[root@localhost mnt]# touch file
[root@localhost mnt]# ls
file  westosfile1  westosfile2  westosfile3  westosfile4
[root@localhost mnt]# rm -fr file
[root@localhost mnt]# ls
westosfile1  westosfile2  westosfile3  westosfile4

9:多用户共享目录

[root@localhost ~]# vim /etc/samba/smb.conf 
[root@localhost ~]# systemctl restart smb.service 

这里写图片描述
这里写图片描述

[root@localhost ~]# vim /root/smbpassword [root@localhost ~]# chmod 600 /root/smbpassword [root@localhost ~]# mount -o credentials=/root/smbpassword,multiuser,sec=ntlmssp //172.25.254.111/DATA /mnt

这里写图片描述

[root@localhost ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/vda1              10473900 7620580   2853320  73% /
devtmpfs                 927072       0    927072   0% /dev
tmpfs                    942660      84    942576   1% /dev/shm
tmpfs                    942660   17024    925636   2% /run
tmpfs                    942660       0    942660   0% /sys/fs/cgroup
/dev/mapper/vg0-vo       483670    2399    451780   1% /home
/dev/loop0              3947824 3947824         0 100% /var/www/html/rhel7.2
//172.25.254.111/DATA  10473900 3205196   7268704  31% /mnt
在Linux系统中,可以通过`mount`命令将远程的CIFS文件系统挂载到本地目录。CIFS(Common Internet File System)是一种网络文件共享协议,通常用于Windows网络共享。如果你需要将Windows系统下的`winshare`目录挂载到Linux系统的当前宿主目录下的`share`子目录,可以按照以下步骤操作: 1. 确保你的Linux系统中已经安装了cifs-utils工具包,这个包提供了挂载CIFS文件系统的必要工具。可以通过包管理器安装,例如在基于Debian的系统中使用`apt-get install cifs-utils`。 2. 创建一个本地目录作为挂载点,例如在当前宿主目录下创建一个名为`share`的目录: ```bash mkdir ~/share ``` 3. 使用`mount`命令挂载远程的Windows共享目录。这需要知道Windows共享的IP地址或主机名、共享目录名称以及用户名等信息。挂载命令可能类似于: ```bash sudo mount -t cifs //winshare_ip_or_name/share /home/username/share -o username=user,password=pass ``` 其中`winshare_ip_or_name`是Windows共享的IP地址或主机名,`user`和`pass`分别是访问该共享的用户名和密码。`/home/username/share`是你在Linux上创建的挂载点目录。 4. 如果你希望每次开机时自动挂载该共享目录,你可以编辑`/etc/fstab`文件,添加以下行: ```bash //winshare_ip_or_name/share /home/username/share cifs username=user,password=pass 0 0 ``` 注意:存储用户名和密码在`fstab`文件中可能存在安全风险,因此在实际部署时应考虑使用更安全的认证方式,比如使用密钥文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值