ubuntu18系统搭建ftp服务器详解
當(dāng)我們有有的自己的服務(wù)器就可以搭建一個(gè)ftp服務(wù)器,可以自己放進(jìn)去一些東西,這樣以后下載的話會(huì)很方便,而且服務(wù)器端速度很快(所以快慢基本就看自己下載段的速度了.
1. 更新一些服務(wù)器上的文件文件源
sudo apt-get update
2. 下載vsftpd軟件
sudo apt-get install vsftpd
之后就等著下完
3. 配置ftp登錄的用戶
ftp服務(wù)器也是和正常ssh登錄一樣,也是需要用戶指令的.當(dāng)我們下載完vsftpd后,我們系統(tǒng)上就會(huì)多出一個(gè)ftp用戶和ftp組,當(dāng)然這個(gè)ftp用戶是不能直接登錄的.因此,我們也要為ftp創(chuàng)建一個(gè)用戶,當(dāng)然這個(gè)用戶所在的組就是ftp組.例如,創(chuàng)建一個(gè)test:123456 的用戶,如下:
sudo useradd test -g ftp -d /home/ //在/home文件夾下創(chuàng)建該用戶 之后會(huì)提示你密碼,當(dāng)然太簡單的密碼無法通過4. 配置vsftpd配置
在/etc/目錄下有個(gè)vsftp.conf文件,該文件是ftp服務(wù)器的主要配置文件,用vm打開,對(duì)里面的文件進(jìn)行修改.下面貼出我的文件:
后面會(huì)對(duì)其中一些做出簡要說明,要說明的的放會(huì)有 注(num):
# 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=NO #注1: # # 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=YES # # Allow anonymous FTP? (Disabled by default). anonymous_enable=NO #注2: userlist_deny=YES# # 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#注3 # # 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=hellow! Welcome to Curve's FTP service.#注4 # # 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 #注5 chroot_list_enable=YES local_root=/var/ftp #注6 # (default follows) chroot_list_file=/etc/vsftpd.chroot_list 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/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=YESLISTEN = NO :這個(gè)值只能為NO,如果改為YES的話,啟動(dòng)時(shí)會(huì)出錯(cuò)
anonymous_enable=NO :是否允許匿名登錄,不做匿名的話就不重要
write_enable=YES :設(shè)置可以上傳文件
ftpd_banner= :設(shè)置登錄是可以看到的信息,可以任意修改
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
對(duì)ftp登錄的用戶進(jìn)行限制具體請(qǐng)參考.
local_root=/var/ftp :設(shè)置根目錄所在的位置,可以自己設(shè)置.注意可能會(huì)需要權(quán)限此時(shí)加上下面兩條語句,如這個(gè)例子,
chown -R test ftp //test為要ftp登錄的用戶名,第二個(gè)為文件夾
chgrp -R ftp ftp //第一個(gè)ftp 為ftp組
5. 對(duì)ftp用戶訪問進(jìn)行配置
-
設(shè)置test用戶只能夠ftp登錄,不能ssh登錄
usermod -s /sbin/nologin test -
修改/etc/ftpusers.這個(gè)目錄是設(shè)置禁止ftp登錄用戶的因此,如果有自己想讓登錄的用戶,那就直接刪掉
-
增加/etc/vsftpd.chroot_list文件,這個(gè)和上面那個(gè)注5是相關(guān)的,在我的配置下的話,要增加用戶名,因此直接增加test
-
此時(shí)當(dāng)你試著連接時(shí),可能仍舊出現(xiàn)“530 Login incorrect”,修改/etc/shells文件,后面添加以下內(nèi)容:/sbin/nologin/
-
登錄時(shí)可能會(huì)出現(xiàn)的錯(cuò)誤"refusing to run with writable root inside chroot()",問題在于啟用了chroot的話,根目錄要設(shè)置為不可寫
-
當(dāng)然還能夠限制那些用戶可以登錄,當(dāng)如不加也是可以的參考源
首先修改vsftpd.cong文件userlist_enable=YES //設(shè)置用戶訪問列表#允許登錄的用戶 userlist_file=/etc/allowed_users //設(shè)置該列表所在的位置 #最后,對(duì)其進(jìn)行修改,加入自己想要添加進(jìn)的用戶名即可 ```
最最后,重新啟動(dòng)vsftpd進(jìn)程
server vsftpd restart6. 登錄時(shí)常用登錄命令
- 自己可以下載個(gè)ftp連接的軟件,這里說明一下linux終端命令所需的常用命令
- ftp ip 例如ftp 1.1.1.1
- 直接ftp進(jìn)入ftp命令行 用open ip
之后會(huì)讓你輸入用戶名和密碼 - 關(guān)閉連接輸入close
- 推出ftp命令行bye
- ls或者dir
注意用ls很多此的話,可能會(huì)出現(xiàn)連接錯(cuò)誤,dir目前還為發(fā)現(xiàn)
cd 命令
- get|mget 目的文件 下載位置.
get下載單個(gè)文件,mget下載多個(gè)文件.*.*代表所有文件
- put local_filt remote_file
下面附上學(xué)習(xí)時(shí)所參考文章的來源,感謝各位大佬文章
參考文章1 參考文章2 參考文章3 參考文章4 參考文章5 參考文章6
當(dāng)然,還有一些學(xué)習(xí)是所看過的文章,由于看時(shí)還沒有開始寫這個(gè)文章.因此,有些知識(shí)也不知道了來源,因此沒附地址.
轉(zhuǎn)載于:https://www.cnblogs.com/i-curve/p/10152378.html
與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的ubuntu18系统搭建ftp服务器详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android Studio模拟器的ro
- 下一篇: idea去除重复代码校验