ubuntu/centos 下安装配置samba服务器

  • 前提
假设此时你有一个ubuntu , ip 为 192.168.1.4,用户 pop
还有一台windows,此时ip为 192.168.1.2
且此时 192.168.1.2192.168.1.4 在同一网段,能互相ping通

在ubuntu 22.04 下测试
  • 需求
此时你想在 windows机器下 访问(读写) ubuntu 的  /home/pop 下的文件
解决方案
本文只描述 在 linux 下建立 samba 服务器
在 windows/linux 下建立samba客户端, 来访问 samba服务器 管理的文件

当然 在 windows 下建立 samba服务器 (其实是共享邻居)
在 windows/linux 下建立 samba客户端访问   也是可以的,本篇文章不描述


两个过程其实是一样的 
服务器 在 windows 上是 共享邻居,			在linux上是samba
服务器客户端 通信协议 都是 通过 cifs
客户端 在 windows 上是 windows资源管理器,	在linux上是mount

    1. 安装samba
sudo apt-get install samba
    1. 修改密码
sudo smbpasswd -a pop , 创建密码,密码为你用户密码

此时 登录 \\192.168.1.4 , 可以登陆,但是没有任何目录
    1. 修改配置
/etc/samba/smb.conf 中 有6行如下
# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each
# user's home directory as \\server\username
;[homes]
;   comment = Home Directories
;   browseable = no
更改为如下 // 下面的配置只支持 读 ,不支持写
# Un-comment the following (and tweak the other settings below to suit)
# to enable the default home directory shares. This will share each
# user's home directory as \\server\username
[homes]
   comment = Home Directories
   browseable = no

并利用 sudo systemctl restart smbd.service 或者 sudo service smbd restart 重启samba 服务器生效
    1. windows下访问
在windows机器下
在 windows资源管理器 地址栏内输入 \\192.168.1.4 // 或 win+R打开运行,输入 \\192.168.1.4
此时会显示一个 文件夹,文件夹名为 pop

双击 pop ,提示你输入账户名和密码
账户名为pop
密码为 你修改后的秘密

进入后,可以看到 /home/pop 下的文件,只能读,不能写

  • A. 再次修改配置,增加写,删除
在 browseable = no 下一行,增加
writeable = yes

并利用 sudo systemctl restart smbd.service 或 sudo service smbd restart 重启samba 服务器生效


创建的文件和文件夹权限为 // 下面的是samba默认创建权限
-rwxr--r--
drwxr-xr-x
  • B. 再次修改配置,修改写入权限
在 writeable = yes 下一行,增加
create mode = 0664
directory mode = 0775

并利用 sudo systemctl restart smbd.service 或 sudo service smbd restart 重启samba 服务器生效

创建的文件和文件夹权限为
-rw-rw-r--
drwxrwxr-x

linux下访问
sudo mount -t cifs //192.168.1.4/pop /mnt/ -o username=pop,password=123456
如何查看有哪些samba共享
sudo apt install smbclient
smbtree
centos 7.7 实战
1. [root@localhost ~]# systemctl stop firewalld.service 
2. [root@localhost ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.


3. [root@localhost ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
# SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

[homes] 下增加
path = /home/pop
其他
[share_name]
    comment = my share directory
    path = /home/user
    writeable = yes
    browseable = yes
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值