CentOS8 set up FTP server

1 Overview

CentOS8 passage about how vsftpd set up an FTP server, then a simple anonymous upload / download and users to upload / download the test, as well as the use of wget test.

2 Installation vsftpd

yum install -y vsftpd

3 open service

service httpd start

4 Set the boot

Can use

systemctl list-unit-files | grep vsftpd

Check whether the boot display disabled.
Here Insert Picture Description
By

chkconfig vsftpd on

Open from the start, execute systemctl again, you can see become enabled.

5 Modify /etc/vsftpd/vsftpd.conf

sudo vim /etc/vsftpd/vsftpd.conf

First of all modifications
Here Insert Picture Description
to YES.
Add anon_upload_enable = YES line of
Here Insert Picture Description
the first line means that allow anonymous logins, the second line means that allow anonymous uploads.
Restart the service.

service vsftpd restart

6 Creating test file

cd /var/ftp/pub
sudo vim test

Here Insert Picture Description

7 Test

7.1 Browser Test

7.1.1 anonymous testing

ifconfig obtain network ip, enter in your browser ftp:. // ip
Here Insert Picture Description
can see there is a pub folder, there are just the new test file.
Here Insert Picture Description
Here Insert Picture Description
Right Save to download the file
Here Insert Picture Description
download is complete.
Here Insert Picture Description
to look at the terminal.
Here Insert Picture Description

7.1.2 Test User Login

Entry

ftp://username@ip

Here Insert Picture Description
Then enter the user's password.
The default is accessed files in the root directory of the user, showing out here.
Here Insert Picture Description
Download the case above, the right to choose.

7.2 ftp command to test

First install ftp:

sudo yum install ftp

7.2.1 anonymous testing

ftp ip

Here select the user name ftp, password is blank, an anonymous login .ftp as the default anonymous user login name, as the password, you can set up in one of the /etc/vsftpd/vsftpd.conf

no_anon_password=YES

So that anonymous users can log on without a password.
Here Insert Picture Description

7.2.1.1 upload test

直接使用put命令,后面接上文件,这里的upload.txt是执行ftp之前的所在文件夹下的upload.txt
Here Insert Picture Description
这里提示不能创建文件,是权限的原因,要确保/var/ftp/pub对"other"用户有写权限.
Here Insert Picture Description
默认的/var/ftp/pub的权限是644,修改成647.

sudo chmod 647 /var/ftp/pub

同时修改上传文件的权限,允许other用户可读.

sudo chmod 644 /root/upload.txt

如果不行,使用selinux设置.

getsebool -a | grep ftp

Here Insert Picture Description
把ftpd_full_access开启:

setsebool ftpd_full_access on

Here Insert Picture Description
再进入upload.txt所在的文件夹,执行ftp,再次put.
Here Insert Picture Description
成功!
Here Insert Picture Description

7.2.1.2 下载测试

直接get文件即可,由于上面已经设置好了权限,所以不会出现问题.
Here Insert Picture Description
Here Insert Picture Description
若出现权限问题可从三方面入手:

  • (1)/var/ftp/pub的对other用户的可读权限:因为是下载,而且匿名,所以只需要对other用户的可读权限
  • (2)被下载文件的对other用户的可读权限
  • (3)selinux的问题,设置ftpd_full_access为on

7.2.2 用户登录测试

执行ftp时用对应用户名与密码登录.
Here Insert Picture Description
默认进入了用户根目录.

7.2.2.1 上传测试

直接put即可.
Here Insert Picture Description
Here Insert Picture Description
若出现权限问题参照上面7.2.1.2的那三条方法.

7.2.2.2 下载测试

随便在用户根目录新建一个文件,这里是kr.
Here Insert Picture Description
直接get即可.
Here Insert Picture Description
Here Insert Picture Description

7.3 wget测试

wget to download files, the same directory with the initial download ftp login directory, such as anonymous ftp login, login is / var / ftp directory, wget will be from the / var / ftp directory download files, download wget command to execute directory. user "kr" Log ftp, the login is / home / kr directory, wget will be from / home / kr Download file.

7.3.1 anonymous testing

Note Make sure that the downloaded file has read permissions to other users.

sudo chmod o+w xxxxxx

Then use wget

wget ftp://ip/pub/xxxx

Here Insert Picture Description
Here Insert Picture Description

7.3.2 Test User Login

Use --ftp-user, - ftp-password specify a user name and password, above the rest.

wget ftp://ip/xxx --ftp-user=xxxx --ftp-password=xxxx

Here Insert Picture Description
success.

8 summary

Uh .... Simply put, first installed ftp with vsftpd, add the appropriate permissions and modify /etc/vsftpd/vsftpd.conf, for reasons not upload and download, basically the question of powers, is the three main aspect:

  • Rights (1) ftp directory: for example, may be / var / ftp / pub no corresponding write access to the upload failed, there is no corresponding read permission download fails.
  • Permissions (2) is uploaded files: such as uploading a file upload failed due to no read permission.
  • (3) selinux: Use setsebool to on.

After resolving permissions issues, basically you can use this by ftp or wget ftp server successfully upload / download files.

Guess you like

Origin www.cnblogs.com/Blueeeeeeee/p/12128155.html