Hotline: 094.320.0088

Thiết Lập Samba Server

Để chia sẽ dữ liệu giữa máy Linux và các hệ điều hành khác một trong các cách là ta sử dụng Samba Server. Loại server này sử dụng giao thức SMB sử dụng TCP/445 để hoạt động. Bài viết bên dưới bao gồm các phần

+ Thiết lập chia sẻ dữ liệu không bảo mật

+ Thiết lập chia sẻ dữ liệu phân quyền

Các bạn tham khảo video bên dưới kết hợp với bài viết để thực hành

 

1. Thiết lập chia sẻ dữ liệu Full Quyền

– Cài đặt Samba Server và tạo thư mục để chia sẻ dữ liệu

[root@samba ~]# dnf -y install samba

[root@samba ~]# mkdir /data-share

[root@samba ~]# chmod 777 /data-share

– Thiết lập cấu hình cơ bản cho Samba Server và thiết lập cấu hình cho thư mục cần chia sẻ

[root@localhost ~]# vi /etc/samba/smb.conf

[global]

unix charset = UTF-8

workgroup = WORKGROUP

security = user

hosts allow = 192.168.1. 172.16.

passdb backend = tdbsam

printing = cups

printcap name = cups

load printers = yes

cups options = raw

map to guest = Bad User

[Share]

#xac dinh thu muc chia se

path = /data-share

# cho phep ghi du lieu

writable = yes

#Cho phep tat ca tai khoan truy cap vao (nobody)

guest ok = yes

# File tao ra co quyen 777

force create mode = 777

# Thu muc tao ra quyen 777

force directory mode = 777

#File va thu muc tao ra se co user owner va group owner

force user = localuser

force group = localuser

 

2. Thiết lập chia sẻ dữ liệu phân quyền

– Kích hoạt tính năng ACL cho partition nếu đang dùng dạng format là ext4. Nếu máy chủ đang dùng dạng format là xfs thì tính năng ACL mặc định được kích hoạt

[root@centos1 share]# vi /etc/fstab

=> kích hoạt tính năng ACL ở trên phân vùng

[root@server ~]# mount -o remount /

– Tạo ra folder “/data/share” và sử dụng ACL để phân quyền

[root@centos1 share]# mkdir /share

[root@centos1 share]# groupadd student

[root@centos1 share]# groupadd teacher

[root@centos1 share]# useradd -g student user1

[root@centos1 share]# useradd -g student user2

[root@centos1 share]# useradd -g teacher gv1

[root@centos1 share]# useradd -g teacher gv2

– Tạo thư mục /share và phân quyền

[root@vmware data]# cd /

[root@vmware share]# chmod 750 /share

=> như vậy OTHER sẽ không có quyền trên folder share

[root@vmware data]# setfacl -m g:student:r-x /share

[root@vmware data]# setfacl -m g:teacher:rwx /share

=> sử dụng ACL để phân quyền cho từng loại group khác nhau

 

[root@vmware data]# getfacl share/

# file: share/

# owner: root

# group: root

user::rwx

group::r-x

group:student:rwx

group:teacher:rwx

mask::rwx

other::r-x

– Thiết lập mật khẩu để kết nối chia sẻ dữ liệu thông qua Samba

[root@localhost ~]# smbpasswd -a gv1

New SMB password: 123456

Retype new SMB password: 123456

Added user gv1.

[root@localhost ~]# smbpasswd -a gv2

New SMB password: 654321

Retype new SMB password: 654321

Added user gv2.

[root@localhost ~]# smbpasswd -a user1

New SMB password: 123456

Retype new SMB password: 123456

Added user user1.

[root@localhost ~]# smbpasswd -a user2

New SMB password: 654321

Retype new SMB password: 654321

Added user user2.

– Thiết lập cấu hình cho Samba Server

[root@samba ~]# vi /etc/samba/smb.conf

[global]

unix charset = UTF-8

workgroup = WORKGROUP

security = user

hosts allow = 192.168.1. 172.16.

passdb backend = tdbsam

printing = cups

printcap name = cups

load printers = yes

cups options = raw

map to guest = Bad User

#guest account = localuser

[Data]

#xac dinh thu muc chia se

path = /share

#Cho phep ghi du lieu

writable = yes

#Khong cho phep tat ca tai khoan truy cap vao (nobody)

guest ok = no

#valid users xac dinh group nao duoc ket noi vao share

valid users = @teacher @student

#set permission [777] when file created

force create mode = 777

# set permission [777] when folder created

force directory mode = 777

# inherit permissions from parent folder

# inherit permissions = yes