vsftpd服務

来源:https://www.cnblogs.com/zuohaha/archive/2022/10/18/16802316.html
-Advertisement-
Play Games

vsftpd服務 ftp是互聯網中進行文件傳輸的一種協議,基於C/S模式,FTP預設有兩個工作埠(20數據傳輸,21FTP服務端就收客戶端發來的指令和) 安裝FTP服務 [root@haha-main-130 ~]# yum -y install vsftpd 配置文件位置及內容 [root@ha ...


vsftpd服務

ftp是互聯網中進行文件傳輸的一種協議,基於C/S模式,FTP預設有兩個工作埠(20數據傳輸,21FTP服務端就收客戶端發來的指令和)

安裝FTP服務

[root@haha-main-130 ~]# yum -y install vsftpd

配置文件位置及內容

[root@haha-main-130 ~]# cat /etc/vsftpd/vsftpd.conf 
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=YES

pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

主要配置項

[root@haha-main-130 ~]# cat /etc/vsftpd/vsftpd.conf | grep -vE '^$|^#'
anonymous_enable=YES #是否允許匿名登錄
local_enable=YES #是否允許本地用戶登錄
write_enable=YES #是否允許寫入
local_umask=022 #掩碼值
dirmessage_enable=YES #是否允許記錄日誌
xferlog_enable=YES #是否允許記錄日誌
connect_from_port_20=YES #允許20埠連接
xferlog_file=/var/log/xferlog #日誌記錄文件位置
xferlog_std_format=YES 
listen=YES #是否打開本地監聽
listen_ipv6=YES #ipv6監聽
pam_service_name=vsftpd #守護名稱
userlist_enable=YES #允許userlist文件內用戶登錄
tcp_wrappers=YES

vsftp匿名用戶模式

  • 任何人不需要賬號密碼登錄

配置文件

1.允許匿名用戶登錄
	anonymous_enable=YES
2.允許匿名用戶上傳文件
	anon_upload_enable=YES
3.允許匿名用戶寫入、創建文件夾
	anon_mkdir_write_enable=YES
4.允許匿名用戶修改文件名,刪除文件夾操作
	anon_other_witer_enable=YES

vsftp本地用戶模式

  • 基於linux的本地賬號密碼進行驗證,配置簡單,但是存在安全隱患

配置文件

[root@haha-main-130 ~]# cat /etc/vsftpd/vsftpd.conf | grep -Ev '^$|^#'
anonymous_enable=NO #關閉匿名用戶驗證模式
local_enable=YES
write_enable=YES
local_umask=022 #預設文件許可權
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/xferlog
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=YES
tcp_wrappers=YES	

此時/etc/vsftpd/ftpuser文件中的用戶名不允許登錄

vsftp虛擬用戶模式

  • 單獨為FTP工具創建用戶資料庫,基於口令驗證賬號密碼的信息
  1. 安裝DB工具,能夠轉化普通文件為vsftpd識別的資料庫文件
yum -y install db4 db4-utils
  1. 創建用於驗證的數據文件
[root@haha-main-130 vsftpd]# cat db.txt 
name1
111
name2
222
  1. 加密文件
[root@haha-main-130 vsftpd]# db_load -T -t hash -f /etc/vsftpd/db.txt /etc/vsftpd/db.db
[root@haha-main-130 vsftpd]# cat db.db 
a      Gߊ????
??Gߊ????e1? эh^?
       эh^222name2[root@haha-main-130 vsftpd]# 
  1. 創建虛擬用戶登錄後預設訪問的文件夾路徑,與linux中的本地用戶創建一個映射關係,防止匿名用戶登陸之後創建文件提示用戶許可權問題
# 創建一個本地用戶,指定家目錄,禁止登錄bash
[root@haha-main-130 vsftpd]# useradd -d /var/ftp/v_ftpfir -s /sbin/nologin v_user

# 修改/var/ftp/v_ftpfir目錄屬性為600
[root@haha-main-130 ftp]# chmod -Rf 755 v_ftpfir/

# 修改/etc/vsftpd/ftpuser文件,禁止v_user用戶登錄
[root@haha-main-130 vsftpd]# echo 'v_user' >> /etc/vsftpd/ftpusers

  1. 修改PAM文件/etc/pam.d/vsftpd
[root@haha-main-130 vsftpd]# cat /etc/pam.d/vsftpd 
#%PAM-1.0
session    optional     pam_keyinit.so    force revoke
auth       required	pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth       required	pam_shells.so
auth       include	password-auth
account    include	password-auth
session    required     pam_loginuid.so
session    include	password-auth

