samba
来源:互联网 发布:网络服务器租用业务员 编辑:程序博客网 时间:2024/06/10 05:37
SAMBA:
通用Internet文件系统(CIFS)也称为服务器信息块(SMB),是适用于MicrosoftWindows服务器和客户端的标准文件和打印机共享系统。Samba服务可用于将Linux文件系统作为CIFS/SMB网络文件共享进行共享,并将Linux打印机作为CIFS/SMB打印机共享进行共享。
Samba服务的组成部分
1) 软件包:
Samba-common – Samba的支持文件
Samba-client – 客户端应用程序
Samba – 服务器应用程序
2) 服务名称:smb nmb
3) 服务端口: 通常使用TCP/445进行所有连接。还使用UDP137、UDP138和TCP/139进行向后兼容
4) 主配置文件:/etc/samba/smb.conf
1.samba作用
提供cifs协议实现共享文件
2.安装
yum install samba samba-common samba-client -y
systemctl start smb nmb
systemctl enable smb nmb
注意关掉火墙
测试:
smbclient -L //172.25.254.100##匿名登陆,不需要输入密码
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 smb用户 ###删除smb用户
setsebool -P samba_enable_home_dirs on ###在selinux中设定smb用户可以访问自己的家目录
客户端登录测试:
[kiosk@foundation42 Desktop]$ smbclient //172.25.254.100/student -U student ##使用smb用户登陆
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Fri Jul 11 07:06:52 2014
.. D 0 Fri Jul 11 06:19:09 2014
.bash_logout H 18 Wed Jan 29 20:45:18 2014
.bash_profile H 193 Wed Jan 29 20:45:18 2014
.bashrc H 231 Wed Jan 29 20:45:18 2014
.ssh DH 0 Fri Jul 11 06:19:10 2014
.config DH 0 Fri Jul 11 07:06:53 2014
10473900 blocks of size 1024. 7305060 blocks available
4.共享目录的基本设定
vim /etc/samba/smb.conf
[westos] 共享名称
comment = 对共享目录的描述
path = 共享目录的绝对路径
1)当共享目录为用户自建立的目录时:
mkdir /smbshare ###创建共享目录
touch /smbshare/lalala ###创建共享文件
semanage fcontext -a -t samba_share_t '/smbshare(/.*)?' ##更改安全上下文
restorecon -RvvF /smbshare ###刷新配置
systemctl restart smb ###重启服务
查看:
[kiosk@foundation42 Desktop]$ smbclient //172.25.254.100/haha -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Sat Jun 3 14:26:16 2017
.. D 0 Sat Jun 3 14:26:02 2017
lalala N 0 Sat Jun 3 14:26:16 2017
10473900 blocks of size 1024. 7305796 blocks available
2)当共享目录为系统建立目录时:
vim /etc/samba/smb.conf
[westos]
comment = local directory
path = /mnt
[root@localhost ~]# setsebool -P samba_export_all_ro on ##只读共享
//[root@localhost ~]# setsebool -P samba_export_all_rw on ##读写共享
[root@localhost ~]# touch /mnt/file{1..8}
[root@localhost ~]# systemctl restart smb
查看共享:
[kiosk@foundation42 Desktop]$ smbclient //172.25.254.100/haha -U student
Enter student's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: \> ls
. D 0 Sat Jun 3 14:35:40 2017
.. D 0 Sat Jun 3 14:26:02 2017
file1 N 0 Sat Jun 3 14:35:40 2017
file2 N 0 Sat Jun 3 14:35:40 2017
file3 N 0 Sat Jun 3 14:35:40 2017
file4 N 0 Sat Jun 3 14:35:40 2017
file5 N 0 Sat Jun 3 14:35:40 2017
file6 N 0 Sat Jun 3 14:35:40 2017
file7 N 0 Sat Jun 3 14:35:40 2017
file8 N 0 Sat Jun 3 14:35:40 2017
5.samba的配置参数
匿名用户访问
[root@localhost ~]# vim /etc/samba/smb.conf
guset ok = yes ##允许匿名用户访问
map to guset = bad user ##指定匿名用户
访问控制
hosts allow = ##仅允许
hosts deny = 172.25.254.59 ##仅拒绝59主机
valid users = ##当前共享的有效用户
valid users = westos 当前共享的有效用户为westos
测试:
[root@foundation59 ~]# smbclient //172.25.254.100/haha -U westos
Enter westos’s password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
smb: > q ##westos用户可以访问
[root@foundation59 ~]# smbclient //172.25.254.100/haha -U student
Enter student’s password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
tree connect failed: NT_STATUS_ACCESS_DENIED ##student用户被拒绝
valid users = @westos 当前共享的有效用户为westos组
valid users = +westos 当前共享的有效用户为westos组
读写控制
*所有用户均可写
[root@localhost ~]# setsebool -P samba_export_all_rw on
[root@localhost ~]# chmod o+w /mnt
[root@localhost ~]# vim /etc/samba/smb.conf
writable = yes
[root@localhost ~]# systemctl restart smb
测试:
[root@foundation42 Desktop]# mount -o username=westos,password=lee //172.25.254.142/westos /mnt/
[root@foundation42 Desktop]# cd /mnt/
[root@foundation42 mnt]# ls
file1 file2 file3 file4 file5 file6 file7 file8
[root@foundation42 mnt]# touch file10
*设定指定用户可写
[root@localhost ~]# vim /etc/samba/smb.conf
writable = no
write list = student ##可写用户
write list = +student ##可写用户组
write list = @student
测试:
[root@foundation42 ~]# umount /mnt/
[root@foundation42 ~]# mount -o username=student,password=lee //172.25.254.142/westos /mnt/
[root@foundation42 ~]# cd /mnt/
[root@foundation42 mnt]# ls
file file1 file2 file3 file4 file5 file6 file7 file8 filee
[root@foundation42 mnt]# touch filw
[root@localhost ~]# vim /etc/samba/smb.conf
writable = yes
admin users = westos ###共享的超级用户指定为westos
[root@localhost ~]# systemctl restart smb
[root@localhost ~]# chmod o-w /mnt
测试:
[root@foundation42 ~]# mount -o username=westos,password=lee //172.25.254.142/westos /mnt/
[root@foundation42 ~]# cd /mnt/
[root@foundation42 mnt]# ls
file1 file2 file3 file4 file5 file6 file7 file8 filee
[root@foundation42 mnt]# touch file
[root@foundation42 mnt]# ls
file file1 file2 file3 file4 file5 file6 file7 file8 filee
6.smb多用户挂载
在client上
vim /root/haha ###编辑smb用户文件
username=student
password=lee
chmod 600 /root/haha ###只对root可写
yum install cifs-utils -y
mount -o credentials=/root/haha,mutiluser,sec=ntlmssp //172.25.254.100/westos /mnt/
#credentials=/root/haha ###指定挂载时所用到的用户文件
#mutiluser ###支持多用户认证
#sec=ntlmssp ###认证方式为标准smb认证方式
测试:
su - kiosk ###切换用户
ls /mnt
ls: cannot access /mnt: Permission denied ###因为没有做smb的认证所以无法访问smb共享
cifscreds add -u westos 172.25.254.100 ###smb用户认证
Password: ###smb用户westos的密码
ls /mnt
- Samba
- Samba
- Samba
- samba
- Samba
- SAMBA
- samba
- samba
- samba
- samba
- samba
- samba
- samba
- samba
- samba
- samba
- SAMBA
- samba
- go语言之结构体数组转为string字符串
- ffmpeg解码实时流出错"non-existing PPS 0 referenced,decode_slice_header error,no frame!"
- 行业软件运行时报MDAC故障的问题解决办法
- SimpleAdapter的学习理解
- MFC基于单文档分割窗口
- samba
- linux环境下(ubuntu)搜狗输入法出错了
- 2017.06.05回顾 dataframe找到喊缺失值的column list组成dataframe
- 欢迎使用CSDN-markdown编辑器
- 表单校验
- mysql 左连接 右连接
- Ubuntu 16.04上安装mysql详细教程
- 日志中如何输出完整的堆栈异常
- firewalld