ubuntu安裝配置FTP
Ubuntu 12.04下安裝FTP軟件固然選擇大名鼎鼎的vsftpd(very secure FTP daemon), Ubuntu裝vsftpd很簡單,一句命令就行:
sudo apt-get install vsftpd
命令執行過程當中,安裝程序會給本地建立一個名爲「ftp」的用戶組,命令執行完以後會自動啓動FTP服務。
可使用「netstat -tl」命令檢查FTP端口有沒有已經打開,或者直接在
瀏覽器裏輸入「ftp://你的服務器IP」(新安裝的vsftpd默認是能夠匿名不須要密碼直接訪問),若是能直接鏈接到FTP服務器,則安裝vsftpd算是大功告成。
開啓、中止、重啓vsftpd服務也很簡單:
service vsftpd start | stop | restart
新安裝的vsftpd默認是能夠匿名訪問,若是隻想給某一個用戶專門訪問某一目錄下的權限,則須要修改vsftpd的配置了。
首先,建立一個專門用來訪問的用戶,例如叫「test」:
mkdir -p /home/test
sudo useradd -g ftp -d /home/test -M test
PS: 刪除用戶用如下命令:
sudo userdel test
設置密碼:
passwd test
修改vsftpd的配置文件「vi /etc/vsftpd.conf」:
#禁止匿名訪問
anonymous_enable=NO
#接受本地用戶
local_enable=YES
#能夠上傳
write_enable=YES
local_umask=022
#啓用在chroot_list_file的用戶只能訪問根目錄
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
在/etc/vsftpd.chroot_list添加受訪問目錄限制的用戶:
1.chroot_list_enable=YES (NO)
是否啓用 chroot 寫入列表的功能?與底下的 chroot_list_flie 有關!這個項目得要開啓,不然底下的列表檔案會無效。
2.chroot_list_file=/etc/vsftpd.chroot_list
若是 chroot_list_enable=YES 那麼就能夠設定這個項目了
3./etc/vsftpd/chroot_list
這個檔案預設是不存在的,因此你必需要手動自行創建。這個檔案的主要功能是能夠將某些賬號的使用者 chroot 在他們的家目錄下!但這個檔案要生效與 vsftpd.conf 內的『 chroot_list_enable, chroot_list_file 』兩個參數有關。 若是你想要將某些實體用戶限制在他們的家目錄下而不準到其餘目錄去,能夠啓動這個設定項目喔!
SO檢查你的linux中是否有/etc/vsftpd/chroot_文件,若是沒有,要本身創建
「500 OOPS: vsftpd: refusing to run with writable root inside chroot()」
啓用了chroot的話,根目錄要設置爲不可寫,這是vsftp的保護機制。
chmod a-w /home/test
那麼用戶登錄FTP就能夠訪問到test下的東西,可是無法去上傳文件。若是把test文件夾設置成777權限,那麼FTP就登錄不上去。
因此解決辦法是。在test文件夾下再建立一個文件夾「/home/test/wwwroot」,將wwwroot設置成777就能夠了,那麼之後上傳東西就上傳到wwwroot裏。
OK,重啓vsftpd以後就可使用上面新建立的帳號訪問。
若是想改變ftp 默認登陸的目錄 則加入下面的命令
/*
#啓用在chroot_list_file的用戶只能訪問根目錄
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list 這2個上面配置過了 是下面必須的前提
*/
local_root=/usr/share/nginx/www 用戶登陸後的目錄 這個能夠註釋掉不寫 由於有 user_config_dir=/etc/vsftpd/userconf 這個下面對應的用戶配置的路徑
chroot_local_user=NO 這個必定要NO 不然能夠訪問上級目錄
#anon_root=/usr/share/nginx/www 這個是匿名用戶登陸後的目錄 這裏註釋掉了 能夠忽略
user_config_dir=/etc/vsftpd/userconf 這個是分配每一個用戶的顯示的目錄 =號的右邊 是配置文件的路徑 若是有的話手動創建
而後在userconf下 創建與用戶名對應的配置文件 好比我這裏是test用戶 則 vim test
裏面輸入 local_root=/usr/share/nginx/www 這裏輸入你須要例如test用戶登陸後的目錄的路徑
配置完後 重啓vsftpd 把鏈接ftp的工具或客戶端 關掉 從新打開 應該就能夠了
下面是我本身的vsftp.conf裏的內容
-----------------------------------------------
# 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
#
# Run standalone with IPv6?
# Like the listen parameter, except vsftpd will listen on an IPv6 socket
# instead of an IPv4 one. This parameter and the listen parameter are mutually
# exclusive.
#listen_ipv6=YES
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
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=whoever
#
# 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
#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 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
# default.
#
# 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=vsftpd
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/private/vsftpd.pem
#local_root =/usr/share/nginx/www/
#local_root=/usr/share/nginx/www
chroot_local_user=NO
#anon_root=/usr/share/nginx/www
user_config_dir=/etc/vsftpd/userconf
-----------------------------------------------
到此測試成功
補充一個添加新用戶的問題
好比爲ftp 添加新的用戶test1
mkdir -p /home/test1
sudo useradd -g ftp -d /home/test1 -M test1
passwd test1
以後查看一下用戶所屬的組 查看test和test1 是否在ftp組裏
groups test test1 肯定在同組後
vim /etc/vsftpd.conf
把 local_umask=000 這樣 就能夠test1和test 2個ftp用戶 共同操做一個aa目錄下的全部文件
上傳時也不會出現553錯誤了 也許還有更好的方法 這裏我測試時是local_umask=000 不知道會不會有安全問題
在/etc/vsftpd/userconf/下 創建一個test的配置 vim test1
local_root=/usr/share/nginx/www 和test配置方法同樣
以後更改/usr/share/nginx/www/aa 這裏好比aa是該項目的文件夾
chown ftp:ftp aa 改權限爲ftp組固然aa 也要有777的權限才行
以後再上傳的文件等 test和test1 均可以互相操做了
===========================
下面是的是參考其餘人的一些配置參數
VSFTP用戶目錄指定linux
1.修改VSFTP配置文件
vi /etc/vsftpd/vsftp.confnginx
#啓動chroot列表
chroot_list_enable=YES
#指定列表位置
chroot_list_file=/etc/vsftpd/chroot_list
全部用戶將被鎖定在定義的目錄ubuntu
userlist_enable=yes
禁止文件/etc/vsftpd/user_list文件中的用戶登錄FTPvim
添加讀取用戶配置目錄(注:本行配置默認沒有須要手動輸入)
user_config_dir=/etc/vsftpd/userconf瀏覽器
2.創建用戶配置目錄
mkdir /etc/vsftpd/userconf安全
3.創建用戶登錄後的目錄
mkdir /export/home/nwom服務器
4.添加用戶配置文件session
已知有用戶nwomsocket
注:有不少用戶時,須要建每一個用戶相對應的文件async
vi /etc/vsftpd/userconf/nwom
local_root=/export/home/nwom
FTP用戶登錄後指定的目錄
5.重啓VSFTP
/etc/init.d/vsftpd restart
登錄nwom用戶FTP將登錄至/export/home/nwom目錄