Ubuntu下搭建多用戶多權限ftp


#1、切換root用戶模式 (已在root模式下的請忽略)
sudo -i
#然后提示你輸入當前用戶密碼,輸入密碼后回車后如果密碼正確控制台就變成root@***:/# 了。
#2、更新軟件源
apt-get update
#3、安裝 vsftpd
apt-get install vsftpd
 
#4.0、為了操作方便管理,我們給FTP創建自定義FTP目錄和用戶組
#4.1、創建FTP目錄  /home/ftp 當然你也可以創建到其它目錄
mkdir /home/ftp
#4.2、創建FTP用戶組 ftp-g  這個你們也可以用其它組名
groupadd ftp-g
#4.3、設置FTP目錄讀寫權限(注:用戶登陸的根目錄如果權限設置的太大會導致無法登陸,根目錄下的子目錄可以給很大的權限)
chmod 755 /home/ftp(一般服務器都是采用755權限)
#4.4、設置文件夾歸屬 root 以及 我們新建的 FTP用戶組
chown root:ftp-g /home/ftp
到此,ftp的根目錄就已經創建完成了
 
#5.0、設置FTP用戶目錄以及添加FTP用戶
#5.1、為用戶ftp_pub 創建目錄 pub並設置權限
mkdir /home/ftp/pub
chmod 755 /home/ftp/pub
#5.2、添加用戶 ftp_pub 並設置歸屬用戶組為 ftp-g 以及設置缺省目錄(FTP登陸目錄) -s /sbin/nologin 禁止用戶登陸控制台
useradd -g ftp-g -d /home/ftp/pub -s /sbin/nologin ftp_pub
#5.3、給新用戶 ftp_pub 設置密碼(無密碼不能登陸)
passwd ftp_pub
#然后按照提示輸入兩遍密碼 比如我們設置為 123456798
#5.4、更改目錄歸屬
chown ftp_pub:ftp-g /home/ftp/pub
此時,ftp下新建的這個目錄只有ftp_pub才能夠被更改
#5.5、增加上傳目錄不可刪除功能
在配置文件中增加user_config_dir=/etc/vsftpd_user_ctrl,同時在vsftpd_user_ctrl文件夾中增加對應的賬戶名字的文件,目的就是對指定的賬戶進行操作限制,比如:
增加的指令:
cmds_denied=DELE,就是防止刪除操作,同樣的指令操作還有很多,可以到網絡上面自行百度。
到此,就實現了普通用戶的操作限制,比如限制指定用戶刪除操作
 
#6、給FTP開放外網端口(默認:tcp端口 21)
ufw allow 21/tcp
#7、啟動FTP服務
/etc/init.d/vsftpd start
 
#8、普通用戶還是比較好搭建服務器,關鍵是管理員權限不好控制,看來是需要更加復雜的控制才行,需要通過單獨的文件進行控制,比如用vsftp的用戶控制或者用用戶的權限控制,比如登陸以后給與某個用戶超級,最后還是解決了超級管理員的問題,在星期四晚上的最后一刻,還是解決了超級管理員的問題,就是設置root可以登錄,同時登陸root賬戶,那么所有的文件權限也都有了。
 
下圖是vsftpd的配置文件配置對照表,嚴格按照下圖對配置文件進行修改
 
# Example config file /etc/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.
#
#
# Run standalone?  vsftpd can run either from an inetd or as a standalone
# daemon started from an initscript.
listen=YES
#
# 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.
listen_ipv6=NO
#
# Allow anonymous FTP? (Disabled by default).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
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.
#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
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=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=root
#
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
chown_uploads=YES
chown_username=root
#
# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log
#
# 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.
# 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
# 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 restrict local users to their home directories.  See the FAQ for
# the possible risks in this before using chroot_local_user or
# chroot_list_enable below.
#chroot_local_user=YES
#
# 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
#
# Customization
#
# Some of vsftpd's settings don't fit the filesystem layout by
This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=ftp
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
#
# Uncomment this to indicate that vsftpd use a utf8 filesystem.
utf8_filesystem=YES
user_config_dir=/etc/vsftpd_user_ctrl


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM