日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

centos创建vsftpd虚拟用户

發布時間:2025/7/14 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 centos创建vsftpd虚拟用户 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

CentOS Vsftpd服務器(虛擬用戶建立)


一、安裝vsftpd服務相關組件

需要安裝組件vsftpd pam db4 db4-utils

[root@CentOS /]# yum -y install vsftpd*? db4-*

?

二、建立帳戶

建立Vsftpd服務的宿主用戶:

[root@CentOS /]#useradd vsftpd -s /sbin/nologin

?默認Vsftpd的服務宿主用戶是root,但是這不符合安全性的需要。這里建立名字為vsftpd的用戶,用它來作為支持Vsftpd的服務宿主用戶。由于該用戶僅用來支持Vsftpd服務用,沒有許可它登陸系統的必要,并設定它為不能登陸系統的用戶。

??建立Vsftpd虛擬宿主用戶:

[root@CentOS /]#useradd ftpuser -s /sbin/nologin

主要是介紹Vsftp的虛擬用戶,虛擬用戶并不是系統用戶,也就是說這些FTP的用戶在系統中是不存在的。他們的總體權限其實是集中寄托在一個在系統中的某一個用戶身上的,所謂Vsftpd的虛擬宿主用戶,就是這樣一個支持著所有虛擬用戶的宿主用戶。由于他支撐了FTP的所有虛擬的用戶,那么他本身的權限將會影響著這些虛擬的用戶,因此,處于安全性的考慮,也要非分注意對該用戶的權限的控制,該用戶也絕對沒有登陸系統的必要,這里也設定他為不能登陸系統的用戶。

?

三、調整Vsftpd的配置文件:

編輯配置文件前先備份

[root@CentOS /]#cp /etc/vsftpd/vsftpd.conf/etc/vsftpd/vsftpd.conf.backup

?編輯主配置文件Vsftpd.conf

[root@CentOS /]# vi /etc/vsftpd/vsftpd.conf

?原配置文件的修改完全記錄,凡是修改的地方都會保留注釋原來的配置。原本英語的說明我也不***,供參考對比用。———————————————————————————————————————

# Example config file /etc/vsftpd/vsftpd.conf
#

# The default compiled in settings are fairlyparanoid. 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 anexhaustive list of vsftpd options.

# Please read the vsftpd.conf.5 manual page toget a full idea of vsftpd’s

# capabilities.

?#

# Allow anonymous FTP? (Beware – allowed bydefault if you comment this out).

#anonymous_enable=YES

anonymous_enable=NO

設定不允許匿名訪問

#

# Uncomment this to allow local users to login.

?local_enable=YES

設定本地用戶可以訪問。注意:主要是為虛擬宿主用戶,如果該項目設定為NO那么所有虛擬用戶將無法訪問。

#

# Uncomment this to enable any form of FTPwrite command.

?write_enable=YES

設定可以進行寫操作。

#

# Default umask for local users is 077. You maywish to change this to 022,

?# ifyour users expect that (022 is used by most other ftpd’s)

?local_umask=022

設定上傳后文件的權限掩碼。

#

# Uncomment this to allow the anonymous FTPuser to upload files. This only

# has an effect if the above global write enableis activated. Also, you will

# obviously need to create a directory writableby the FTP user.

#anon_upload_enable=YES

anon_upload_enable=NO

禁止匿名用戶上傳。

#

# Uncomment this if you want the anonymous FTPuser to be able to create

# new directories.

#anon_mkdir_write_enable=YES

anon_mkdir_write_enable=NO

禁止匿名用戶建立目錄。

#

# Activate directory messages – messages givento 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 originatefrom port 20 (ftp-data).

connect_from_port_20=YES

設定端口20進行數據連接。

#
# If you want, you can arrange for uploaded anonymous files to be owned by

# a different user. Note! Using “root” foruploaded files is not

# recommended!

#chown_uploads=YES

chown_uploads=NO

設定禁止上傳文件更改宿主。

#chown_username=whoever

#

# You may override where the log file goes ifyou like. The default is shown

# below.

xferlog_file=/var/log/vsftpd.log

設定Vsftpd的服務日志保存路徑。注意,該文件默認不存在。必須要手動touch出來,并且由于這里更改了Vsftpd的服務宿主用戶為手動建立的Vsftpd。必須注意給與該用戶對日志的寫入權限,否則服務將啟動失敗。

#

# If you want, you can have your log file instandard ftpd xferlog format

