1)安裝vsftpd
Ubuntu安裝軟體倒不是件困難的事,輸入:
sudo apt-get install vsftpd
可能會提示你使用CD光牒,放進去再按回車就行了。
安裝了之後會在/home/下建立一個ftp目錄。這時候你可以試着通路下ftp://IP位址。應該可以看到一個空白内容的ftp空間。
預設設定下匿名使用者可以下載下傳,但不能寫入或是上傳
2)設定 vsftpd.conf檔案
現在我們要讓匿名使用者無法通路,并且得輸入linux上的使用者密碼後才能通路到他們自己目錄裡的内容。
首先找到設定vsftpd的檔案,位置在/etc/vsftpd.conf
修改之前最好先備份下這個檔案:
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.old
然後可以改動了:
#不讓匿名使用者使用
#anonymous_enable=YES
#本地使用者可用
local_enable=YES
#可用寫操作
write_enable=YES
#不需要顯示某目錄下檔案資訊
#dirmessage_enable=YES
#加點banner提示
ftpd_banner=Hello~~
#FTP伺服器最大承載使用者
max_clients=100
#限制每個IP的程序
max_per_ip=5
#最大傳輸速率(b/s)
local_max_rate=256000
#隐藏帳号
hide_ids=YES
好了,重新開機下ftp 伺服器看看效果
重新開機後還是和原來一樣對嗎?呵呵,這是預設的ftp目錄在做鬼,我們把它删除,再看看。怎麼樣?要你輸入使用者名和密碼了吧。
新的問題
1.輸入使用者名密碼後顯示的位置是在使用者的根目錄下,而我們的WEB内容是在public_html目錄裡
2.使用者可以跳到任何其他目錄(非常危險..)
要解決這些問題我們還得設定下vsftpd.conf
#啟動chroot清單(Change root)
chroot_list_enable=YES
#指定清單位置(我這用的是預設位址)
chroot_list_file=/etc/vsftpd.chroot_list
接下來我們得在vsftpd.chroot_list上寫進去我們要限制哪些使用者,不讓他們“漂移”..
現在有使用者linyupark,是以隻要sudo nano一下,往裡面寫就行了
這樣我們已經解決第2個問題了,登陸的使用者隻能在它的使用者檔案夾裡活動,下面我們要更狠一點,讓他隻能在public_html裡活動
依然還是找vsftpd.conf
#這句預設設定裡是沒有的,自己加
user_config_dir=/etc/自己定義一個設定個别使用者用的檔案夾位址
根據自己設定的位址,建立一個相應的檔案夾,然後往裡面建立和使用者名相同的檔案,nano一下:
#本地使用者的根位址,假設使用者是linyupark
local_root=/home/linyupark/public_html
好咯,重新開機下伺服器。
=========================================================
1- 使用下面的指令安裝proftpd:
Code:
sudo apt-get install proftpd
2- 在etc/shells 加入如下代碼 (sudo gedit /etc/shells to open the file)(譯注:指令行模式下sudo vi /etc/shells) :
/bin/false
建立一個 /home/FTP-shared 目錄 :
cd /home
sudo mkdir FTP-shared
建立一個隻能用來讀取ftp的使用者userftp. 這個使用者不需要有效的shell(更安全) ,是以選擇 /bin/false shell 給 userftp , /home/FTP-shared 作為主目錄。
為了是這部分更清楚,我給取此操作的指令行:
sudo useradd userftp -p your_password -d /home/FTP-shared -s /bin/false
在FTP-shared 目錄下建立一個download和一個upload 目錄:
cd /home/FTP-shared/
sudo mkdir download
sudo mkdir upload
現在我們來給它們設定相應的權限:
sudo chmod 755 FTP-shared
cd FTP-shared
sudo chmod 755 download
sudo chmod 777 upload
3- 好了,現在進入proftpd的配置檔案:
sudo gedit /etc/proftpd/proftpd.conf //特别注意路徑,網上以前給的是錯的
當然你可以按你的需要編輯你自己的proftpd.conf:
# To really apply changes reload proftpd after modifications.
AllowOverwrite on
AuthAliasOnly on
# Choose here the user alias you want !!!!
UserAlias sauron userftp
ServerName "ChezFrodon"
ServerType standalone
DeferWelcome on
MultilineRFC2228 on
DefaultServer on
ShowSymlinks off
TimeoutNoTransfer 600
TimeoutStalled 100
TimeoutIdle 2200
DisplayFirstChdir .message
ListOptions "-l"
RequireValidShell off
TimeoutLogin 20
RootLogin off
# It''s better for debug to create log files ;-)
ExtendedLog /var/log/ftp.log
TransferLog /var/log/xferlog
SystemLog /var/log/syslog.log
#DenyFilter \*.*/
# I don''t choose to use /etc/ftpusers file (set inside the users you want to ban, not useful for me)
UseFtpUsers off
# Allow to restart a download
AllowStoreRestart on
# Port 21 is the standard FTP port, so don''t use it for security reasons (choose here the port you want)
Port 1980
# To prevent DoS attacks, set the maximum number of child processes
# to 30. If you need to allow more than 30 concurrent connections
# at once, simply increase this value. Note that this ONLY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd)
MaxInstances 8
# Set the user and group that the server normally runs at.
User nobody
Group nogroup
# Umask 022 is a good standard umask to prevent new files and dirs
# (second parm) from being group and world writable.
Umask 022 022
PersistentPasswd off
MaxClients 8
MaxClientsPerHost 8
MaxClientsPerUser 8
MaxHostsPerUser 8
# Display a message after a successful login
AccessGrantMsg "welcome !!!"
# This message is displayed for each access good or not
ServerIdent on "you''re at home"
# Set /home/FTP-shared directory as home directory
DefaultRoot /home/FTP-shared
# Lock all the users in home directory, ***** really important *****
DefaultRoot ~
MaxLoginAttempts 5
#VALID LOGINS
AllowUser userftp
DenyALL
AllowOverwrite off
DenyAll
AllowAll
好了,你已經完成了proftpd的配置,你的服務端口是1980,而讀取的參數如下,使用者:sauron,密碼:你為userftp設定的那個。
4- 啟動/停止/重新開機動你的服務:
sudo /etc/init.d/proftpd start
sudo /etc/init.d/proftpd stop
sudo /etc/init.d/proftpd restart
對你的proftpd進行一下文法檢查: