背景
銀河麒麟服務(wù)器會(huì)有文件導(dǎo)入導(dǎo)出的需要岭皂,由于環(huán)境原因主機(jī)上沒有USB接口见擦,需要使用以太網(wǎng)完成,因此準(zhǔn)備在服務(wù)器中安裝ftp服務(wù)姥饰,讓導(dǎo)入導(dǎo)出設(shè)備使用ftp客戶端連接服務(wù)器做文件導(dǎo)入導(dǎo)出操作傻谁。
安裝
ftp服務(wù)是需要單獨(dú)安裝的,如果沒有的話列粪。首先使用命令查看服務(wù)器中是否已經(jīng)安裝了ftp
rpm -qa | grep ftp
通過(guò)命令查看此主機(jī)中已經(jīng)安裝了vsftpd审磁。ftp是一種協(xié)議,基于此協(xié)議的軟件有很多岂座,其中vdftpd是其中的一種态蒂,既然主機(jī)中已經(jīng)安裝了,那我們就用這一個(gè)费什,省的再去找安裝包钾恢。
ftp默認(rèn)端口是21,使用命令查看此端口是否已經(jīng)開啟鸳址,如果開啟了說(shuō)明ftp是啟動(dòng)的就可以直接連接了
lsof -i :21
通過(guò)查看主機(jī)中端口21是沒有開啟的瘩蚪,也就時(shí)ftp服務(wù)沒有啟動(dòng),使用命令查看服務(wù)狀態(tài)
systemctl status vsftpd
通過(guò)查看主機(jī)中vsftpd服務(wù)是沒有運(yùn)行的稿黍,并且啟動(dòng)參數(shù)是disable疹瘦,也就是不開機(jī)啟動(dòng)。我們使用命令啟動(dòng)ftp服務(wù)巡球,并且設(shè)置為開機(jī)啟動(dòng)
systemctl start vsftpd
systemctl enable vsftpd
systemctl status vsftpd
看到ftp服務(wù)已經(jīng)啟動(dòng)言沐,并且設(shè)置為開機(jī)啟動(dòng),重啟主機(jī)在查看ftp服務(wù)狀態(tài)和21端口狀態(tài)
看到21端口已經(jīng)被vsftpd進(jìn)程占用辕漂,說(shuō)明ftp服務(wù)器開機(jī)啟動(dòng)成功
使用
ftp服務(wù)開啟后呢灶,可以在客戶機(jī)上使用ftp客戶端工具進(jìn)行連接
客戶端使用ftp連接上主機(jī)后吴超,可以看到主機(jī)的文件系統(tǒng)钉嘹,并且通過(guò)工具可以進(jìn)行文件導(dǎo)入導(dǎo)出操作。
問題
服務(wù)器中開啟ftp服務(wù)后鲸阻,直接連接ftp服務(wù)會(huì)有一些錯(cuò)誤跋涣,沒有權(quán)限。這跟ftp服務(wù)配置有關(guān)鸟悴,ftp配置是有規(guī)則的陈辱,比如允許/不允許xxx用戶連接,允許/不允許xxx用戶讀寫等细诸。
vsftpd配置文件在/etc/vsftpd目錄中沛贪,其中ftpusers文件是不允許連接的用戶,可以看到里面第一個(gè)就是root,表示不允許root用戶連接利赋,我們把root用戶注釋掉水评。user_list文件是允許連接的用戶,里面有root媚送,表示允許root用戶連接中燥,如果沒有就加上。我們看2個(gè)文件都有root塘偎,說(shuō)明黑名單的權(quán)限高一些疗涉。vsftpd.conf就是ftp服務(wù)的配置文件,基本都是默認(rèn)參數(shù)吟秩,但是不修改是不行的咱扣,需要進(jìn)行一些修改,下面貼圖中標(biāo)注了要修改的位置和描述峰尝,有的配置是本身沒有的偏窝,需要自己加上。
# Example config file /etc/vsftpd/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.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
# #允許匿名用戶登錄FTP
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
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.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#打開匿名用戶的上傳權(quán)限
#anon_upload_enable=YES
anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#打開匿名用戶創(chuàng)建目錄的權(quán)限
#anon_mkdir_write_enable=YES
anon_mkdir_write_enable=YES
#打開匿名用戶刪除和重命名的權(quán)限
anon_other_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=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/xferlog
#
# 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. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# 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 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
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO
#
# 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.
# Make sure, that one of the listen options is commented !!
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
#允許任何人訪問
userlist_deny=no
userlist_file=/etc/vsftpd/user_list
關(guān)于此問題有的說(shuō)是要在/etc/pam.d/vsftpd文件中注釋掉關(guān)于auth的配置武学,筆者試了沒有效果祭往。這個(gè)文件不需要改動(dòng)。
完成上述操作重啟主機(jī)后再連接ftp就可以進(jìn)行文件上傳和下載火窒。 還有就是筆者使用一個(gè)銀河麒麟V10桌面版電腦使用ftp客戶端連接硼补,上傳可以正常完成,下載時(shí)總是錯(cuò)誤熏矿。這個(gè)不是ftp服務(wù)沒有配置好已骇,是因?yàn)榭蛻舳讼到y(tǒng)是普通用戶登錄的,在很多目錄沒有權(quán)限票编,進(jìn)入該用戶的文件目錄時(shí)就可以下載褪储。其實(shí)時(shí)客戶端本身的寫權(quán)限沒有。