xferlog_std_format=YES

設定日志使用標準的記錄格式。

#

# You may change the default value for timingout an idle session.

#idle_session_timeout=600

設定空閑連接超時時間,這里使用默認。將具體數值留給每個具體用戶具體指定,當然如果不指定的話,還是使用這里的默認值600,單位秒。

#

# You may change the default value for timingout a data connection.

#data_connection_timeout=120

設定單次最大連續傳輸時間,這里使用默認。將具體數值留給每個具體用戶具體指定,當然如果不指定的話,還是使用這里的默認值120,單位秒。

#

# It is recommended that you define on yoursystem a unique user which the

# ftp server can use as a totally isolated andunprivileged user.

#nopriv_user=ftpsecure

nopriv_user=vsftpd

設定支撐Vsftpd服務的宿主用戶為手動建立的Vsftpd用戶。注意,一旦做出更改宿主用戶后,必須注意一起與該服務相關的讀寫文件的讀寫賦權問題。比如日志文件就必須給與該用戶寫入權限等。

#

# Enable this and the server will recogniseasynchronous ABOR requests. Not

# recommended for security (the code isnon-trivial). Not enabling it,

# however, may confuse older FTP clients.

async_abor_enable=YES

設定支持異步傳輸功能。

#

# By default the server will pretend to allowASCII mode but in fact ignore

# the request. Turn on the below options tohave the server actually do ASCII

# mangling on files when in ASCII mode.

# Beware that on some FTP servers, ASCIIsupport allows a denial of service

# attack (DoS) via the command “SIZE /big/file”in ASCII mode. Vsftpd

# predicted this attack and has always beensafe, reporting the size of the

# raw file.

# ASCII mangling is a horrible feature of theprotocol.

ascii_upload_enable=YES

ascii_download_enable=YES

設定支持ASCII模式的上傳和下載功能。

#

# You may fully customise the login bannerstring:

ftpd_banner=This Vsftp server supports virtual users

設定Vsftpd的登陸標語。

#

# You may specify a file of disallowedanonymous 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 localusers to chroot() to their home

# directory. If chroot_local_user is YES, thenthis list becomes a list of

# users to NOT chroot().

#chroot_list_enable=YES

chroot_list_enable=NO

禁止用戶登出自己的FTP主目錄。

# (default follows)

#chroot_list_file=/etc/vsftpd/chroot_list

#

# You may activate the “-R” option to thebuiltin ls. This is disabled by

# default to avoid remote users being able tocause excessive I/O on large

# sites. However, some broken FTP clients suchas “ncftp” and “mirror” assume

# the presence of the “-R” option, so there isa strong case for enabling it.

#ls_recurse_enable=YES

ls_recurse_enable=NO

禁止用戶登陸FTP后使用”ls -R”的命令。該命令會對服務器性能造成巨大開銷。如果該項被允許,那么擋多用戶同時使用該命令時將會對該服務器造成威脅。

# When “listen” directive is enabled, vsftpdruns in standalone mode and

# listens on IPv4 sockets. This directivecannot be used in conjunction

# with the listen_ipv6 directive.

listen=YES

設定該Vsftpd服務工作在StandAlone模式下。順便展開說明一下,所謂StandAlone模式就是該服務擁有自己的守護進程支持,在ps -A命令下我們將可用看到vsftpd的守護進程名。如果不想工作在StandAlone模式下,則可以選擇SuperDaemon模式,在該模式下?vsftpd將沒有自己的守護進程,而是由超級守護進程Xinetd全權代理,與此同時,Vsftp服務的許多功能將得不到實現。

#

# This directive enables listening on IPv6sockets. To listen on IPv4 and IPv6

# sockets, you must run two copies of vsftpdwhith two configuration files.

# Make sure, that one of the listen options iscommented !!

#listen_ipv6=YES

pam_service_name=vsftpd
設定PAM服務下Vsftpd的驗證配置文件名。因此,PAM驗證將參考/etc/pam.d/下的vsftpd文件配置。

userlist_enable=YES

設定userlist_file中的用戶將不得使用FTP

tcp_wrappers=YES

設定支持TCP Wrappers

#KC: The following entries are added forsupporting virtual ftp users.

以下這些是關于Vsftpd虛擬用戶支持的重要配置項目。默認Vsftpd.conf中不包含這些設定項目,需要自己手動添加配置。

guest_enable=YES

