ubuntu 20.04安装samba服务器

1.安装服务

sudo apt update
sudo apt install samba samba-common-bin

2.添加samba用户以及设置群组

A.samba用户必须先是ubuntu的用户,因此先添加ubuntu用户。如果只是给其配置samba,不给其设置用户目录和ssh登录,则使用 useradd 命令;如果要配置用户目录和ssh登录,则使用adduser命令给其配置目录和密码。如果只是使用samba服务,建议使用useradd命令。

B.为用户添加群组group,方便整个群组设置访问权限。

C.将ubuntu用户添加到samba的用户列表中,使用smbpasswd命令,根据提示,为其设置samba密码。

##only add user
sudo useradd user_A

##add user and config path and ssh
sudo adduser user_A

##add user to group
sudo usermod -aG pd user_A

##add user to samba
sudo smbpasswd -a user_A

3.配置samba服务

samba的配置文件位于/etc/samba/smb.conf中,编辑此文件,定义共享目录和权限,如下图中配置,配置了rd目录中,整个rd的用户组和user_A有读权限,user_B,user_C,user_D有写权限。

;   path = /home/samba/profiles
;   guest ok = no
;   browseable = no
;   create mask = 0600
;   directory mask = 0700

[printers]
   comment = All Printers
   browseable = no
   path = /var/spool/samba
   printable = yes
   guest ok = no
   read only = yes
   create mask = 0700

# Windows clients look for this share name as a source of downloadable
# printer drivers
[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = no
# Uncomment to allow remote administration of Windows print drivers.
# You may need to replace 'lpadmin' with the name of the group your
# admin users are members of.
# Please note that you also need to set appropriate Unix permissions
# to the drivers directory for these users to have write rights in it
;   write list = root, @lpadmin
[rd]
   comment = RD Dept
   path = /home/samba/RD
   printable = no
   guest ok = no
   browseable = yes
   valid users = @rd,user_A
   write list = user_B, user_C, user_D

[pd]
   comment = Production Dept
   path = /home/samba/PD
   printable = no
   guest ok = no
   browseable = yes
   valid users = @pd
   write list = user_A

[fd]
   comment = Finance Dept
   path = /home/samba/FD
   printable = no
   guest ok = no
   browseable = yes
   valid users = @fd, user_B
   write list = user_A, user_C

[share]
   comment = Shared Directory
   path = /home/samba/SHARE
   printable = no
   guest ok = yes
   browseable = yes
   read only = no
   create mask = 0755
   directory mask = 0755

4.开启samba服务,以及防火墙放行samba服务

sudo systemctl start smbd
sudo systemctl enable smbd
sudo systemctl start nmbd
sudo systemctl enable nmbd
##ufw allow samba
sudo ufw allow samba
##if samba is running,use restart cmd
sudo systemctl restart smbd.service
sudo systemctl restart nmbd.service

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值