1. 程式人生 > >Ubuntu16.04 ftp伺服器安裝+配置

Ubuntu16.04 ftp伺服器安裝+配置

ftp伺服器安裝與配置

1. ftp服務端的安裝

如果之前配置過ftp伺服器的還是之後配置的伺服器,無法啟動服務,那麼基本是配置出現了錯誤,那麼可先完全解除安裝後再進行安裝。如果無法定位多半是映象源的問題,請更換阿里源。

sudo apt-get update 
sudo apt-get install vsftpd
vsftpd --version     //檢測是否安裝
2. ftp服務端的配置
 vim /etc/vsftpd.conf    //編輯配置檔案

修改vsftpd.conf檔案如下:

listen=NO                 //是否開啟監聽ipv4和ipv6資料      
listen_ipv6=YES //是否開啟監聽ipv6資料 # 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 //設定本地使用者預設要減免的許可權 # 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 //確認連線傳輸的埠號為20 # 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 fully customise the login banner string: ftpd_banner=Welcome to FTP service. //在使用shell時登陸那麼會發送歡迎語 # 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 //白名單路徑,若無這個檔案需要自己建立 # 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 pam_service_name=ftp //此處ubuntu的系統需要改為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 //編碼統一為utf8編碼,可以識別中文,防止亂碼
 3. vftpd配置完成

新增設定ftpuser使用者和訪問目錄

 1. 建立ftp使用者組和使用者
sudo groupadd ftpusers //建立ftpusers使用者組
sudo useradd -m ftpuser_lxr//建立一個使用者並且自動建立家目錄為/home/ftpuser_lxr
(第二種方式:mkdir /home/ftpuser_lxr //先建立家目錄sudo userad -d /home/ftpuser_lxr ftpuser_lxr //繫結這個家目錄)
usermod -G ftpusers ftpuser_lxr //將這個新使用者加入到ftpusers使用者組中
sudo passwd ftpuser_lxr   //更改密碼
mkdir /home/ftpuser_lxr/ftp  //為使用者新增一個具有一定許可權的資料夾
chmod 777 -R /home/ftpuser_lxr/ftp //新建一個pub目錄用於存放檔案,並且賦予全部許可權
usermod -s /sbin/nologin username  //限制使用者登入方式;限制使用者username只能通過ftp登陸,而不能直接登陸伺服器
2.將該使用者加入vsftpd.chroot_list白名單中
mkdir /etc/vsftpd.chroot_list
vim vsftpd.chroot_list

該檔案內容如下:

#白名單
ftpuser_lxr
3.開啟並重啟vsftpd的服務

systemctl start vsftpd或者service vsftpd start systemctl restart vsftpd或者service vsftpd restart

測試

方法一:

開啟瀏覽器,在位址列輸入:ftp://ip_addresss

方法二:

 在ubuntu中使用shell輸入:ftp ip_address

方法三:

 在windows中在檔案管理器位址列輸入:ftp://ip_addresss,該方式可以上傳下載檔案

方法四:

 在windows中使用cmd輸入:ftp://ip_addresss //顯示連線成功