設定啟用虛擬用戶功能。

?guest_username=ftpuser

指定虛擬用戶的宿主用戶。

?virtual_use_local_privs=YES

設定虛擬用戶的權限符合他們的宿主用戶。

?user_config_dir=/etc/vsftpd/vconf

設定虛擬用戶個人Vsftp的配置文件存放路徑。也就是說,這個被指定的目錄里,將存放每個Vsftp虛擬用戶個性的配置文件,一個需要注意的地方就是這些配置文件名必須和虛擬用戶名相同。

————————————————————————-———————————————————

?保存退出。

?

四、建立Vsftpd的日志文件,并更該屬主為Vsftpd的服務宿主用戶:

[root@CentOS /]#touch /var/log/vsftpd.log

[root@CentOS /]#chown vsftpd.vsftpd/var/log/vsftpd.log

?

五、建立虛擬用戶配置文件存放路徑:

[root@CentOS /]# mkdir /etc/vsftpd/vconf/

?

六、制作虛擬用戶數據庫文件

先建立虛擬用戶名單文件:

[root@CentOS /]#touch /etc/vsftpd/virtusers

?

建立了一個虛擬用戶名單文件,這個文件就是來記錄vsftpd虛擬用戶的用戶名和口令的數據文件,我這里給它命名為virtusers。為了避免文件的混亂,我把這個名單文件就放置在/etc/vsftpd/下。

?編輯虛擬用戶名單文件:

[root@CentOS /]#vi /etc/vsftpd/virtusers

—————————-————————-————————-————————-————————-—

ftpuser01

123456

ftpuser02

123456

ftpuser03

123456

—————————-————————-————————-————————-————————-—

編輯這個虛擬用戶名單文件,在其中加入用戶的用戶名和口令信息。格式很簡單:一行用戶名,一行口令

?

生成虛擬用戶數據文件:

[root@CentOS /]#db_load -T -t hash -f/etc/vsftpd/virtusers /etc/vsftpd/virtusers.db

?

察看生成的虛擬用戶數據文件

[root@CentOS /]# ll /etc/vsftpd/virtusers.db

-rw-r–r– 1 root root 12288 Sep 16 03:51/etc/vsftpd/virtusers.db

需要特別注意的是,以后再要添加虛擬用戶的時候,只需要按照一行用戶名,一行口令的格式將新用戶名和口令添加進虛擬用戶名單文件。但是光這樣做還不夠,不會生效的哦!還要再執行一遍“ db_load -T -t hash -f?虛擬用戶名單文件虛擬用戶數據庫文件.db ”的命令使其生效才可以!

?

七、設定PAM驗證文件,并指定虛擬用戶數據庫文件進行讀取

?察看原來的VsftpPAM驗證配置文件:

[root@CentOS /]#cat /etc/pam.d/vsftpd

—————————————————————————————————-—————————-

#%PAM-1.0

session???optional???? pam_keyinit.so??? force revoke

auth??????required???? pam_listfile.so item=user sense=denyfile=/etc/vsftpd/ftpusers onerr=succeed

auth??????required???? pam_shells.so

auth??????include????? system-auth

account???include????? system-auth

session???include????? system-auth

session???required???? pam_loginuid.so

——————————————————————————————————————————--

在編輯前做好備份:

[root@CentOS /]#cp /etc/pam.d/vsftpd/etc/pam.d/vsftpd.backup

編輯VsftpdPAM驗證配置文件

[root@CentOS /]#vi /etc/pam.d/vsftpd

#%PAM-1.0

auth???sufficient?????/lib/security/pam_userdb.so???? db=/etc/vsftpd/virtusers

account sufficient?????/lib/security/pam_userdb.so???? db=/etc/vsftpd/virtusers

以上兩條是手動添加的,內容是對虛擬用戶的安全和帳戶權限進行驗證。這里的auth是指對用戶的用戶名口令進行驗證。這里的accout是指對用戶的帳戶有哪些權限哪些限制進行驗證。其后的sufficient表示充分條件,也就是說,一旦在這里通過了驗證,那么也就不用經過下面剩下的驗證步驟了。相反,如果沒有通過的話,也不會被系統立即擋之門外,因為sufficient的失敗不決定整個驗證的失敗,意味著用戶還必須將經歷剩下來的驗證審核。

