Cách cài đặt và cấu hình Samba trên CentOS

Samba là gì?

Samba là một phần mềm miễn phí chủ yếu dùng để chia sẻ file giữa các nền tảng khác nhau như WindowsLinux bằng cách sử dụng giao thức SMB/CIFS.

Cách cài đặt và cấu hình Samba trên CentOS - CentOS Linux samba windows - Webmasters Tools Phát triển website
Samba Logo

Cách cài đặt Samba trên CentOS

Sau đây chúng ta sẽ sử dụng YUM để cài đặt Samba

Bước 1Cài đặt các YUM Repositories cho CentOS theo hướng dẫn tại bài này

Bước 2 : Cài đặt Samba bằng YUM trên CentOS

yum install -y samba

Cách cấu hình Samba trên CentOS

Bước 3 : Thêm user trên CentOS

useradd pepvn_samba -s /sbin/nologin

pepvn_samba là username bạn muốn tạo, bạn có thể thay bằng bất cứ username nào bạn muốn

Bước 4 : Tạo password cho user pepvn_samba

smbpasswd -a pepvn_samba

Ví dụ :

[root@xtraffic ~]# smbpasswd -a pepvn_samba
New SMB password:
Retype new SMB password:
Added user pepvn_samba.
[root@xtraffic ~]#

Bước 5 : Tạo thư mục có tên là share_samba tại thư mục root

mkdir -p /share_samba

Thay đổi quyền sở hữu cho thư mục share_samba

chown -R pepvn_samba:root /share_samba/

Thư mục share_samba là thư mục bạn dùng để chia sẻ cho user pepvn_samba

Bước 6 : Cấu hình “/etc/samba/smb.conf

Bạn mở file “/etc/samba/smb.conf” và thêm các dòng sau vào cuối file :

[pepvn_samba]
comment = This is description
path = /share_samba
writable = yes
valid users = pepvn_samba

Bước 7 : Khởi động Samba service

service smb start

Tự khởi động Samba service mỗi khi VPS/Server khởi động

chkconfig --levels 235 smb on

Bước 8 : Test cấu hình Samba

Kiểm tra cấu hình Samba bằng lệnh sau :

testparm

Ví dụ :

[root@xtraffic ~]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[pepvn_samba]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

[global]
        workgroup = MYGROUP
        server string = Samba Server Version %v
        log file = /var/log/samba/log.%m
        max log size = 50
        idmap config * : backend = tdb
        cups options = raw

[homes]
        comment = Home Directories
        read only = No
        browseable = No

[printers]
        comment = All Printers
        path = /var/spool/samba
        printable = Yes
        print ok = Yes
        browseable = No

[pepvn_samba]
        comment = This is Pep Share Folder
        path = /share_samba
        valid users = pepvn_samba
        read only = No
[root@xtraffic ~]#

Vậy là xong, bây giờ bạn mở run prompt của Windows lên bằng cách nhấn phím “Window + R” và gõ vào dòng sau “\\your-vps-ipaddress\“, sau đó nhập vào username (ở ví dụ này là pepvn_samba) & password của username đó để sử dụng.

Đây là cách rất hay giúp bạn code ngay trên máy tính windows của bạn và những thay đổi mã nguồn của bạn sẽ lập tức lưu trên VPS/Server sử dụng Samba khi bạn nhấn lưu file.

Leave a Comment