# 添加如下兩行,db之後的參數為db_load之後的文件路徑,不需要添加尾碼名
auth required pam_userdb.so db=/etc/vsftpd/db
account required pam_userdb.so db=/etc/vsftpd/db
  1. 修改vsftpd主配置文件/etc/vsftpd/vsftpd.conf
[root@haha-main-130 vsftpd]# grep -Ev '^$|^#' vsftpd.conf 
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/xferlog
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
userlist_deny=YES
tcp_wrappers=YES
# 添加如下配置
guest_enable=YES # 開啟虛擬用戶
guest_username=v_user # 指定虛擬用戶賬號(關聯的本地用戶)
allow_writeable_chroot=YES # 允許寫入數據
  1. 針對不同用戶設置不同的許可權
  • name1 允許上床,新建,修改,查看,刪除
  • name2 只讀
# 設置關聯許可權文件夾
mkdir /etc/vsftpd/v_user_dir

# 創建文件,設置許可權
[root@haha-main-130 v_user_dir]# pwd
/etc/vsftpd/v_user_dir
[root@haha-main-130 v_user_dir]# cat name1 
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
[root@haha-main-130 v_user_dir]# cat name2 
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
[root@haha-main-130 v_user_dir]# 

# 編輯vsftpd主配置文件,添加如下配置
[root@haha-main-130 v_user_dir]# echo 'user_config_dir=/etc/vsftpd/v_user_dir' >> /etc/vsftpd/vsftpd.conf
  1. 重啟服務
systemctl restart vsftpd

問題記錄

  1. 創建文件失敗

    ftp> mkdir data
    550 Create directory operation failed.
    

    解決方法:

    修改/var/ftp/pub文件夾所屬用戶以及所屬用戶組

    [root@haha-main-130 ftp]# pwd
    /var/ftp
    [root@haha-main-130 ftp]# chown -Rf ftp.ftp pub/
    [root@haha-main-130 ftp]# ll
    總用量 0
    drwxr-xr-x 2 ftp ftp 6 6月   9 2021 pub
    

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 一:背景 1.講故事 最近遇到了好幾起和 COM 相關的Dump,由於對 COM 整體運作不是很瞭解,所以分析此類dump還是比較頭疼的,比如下麵這個經典的 COM 調用棧。 0:044> ~~[138c]s win32u!NtUserMessageCall+0x14: 00007ffc`5c891 ...
  • 【進程間通信】常用方式彙總 隨著我們的進程越來越多,難免不同進程之間要互相傳輸一些數據,那麼這個時候該怎麼辦呢? 下麵主要簡單瞭解一下,**進程間通信(InterProcess Communication,IPC)**的幾種實現方式! 1、管道模型 管道模型與軟體生命周期模型——瀑布模型(Water ...
  • 1.apache服務編譯安裝 https://www.cnblogs.com/heyongshen/p/16803125.html 說明: 編譯安裝預設不支持fastcgi功能和反向代理功能 相關配置: 開啟fastcgi功能和反向代理功能 #需要在配置文件中開啟這兩個模塊功能 [root@Cent ...
  • Linux系統下提高工作效率的10個別名用法,可以大大簡化我們的敲命令時間,也不容易出錯,推薦常用的命令,尤其是長的命令,可以使用別名。 ...
  • 使用Podman最好的地方就是支持rootless,也就是說用戶不需要為root許可權即可進行容器的管理操作。因此現在在CentOS 8及以後的版本中,預設使用Podman替代Docker,如果使用docker命令,會重定向到podman。 rootless很好,但是也帶來了一些問題: 多餘的提示 運 ...
  • 最原始的服務部署,為單點部署,即直接把服務部署在一個伺服器上。如果伺服器出現故障,或者服務因為某個異常而掛掉,則服務就會發生中斷。單點部署出現故障的概率最高。 後來,出現了網關,比如 nginx kong 等。如下圖所示: 這樣,所有客戶請求都會經過網關,再由網關轉發到各個服務。如果由服務出現故障, ...
  • 安裝VMware Tools選項顯示灰色的解決辦法 Linux 1. 解決VMware灰色狀態 ①點擊虛擬機; ②在虛擬機設置分別設置CD/DVD和軟盤中選擇連接【使用物理驅動器】(如有CD/DVD2一樣操作); ③重啟虛擬機,灰色字即點亮。 image-20221018195444397 2.VM ...
  • Linux中的文件訪問控制 在Unix系統家族裡,文件或目錄許可權的控制分別以讀取、寫入、執行3種一般許可權來區分,另有3種特殊許可權可供運用【SUID,SGID,SBIT】,再搭配擁有者與所屬群組管理許可權範圍。 SUID: 1、只對二進位可執行程式有效,不能為普通文件; 2、對程式文件必須擁有執行許可權; ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...