再后面的/lib/security/pam_userdb.so表示該條審核將調用pam_userdb.so這個庫函數進行。
最后的db=/etc/vsftpd/virtusers則指定了驗證庫函數將到這個指定的數據庫中調用數據進行驗證。(注:如果是64位操作系統lib=lib64

另外,如果是虛擬用戶登錄出現503錯誤,有可能是防火墻或者selinux設置,另外就是注釋?/etc/pam.d/vsftpd除vsftpd驗證的其他所有行!

?

八、虛擬用戶的配置

?

規劃好虛擬用戶的主路徑:

[root@CentOS /]#mkdir /opt/vsftp/

建立測試用戶的FTP用戶目錄:

[root@CentOS /]#mkdir /opt/vsftp/kanecruise/ /opt/vsftp/mello/ /opt/vsftp/near/

建立虛擬用戶配置文件模版:

[root@CentOS /]#cp /etc/vsftpd/vsftpd.conf.backup /etc/vsftpd/vconf/vconf.tmp

?定制虛擬用戶模版配置文件:

[root@CentOS /]#vi /etc/vsftpd/vconf/vconf.tmp

local_root=/opt/vsftp/virtuser

指定虛擬用戶的具體主路徑。

anonymous_enable=NO

設定不允許匿名用戶訪問。

write_enable=YES

設定允許寫操作。

local_umask=022

設定上傳文件權限掩碼。

anon_upload_enable=NO

設定不允許匿名用戶上傳。

anon_mkdir_write_enable=NO

設定不允許匿名用戶建立目錄。

idle_session_timeout=600

設定空閑連接超時時間。

data_connection_timeout=120

設定單次連續傳輸最大時間。

max_clients=10

設定并發客戶端訪問個數。

max_per_ip=5

設定單個客戶端的最大線程數,這個配置主要來照顧Flashget、迅雷等多線程下載軟件。

local_max_rate=50000

設定該用戶的最大傳輸速率,單位b/s

——————————–————————————————————————————————

這里將原vsftpd.conf配置文件經過簡化后保存作為虛擬用戶配置文件的模版。這里將并不需要指定太多的配置內容,主要的框架和限制交由Vsftpd?的主配置文件vsftpd.conf來定義,即虛擬用戶配置文件當中沒有提到的配置項目將參考主配置文件中的設定。而在這里作為虛擬用戶的配置文件模版只需要留一些和用戶流量控制,訪問方式控制的配置項目就可以了。這里的關鍵項是local_root這個配置,用來指定這個虛擬用戶的FTP主路徑。

?

更改虛擬用戶的主目錄的屬主為虛擬宿主用戶:

[root@CentOS /]#chown -R ftpuser.ftpuser /opt/vsftp/

檢查權限:

[root@CentOS /]#ll /opt/vsftp/

total 24

drwxr-xr-x 2 ftpuser.ftpuser ?4096 Sep 16 05:14 ftpuser01

drwxr-xr-x 2 ftpuser.ftpuser ?4096 Sep 16 05:00 ftpuser02

drwxr-xr-x 2 ftpuser.ftpuser ?4096 Sep 16 05:00 ftpuser03

?

九、給測試用戶定制:

?從虛擬用戶模版配置文件復制:

[root@CentOS /]#cp /etc/vsftpd/vconf/vconf.tmp/etc/vsftpd/vconf/ftpuser01

針對具體用戶進行定制:

[root@CentOS /]#vi /etc/vsftpd/vconf/ftpuser01

———————————————————————————————————————————

local_root=/opt/vsftp/ftpuser01

anonymous_enable=NO

write_enable=YES

local_umask=022

anon_upload_enable=NO

anon_mkdir_write_enable=NO

idle_session_timeout=300

data_connection_timeout=90

max_clients=1

max_per_ip=1

local_max_rate=25000

?

十、啟動服務:

[root@CentOS /]#service vsftpd start

Starting vsftpd forvsftpd:???????????????????????????????[ OK ]

?

如果想把虛擬用戶鎖定在其用戶根目錄請在/etc/vsftpd/配制vsftpd.conf

第一種方法:

chroot_local_user=NO
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
然后,在/etc/vsftpd.chroot_list文件中加入虛擬用戶名。

第二種方法:

在配置文件中修改chroot_local_user=YES

本文轉自歲月丶傾城博客51CTO博客,原文鏈接http://blog.51cto.com/alca0126/1754906如需轉載請自行聯系原作者


laihuadongcto

總結

以上是生活随笔為你收集整理的centos创建vsftpd虚拟用户的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。