<?xml version="1.0" encoding="UTF-8" ?><!-- generator=Zoho Sites --><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><atom:link href="https://www.daihockhonggiay.com/blogs/tag/dich-vu-ftp/feed" rel="self" type="application/rss+xml"/><title>Đại học Không Giấy - Blog #dịch vụ FTP</title><description>Đại học Không Giấy - Blog #dịch vụ FTP</description><link>https://www.daihockhonggiay.com/blogs/tag/dich-vu-ftp</link><lastBuildDate>Wed, 10 Sep 2025 18:45:31 -0700</lastBuildDate><generator>http://zoho.com/sites/</generator><item><title><![CDATA[Cài đặt dịch vụ FTP và Cisco Discovery Protocol]]></title><link>https://www.daihockhonggiay.com/blogs/post/cai-dat-va-cau-hinh-dich-vu-ftp</link><description><![CDATA[<img align="left" hspace="5" src="https://www.daihockhonggiay.com/files/trunganh/37.jpg"/>Bài viết này sẽ hướng dẫn các bạn cài đặt và cấu hình dịch vụ FTP Cisco Discovery Protocol]]></description><content:encoded><![CDATA[<div class="zpcontent-container blogpost-container "><div data-element-id="elm_3KTDYUf6QFeOkbZASjvzxQ" data-element-type="section" class="zpsection "><style type="text/css"></style><div class="zpcontainer-fluid zpcontainer"><div data-element-id="elm_58d0huvwTzGI4pUrby5drw" data-element-type="row" class="zprow zprow-container zpalign-items- zpjustify-content- " data-equal-column=""><style type="text/css"></style><div data-element-id="elm_VEJj9RzdTVOFRCYUH8BfFw" data-element-type="column" class="zpelem-col zpcol-12 zpcol-md-12 zpcol-sm-12 zpalign-self- "><style type="text/css"></style><div data-element-id="elm_zaN6Ck0cR3uQygwGzXmfdQ" data-element-type="text" class="zpelement zpelem-text "><style> [data-element-id="elm_zaN6Ck0cR3uQygwGzXmfdQ"].zpelem-text { border-style:none; } </style><div class="zptext zptext-align-left " data-editor="true"><p style="margin-bottom:20px;"><span style="font-size:14px;"><span style="font-weight:700;">1.Chuẩn bị thiết bị:</span></span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Một máy chủ Linux CentOS 7 và cài đặt FTP Server.</span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Một máy Windows đã cài đặt SecureCRT.</span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Một Switch kết nối Server Linux và PC.</span></p><p style="margin-bottom:20px;"><span style="font-size:14px;"><span style="font-weight:700;">2.Yêu cầu nội dung:</span></span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Kết nối thiết bị theo mô hình.</span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Đặt địa chỉ IP trên Server.</span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Sử dụng SecureCRT kết nối để thực hiện các nhiệm vụ cơ bản sau:</span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Cài đặt dịch vụ vsftpd trên máy chủ Linux.</span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Cài đặt và cấu hình thêm dịch vụ phân giải tên miền (nếu cần).</span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Tạo thư mục cho việc truy cập tài nguyên trên FTP Server.</span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Tạo User cho việc chứng thực truy cập.</span></p><p style="margin-bottom:20px;"><span style="font-size:14px;">Giới hạn truy cập vào FTP Server cho mỗi User.</span></p><p><b><span style="font-size:14px;">Phần I. Cài đặt dịch vụ FTP Server</span></b></p><p><span style="font-size:14px;">B1: Mount DVD vào thư mục media và sửa file yum, gán alias</span></p><p style="margin-left:27pt;"><span style="font-size:14px;">[root@anln ~]# mount /dev/cdrom /media/</span></p><p style="margin-left:27pt;"><span style="font-size:14px;">[root@anln ~]# vi /etc/yum.repos.d/CentOS-Media.repo</span></p><p style="margin-left:27pt;"><span style="font-size:14px;">[root@anln ~]# vi .bashrc</span></p><p><span style="font-size:14px;">B2: Cài đặt FTP Server từ DVD</span></p><p style="margin-left:27pt;"><span style="font-size:14px;">yum install vsftpd -y</span></p><p><span style="font-size:14px;">B3: gán quyền truy cập cho người dùng vào thư mục</span></p><p style="margin-left:27pt;"><span style="font-size:14px;">setsebool -P ftp_home_dir=&quot;1</span></p><p><span style="font-size:14px;">B4: Tao tạo user: </span></p><p style="margin-left:27pt;"><span style="font-size:14px;">useradd anln</span></p><p style="margin-left:27pt;"><span style="font-size:14px;">passwd anln</span></p><p><span style="font-size:14px;">B5: khởi động dịch vụ ftp và cho phép khởi động cùng hệ thống</span></p><p style="margin-left:27pt;"><span style="font-size:14px;">systemctl start vsftpd </span></p><p style="margin-left:27pt;"><span style="font-size:14px;">systemctl enable vsftpd</span></p><p><span style="font-size:14px;">B6: Bật firewalld </span></p><p style="text-indent:36pt;"><span style="font-size:14px;">firewall-cmd --permanent --zone=public --add-port=20-21/tcp </span></p><p style="text-indent:36pt;"><span style="font-size:14px;">firewall-cmd --permanent --zone=public --add-port=50000-50999/tcp</span></p><p style="text-indent:36pt;"><span style="font-size:14px;">firewall-cmd --reload</span></p><p style="text-indent:36pt;"><span style="font-size:14px;">firewall-cmd --list-all</span></p><p><span style="font-size:14px;">B7: Cấu hình Passive mode</span></p><p><span style="font-size:14px;">[root@anln ~]# vi /etc/vsftpd/vsftpd.conf</span></p><p style="text-indent:36pt;"><span style="font-size:14px;">pasv_enable=YES</span></p><p style="text-indent:36pt;"><span style="font-size:14px;">pasv_min_port=50000</span></p><p style="text-indent:36pt;"><span style="font-size:14px;">pasv_max_port=50999</span></p><p style="text-indent:36pt;"><span style="font-size:14px;">port_enable=YES</span></p><p><span style="font-size:14px;">B8. Khởi động lại dịch vụ FTP</span></p><p style="text-indent:36pt;"><span style="font-size:14px;">systemctl restart vsftpd</span></p><p><span style="font-size:14px;">B9: Đổi thư mục cho người dùng</span></p><p style="text-indent:36pt;"><span style="font-size:14px;">mkdir&nbsp; /Data</span></p><p style="text-indent:36pt;"><span style="font-size:14px;">useradd -d /Data/Data1 jenln</span></p><p style="text-indent:36pt;"><span style="font-size:14px;">passwd jenln</span></p><p><span style="font-size:14px;">B10: Dùng File zilla client kiểm tra sau khi cấu hình</span></p><p><b><span style="font-size:14px;">Chú ý: </span></b></p><p><span style="font-size:14px;">- Khi dùng FTP ở port 21 sẽ không vào được các thư mục khác ngoài thư mục Home và dữ liệu không được bảo mật.</span></p><p><span style="font-size:14px;">- Nên dùng giao thức SFTP chạy ở Port 22 bằng SSH để bảo mật và vào được mọi thư mục theo yêu cầu </span></p><p style="text-align:center;"><img src="/files/luu%20moc/2%20chuan.JPG" style="width:582.44px;height:469px;"><span style="font-size:14px;"><br></span></p><p></p><p><span style="font-size:14px;">- Nếu truy cập dịch vụ FTP dùng SFTP truy cập vào máy chủ: 118.70.119.44 ta dùng port 202 đã được NAT</span></p><p><span style="font-size:14px;">Username: vt, password: 123456a@</span></p><p></p><p style="text-align:center;"><b><span style="font-size:14px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;</span></b><img src="/files/luu%20moc/1%20chu%E1%BA%A9n.JPG" style="width:621.28px;height:206px;"></p><p><b><span style="font-size:14px;">II. CẤU HÌNH FTP VIRTUAL USER</span></b></p><p style="text-align:justify;"><b><span style="font-size:14px;">1. Cài đặt dịch vụ FTP Server</span></b></p><p style="text-align:justify;"><span style="font-size:14px;">B1: Cài đặt dịch vụ FTP Server</span></p><p style="text-align:justify;"><span style="font-size:14px;">yum install vsftpd -y</span></p><p style="text-align:justify;"><span style="font-size:14px;">B2: Nếu bật Selinux thì ta cần phải gán quyền truy cập cho thư mục mới của người dùng </span></p><p style="text-align:justify;"><span style="font-size:14px;">setsebool -P allow_ftpd_full_access on</span></p><p style="text-align:justify;"><span style="font-size:14px;">B3: Bật dịch vụ</span></p><p style="text-align:justify;"><span style="font-size:14px;">systemctl start vsftpd</span></p><p style="text-align:justify;"><span style="font-size:14px;">systemctl enable vsftpd</span></p><p style="text-align:justify;"><span style="font-size:14px;">B4. Cài đặt dịch vụ Berkeley DB</span></p><p style="text-align:justify;"><span style="font-size:14px;">yum install -y db-util</span></p><p style="text-align:justify;"><span style="font-size:14px;">B5. Kiểm tra quá trình cài đặt</span></p><p style="text-align:justify;"><span style="font-size:14px;">db_load -V</span></p><p style="text-align:justify;"><i><span style="font-size:14px;">Kết quả như này là được</span></i></p><p style="text-align:justify;"><span style="font-size:14px;">#db_load -V</span></p><p style="text-align:justify;"><b><span style="font-size:14px;">2. Cấu hình Virtual User trên VSFTPD</span></b></p><p style="text-align:justify;"><b><span style="font-size:14px;">a. Cấu hình trong File Vsftpd.conf</span></b></p><p style="text-align:justify;"><span style="font-size:14px;">vi /etc/vsftpd/vsftpd.conf</span></p><p style="text-align:justify;"><b><span style="font-size:14px;">Sửa các thông số cấu hình như bên dưới.</span></b></p><p style="text-align:justify;"><span style="font-size:14px;">anonymous_enable=NO</span></p><p style="text-align:justify;"><span style="font-size:14px;">write_enable=NO</span></p><p style="text-align:justify;"><span style="font-size:14px;">chroot_local_user=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">allow_writeable_chroot=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">##########Phần cấu hình cho Virtual User##########</span></p><p style="text-align:justify;"><span style="font-size:14px;">userlist_enable=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">userlist_file=/etc/vsftpd/user_list_deny</span></p><p style="text-align:justify;"><span style="font-size:14px;">guest_enable=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">guest_username=ftp</span></p><p style="text-align:justify;"><span style="font-size:14px;">user_config_dir=/etc/vsftpd/vuser_conf</span></p><p style="text-align:justify;"><span style="font-size:14px;">user_sub_token=$USER</span></p><p style="text-align:justify;"><span style="font-size:14px;">pam_service_name=vuser_vsftpd</span></p><p style="text-align:justify;"><span style="font-size:14px;">local_root=/var/ftp/$USER</span></p><p style="text-align:justify;"><b><span style="font-size:14px;">#Cau hinh Passive mode</span></b></p><p style="text-align:justify;"><span style="font-size:14px;">pasv_enable=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">pasv_min_port=50000</span></p><p style="text-align:justify;"><span style="font-size:14px;">pasv_max_port=50999</span></p><p style="text-align:justify;"><span style="font-size:14px;">port_enable=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">###########END###########</span></p><p style="text-align:justify;"><span style="font-size:14px;">Chú ý: thếm dâu # trước pam_service_name=&quot;vsftpd</span></p><p style="text-align:justify;"><b><span style="font-size:14px;">b. Tạo file cấu hình virtual user riêng</span></b></p><p style="text-align:justify;"><span style="font-size:14px;">B1: Tạo folder chứa Virtual User</span></p><p style="text-align:justify;"><span style="font-size:14px;">mkdir /etc/vsftpd/vuser_conf</span></p><p style="text-align:justify;"><span style="font-size:14px;">Trong bài mình sẽ tạo hai user ảo là&nbsp;<b>vuser1</b>&nbsp;và&nbsp;<b>vuser2</b></span></p><p style="text-align:justify;"><span style="font-size:14px;"><span style="font-weight:bold;">B2: Sưa file cấu hình riêng cho vuser1</span>.</span></p><p style="text-align:justify;"><span style="font-size:14px;">vi /etc/vsftpd/vuser_conf/vuser1</span></p><p style="text-align:justify;"><b><span style="font-size:14px;">Thêm nội dung như sau:</span></b></p><p style="text-align:justify;"><span style="font-size:14px;">write_enable=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">anon_world_readable_only=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">anon_upload_enable=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">anon_mkdir_write_enable=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">anon_other_write_enable=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">virtual_use_local_privs=YES</span></p><p style="text-align:justify;"><span style="font-size:14px;">B3:Copy sang cho vuser2</span></p><p style="text-align:justify;"><span style="font-size:14px;">cp /etc/vsftpd/vuser_conf/vuser1 /etc/vsftpd/vuser_conf/vuser2</span></p><p style="text-align:justify;"><b><span style="font-size:14px;">c. Tạo Virtual user Database</span></b></p><p style="text-align:justify;"><span style="font-size:14px;">B1: Tạo file chứa user:</span></p><p style="text-align:justify;"><span style="font-size:14px;">vi /etc/vsftpd/vuser_list</span></p><p style="text-align:justify;"><span style="font-size:14px;">Nội dung như sau, với username một dòng và password một dòng:</span></p><p style="text-align:justify;"><span style="font-size:14px;">vuser1</span></p><p style="text-align:justify;"><span style="font-size:14px;">123456a@</span></p><p style="text-align:justify;"><span style="font-size:14px;">vuser2</span></p><p style="text-align:justify;"><span style="font-size:14px;">123456a@</span></p><p style="text-align:justify;"><span style="font-size:14px;">B2: Tiếp theo import vuser_list vào Berkeley DB</span></p><p style="text-align:justify;"><span style="font-size:14px;">db_load -T -t hash -f /etc/vsftpd/vuser_list /etc/vsftpd/vuser_list.db</span></p><p style="text-align:justify;"><span style="font-size:14px;">B3: Gán quyền read và execute.</span></p><p style="text-align:justify;"><span style="font-size:14px;">chmod 600 /etc/vsftpd/vuser_list.db</span></p><p style="text-align:justify;"><span style="font-size:14px;">Sau đó bạn có thể xóa file vuser_list nếu muốn,&nbsp;rm -f vuser_list</span></p><p style="text-align:justify;"><b><span style="font-size:14px;">d. Cấu hình PAM</span></b></p><p style="text-align:justify;"><span style="font-size:14px;">Nếu không dùng file PAM mặc định mà tạo file riêng để xác thực cho Virtual User. File sẽ có tên là&nbsp;vuser_vsftpd.</span></p><p style="text-align:justify;"><span style="font-size:14px;">vi /etc/pam.d/vuser_vsftpd</span></p><p style="text-align:justify;"><span style="font-size:14px;">Nội dung file:</span></p><p style="text-align:justify;"><span style="font-size:14px;">auth required pam_userdb.so db=&quot;/etc/vsftpd/vuser_list</span></p><p style="text-align:justify;"><span style="font-size:14px;">account required pam_userdb.so db=&quot;/etc/vsftpd/vuser_list</span></p><p style="text-align:justify;"><span style="font-size:14px;">session required pam_loginuid.so</span></p><p style="text-align:justify;"><b><span style="font-size:14px;">e. Cấu hình Home Directory cho Virtual User</span></b></p><p style="text-align:justify;"><span style="font-size:14px;">B1: Sửa file passwd </span></p><p style="text-align:justify;"><span style="font-size:14px;">vi /etc/passwd</span></p><p style="text-align:justify;"><span style="font-size:14px;">Sửa /var/ftp thành</span></p><p style="text-align:justify;"><span style="font-size:14px;">/var/ftp/$USER</span></p><p style="text-align:center;"><img src="/files/luu%20moc/3-2.png"><span style="font-size:14px;"><br></span></p><p style="text-align:justify;"><span style="font-size:14px;"><a href="https://www.thuysys.com/wp-content/uploads/edit-passwd-file.png"></a></span></p><p style="text-align:justify;"><span style="font-size:14px;">B2: Tạo Home Directory cho Virtual User</span></p><p style="text-align:justify;"><span style="font-size:14px;">mkdir /var/ftp/vuser1</span></p><p style="text-align:justify;"><span style="font-size:14px;">mkdir /var/ftp/vuser2</span></p><p style="text-align:justify;"><span style="font-size:14px;"><a href="https://www.thuysys.com/domain-hosting/wordpress-co-ban/tim-hieu-chmod-chown-cach-sua-loi-phan-quyen-wordpress-tren-linux.html">Chown</a>, toàn bộ dữ liệu trong&nbsp;/var/ftp&nbsp;thuộc sở hữu của tài khoản ftp</span></p><p style="text-align:justify;"><span style="font-size:14px;">chown -R ftp:ftp /var/ftp/*</span></p><p style="text-align:justify;"><span style="font-size:14px;">B3: Tạo file user_listdy_deny</span></p><p style="text-align:justify;"><span style="font-size:14px;">vi /etc/vsftpd/user_list_deny</span></p><p style="text-align:justify;"><span style="font-size:14px;">Thêm user muốn deny vào (ví dụ vuser1)</span></p><p style="text-align:justify;"><span style="font-size:14px;">vuser1</span></p><p style="text-align:justify;"><span style="font-size:14px;">B4: Mở Firewall</span></p><p style="text-align:justify;"><span style="font-size:14px;">firewall-cmd --permanent --zone=public --add-port=20-21/tcp&nbsp; </span></p><p style="text-align:justify;"><span style="font-size:14px;">firewall-cmd --permanent --zone=public --add-port=50000-50999/tcp</span></p><p style="text-align:justify;"><span style="font-size:14px;">firewall-cmd --reload</span></p><p style="text-align:justify;"><span style="font-size:14px;">firewall-cmd --list-all</span></p><p style="text-align:justify;"><b><span style="font-size:14px;">B5: Khợi động lại dịch vụ </span></b></p><p style="text-align:justify;"><span style="font-size:14px;">systemctl restart vsftpd</span></p><p style="text-align:justify;"><b><span style="font-size:14px;">6. Kiểm tra hoạt động FTP Server</span></b></p><p style="text-align:justify;"><span style="font-size:14px;">Deny vuser1 bằng cách thêm nó vào&nbsp;<b>user_listdy_deny</b>&nbsp;như đã cấu hình ở trên. Còn vuser2 vẫn cho truy cập upload/delete/rename bình thường.</span></p><p style="text-align:justify;"><span style="font-size:14px;">&nbsp;Kết quả khi dùng FileZilla đăng nhập vào FTP Server trên VPS -&gt; vuser1 đã bị chặn truy cập</span></p><p style="text-align:center;"><img src="/files/luu%20moc/4-2.png" style="width:528.52px;height:306px;"><span style="font-size:14px;"><br></span></p><p></p><p style="text-align:justify;"><span style="font-size:14px;">vuser1</span></p><p style="text-align:justify;"><span style="font-size:14px;">vuser2 đăng nhập bình thường và có thể upload file.</span></p><p style="text-align:center;"><img src="/files/luu%20moc/5-3.png" style="width:539.99px;height:305px;"><span style="font-size:14px;"><br></span></p><p></p><p style="text-align:justify;"><span style="font-size:14px;">vuser2</span></p><p style="margin-bottom:20px;"><span style="color:inherit;font-size:14px;"></span></p><p style="text-align:justify;"><span style="font-size:14px;">Tất cả đã hoạt động ok, bạn thử tạo thêm nhiều user ảo khác và check rename, delete, create folder xem sao.</span></p><p><span style="color:inherit;font-size:14px;"></span></p><p style="margin-bottom:20px;"><span style="font-weight:700;font-size:14px;">4.Video hướng dẫn:</span></p></div>
</div></div></div></div></div><div data-element-id="elm_XdUt4LuhPCIRunklUoiNEg" data-element-type="section" class="zpsection zpdefault-section zpdefault-section-bg "><style type="text/css"> [data-element-id="elm_XdUt4LuhPCIRunklUoiNEg"].zpsection{ border-style:none; } </style><div class="zpcontainer-fluid zpcontainer"><div data-element-id="elm_NTJLNTwCrht-ZTnU1MU2Ew" data-element-type="row" class="zprow zprow-container zpalign-items-flex-start zpjustify-content-flex-start zpdefault-section zpdefault-section-bg " data-equal-column=""><style type="text/css"> [data-element-id="elm_NTJLNTwCrht-ZTnU1MU2Ew"].zprow{ border-style:none; box-shadow:0px 0px 0px 0px #000000; } </style><div data-element-id="elm_HINIdJeSA1X5nNDinz2vQQ" data-element-type="column" class="zpelem-col zpcol-12 zpcol-md-12 zpcol-sm-12 zpalign-self- zpdefault-section zpdefault-section-bg "><style type="text/css"> [data-element-id="elm_HINIdJeSA1X5nNDinz2vQQ"].zpelem-col{ border-style:none; box-shadow:0px 0px 0px 0px #000000; } </style><div data-element-id="elm_L93Ng8jFUdhsrzCBN9M0Og" data-element-type="iframe" class="zpelement zpelem-iframe "><style type="text/css"> [data-element-id="elm_L93Ng8jFUdhsrzCBN9M0Og"].zpelem-iframe{ border-style:none; border-radius:1px; box-shadow:0px 0px 0px 0px #000000; } </style><div class="zpiframe-container zpiframe-align-center"><iframe class="zpiframe " src="https://www.youtube.com/embed/BeZUc4DO2bQ" width="560" height="315" align="center" allowfullscreen frameBorder="0"></iframe></div>
</div></div></div></div></div></div> ]]></content:encoded><pubDate>Fri, 03 May 2019 01:26:23 +0700</pubDate></item></channel></rss>