网站建设资讯

NEWS

网站建设资讯

samba

####samba#########

成都创新互联公司是专业的乐都网站建设公司,乐都接单;提供成都做网站、网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行乐都网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

1samba作用

提供cifs协议实现共享文件

 

2安装

yum install samba samba-common samba-client -y

systemctl start smb nmb

systemctl enable smb nmb

systemctl stop firewalld.service

 

3添加smb用户

smb用户必须是本地用户

smbpasswd -a student

New SMB password:                   #输入smb当前用户密码

Retype new SMB password:#确认密码

Added user student.

 

pdbedit -L#查看smb用户信息

student:1000:Student User  

 

pdbedit -x student#删除smb用户

 

setsebool -P samba_enable_home_dirs on  ##在selinux中设定smb用户可以访问自己的家目录

 

4共享目录的基本设定

117

mkdir /smbshare

touch /smbshare/123

 

vim /etc/samba/smb.conf

321         [westos]      ##共享名称

322         comment = local directory   ##对共享目录的描述

323         path = /smbshare     ##共享目录的绝对路径

 

当共享目录为用户自建目录时

semanage fcontext -a -t samba_share_t '/smbshare(/.*)?'

restorecon -Rvvf /smbshare/

systemctl restart smb.service

 

测试

17

[root@DNS-server 桌面]# smbclient //172.25.254.117/westos -U student

Enter student's password:

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Sat Jun  3 14:39:20 2017

  ..                                  D        0  Sat Jun  3 14:39:12 2017

  123                                 N        0  Sat Jun  3 14:39:20 2017

 

10473900 blocks of size 1024. 7316272 blocks available

smb: \> SMBecho failed (NT_STATUS_CONNECTION_DISCONNECTED). The connection is disconnected now

 

当共享目录为系统建立目录

setsebool -P samba_export_all_ro on#只读共享

setsebool -P samba_export_all_rw on#读写共享

systemctl restart smb.service

 

测试

17

[root@dns-server 桌面]# smbclient //172.25.254.117/westos -U student

Enter student's password:

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Sat Jun  3 13:54:54 2017

  ..                                  D        0  Sat Jun  3 14:39:12 2017

  fstab                               N      313  Wed May  7 09:22:57 2014

  crypttab                            N        0  Wed May  7 09:22:57 2014

  mtab                                R        0  Sat Jun  3 14:47:19 2017

  pki                                 D        0  Wed May  7 09:27:13 2014

  rpm                                 D        0  Fri Jul 11 06:36:36 2014

  yum                                 D        0  Wed May  7 09:24:49 2014

  issue                               N       23  Tue Apr  1 21:28:10 2014

  binfmt.d                            D        0  Wed Apr  2 21:30:23 2014

  issue.net                           N       22  Tue Apr  1 21:28:10 2014

  modules-load.d                      D        0  Wed Apr  2 21:30:23 2014

  os-release                          N      493  Tue Apr  1 21:28:10 2014

  fonts                               D        0  Fri Jul 11 06:22:37 2014

  redhat-release                      N       52  Tue Apr  1 21:28:10 2014

  DIR_COLORS.256color                 N     5725  Sat Jan 25 03:23:50 2014

    。。。。。。。

 

5samba的配置参数

   

#匿名用户访问

vim /etc/samba/smb.conf

125         map to guest = bad user

324guest ok = yes

 

测试

17

[root@dns-server 桌面]# smbclient //172.25.254.117/westos

Enter kiosk's password:      ###无密码

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Sat Jun  3 14:39:20 2017

  ..                                  D        0  Sat Jun  3 14:39:12 2017

  123                                 N        0  Sat Jun  3 14:39:20 2017

 

10473900 blocks of size 1024. 7305320 blocks available

 

 

 

#访问控制

hosts allow =  ##仅允许

hosts deny =  ##仅拒绝

valid users =#当前共享的有效用户

valid users = westos#当前共享的有效用户为westos

valid users = @westos#当前共享的有效用户为westos组

valid users = +westos#当前共享的有效用户为westos组

测试

117

vim /etc/samba/smb.conf

325         hosts allow = 172.25.254.17

 

17

[root@dns-server 桌面]# smbclient //172.25.254.117/westos

Enter kiosk's password:

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \> ls

  .                                   D        0  Sat Jun  3 14:39:20 2017

  ..                                  D        0  Sat Jun  3 14:39:12 2017

  123                                 N        0  Sat Jun  3 14:39:20 2017

 

10473900 blocks of size 1024. 7305276 blocks available

217

[root@localhost ~]# smbclient //172.25.254.117/westos

Enter root's password:

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

tree connect failed: NT_STATUS_ACCESS_DENIED

 

测试

117

vim /etc/samba/smb.conf

324         valid users = westos

 

17

[root@dns-server 桌面]# useradd westos -s /sbin/nologin

[root@dns-server 桌面]# smbpasswd -a westos

New SMB password:

Retype new SMB password:

Added user westos.

[root@dns-server 桌面]# smbclient //172.25.254.117/westos -U westos

Enter westos's password:

Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

smb: \>

 

 

##读写控制

所有用户均可写

chmod o+w /smbshare   ##修改共享目录权限

setsebool -P samba_export_all_rw on

vim /etc/samba/smb.conf

324         writable = yes

systemctl restart smb.service

 

测试

17

[root@dns-server 桌面]# mount -o username=westos,password=redhat //172.25.254.117/westos /mnt/

[root@dns-server 桌面]# cd /mnt/

[root@dns-server mnt]# ls

123

[root@dns-server mnt]# touch file3

[root@dns-server mnt]# ls

123  file3

 

 

 

设定指定用户可写

write list = student    #可写用户

write list = +student#可写用户组

write list = @stident

admin users = westos#共享的超级用户指定

 

测试

117

vim /etc/samba/smb.conf

324         writable = no

325         write list = student

 

 

217

smbpasswd -a student

useradd westos

usermod -G westos student

mount -o username=student,password=123 //172.25.254.117/westos /mnt/

[root@localhost mnt]# ls

123  1234fref  file3

[root@localhost mnt]# touch file5

[root@localhost mnt]# ls

123  1234fref  file3  file5

 

测试

117

vim /etc/samba/smb.conf

324         writable = yes

325         admin users = westos

 

217

[root@localhost ~]# mount -o username=westos,password=redhat //172.25.254.117/westos /mnt/

[root@localhost ~]# cd /mnt/

[root@localhost mnt]# ls

123  1234fref  file3  file5

[root@localhost mnt]# touch file6

[root@localhost mnt]# ls -l file6

-rw-r--r--. 1 root westos 0 6月   3 04:36 file6

 

 

6smb多用户挂载

在client(客户端)上

 

vim /root/haha

username=student

password=123     ##密码为smb密码

 

chmod 600 /root/haha

 

yum install cifs-utils.x86_64  -y

 

mount -o credentials=/root/haha,multiuser,sec=ntlmssp //172.25.254.117/westos /mnt/

 

#credentials=/root/haha  指定挂载时所用到的用户文件

#multiuser        支持多用户认证

#sec=ntlmssp认证方式为标准smb认证方式

 

 

 

 

[root@localhost ~]# su - westos

[westos@localhost ~]$ ls /mnt

ls: cannot access /mnt: Permission denied   #因为没有作smb的认证所以无法访问smb的共享

[westos@localhost ~]$ cifscreds add -u westos 172.25.254.117

Password:##smb用户westos的密码

[westos@localhost ~]$ ls /mnt

123  1234fref  file3  file5  file6

[westos@localhost ~]$


文章题目:samba
当前地址:http://njwzjz.com/article/gjhdjs.html