linux7 samba,RHEL7: Samba文件共享

Samba - Server 配置

1. 安装所需软件

[root@s1 ~]# yum install samba -y

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

[root@s1 ~]# yum install policycoreutils-python

2. 创建共享目录

[root@s1 ~]# mkdir /sharedpath

[root@s1 ~]# semanage fcontext -a -t samba_share_t '/sharedpath(/.*)?'

[root@s1 ~]# restorecon -vvFR /sharedpath/

restorecon reset /sharedpath context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0

3. 修改配置文件/etc/samba/smb.conf, 加上一行。

[myshare]

path = /sharedpath

4. 添加用户

[root@s1 ~]# useradd -s /sbin/nologin fred

[root@s1 ~]# smbpasswd -a fred

5. 启用Samba服务

[root@s1 ~]# systemctl start smb nmb

[root@s1 ~]# systemctl enable smb nmb

6. 添加防火墙规则

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

[root@s1 ~]# firewall-cmd --reload

Samba - Client 配置

1. 安装所需软件

[root@r7-h1 ~]# yum install cifs-utils -y

2.创建挂载点

[root@r7-h1 ~]# mkdir /mnt/myshare

3.以fred身份挂载

[root@r7-h1 ~]# mount -o username=fred //192.168.122.243/myshare /mnt/myshare/

Password for fred@//192.168.122.243/myshare: ******

Multiuser

Server端

[root@s1 ~]# groupadd -r marketing

[root@s1 ~]# mkdir -p /smbshare

[root@s1 ~]# chgrp marketing /smbshare/

[root@s1 ~]# chmod 2775 /smbshare/

[root@s1 ~]# semanage fcontext -a -t samba_share_t '/smbshare(/.*)?'

[root@s1 ~]# restorecon -vvFR /smbshare/

在/etc/samba/smb.conf加上几行

[smbshare]

path = /smbshare

write list = @marketing

[root@s1 ~]# useradd -s /sbin/nologin -G marketing brian

[root@s1 ~]# smbpasswd -a brian

[root@s1 ~]# useradd -s /sbin/nologin rob

[root@s1 ~]# smbpasswd -a rob

Client

1. 创建用户

[root@r7-h1 ~]# useradd brian

2. 创建挂载点

[root@r7-h1 ~]# mkdir /mnt/multiuser/

3. 自动挂载配置

[root@r7-h1 ~]# echo 'username=brian' > /root/smb-multiuser.txt

[root@r7-h1 ~]# echo 'password=redhat' >> /root/smb-multiuser.txt

在/etc/fstab加上一行

//192.168.122.243/smbshare /mnt/multiuser cifs credentials=/root/smb-multiuser.txt,multiuser,sec=ntlmssp 0 0

4. 挂载

[root@r7-h1 ~]# mount /mnt/multiuser/

5. 切换用户,尝试创建文件。

[root@r7-h1 ~]# su - brian

[brian@r7-h1 ~]$ cifscreds add 192.168.122.243

[brian@r7-h1 ~]$ echo "Multiuser" > /mnt/multiuser/brian2.txt

[brian@r7-h1 ~]$ cat /mnt/multiuser/brian2.txt

Multiuser

[root@r7-h1 ~]# useradd rob

[root@r7-h1 ~]# su - rob

[rob@r7-h1 ~]$ cifscreds add 192.168.122.243

[rob@r7-h1 ~]$ echo "Multiuser" > /mnt/multiuser/rob2.txt

-bash: /mnt/multiuser/rob2.txt: Permission denied

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值