Article directory
- Preface
- (1) Building Linux FTP network environment
-
- 1.Install ftp package
- 2. Set up the FTP service for anonymous users to access (maximum permissions)
- 3. Set maximum permissions for anonymous access to the pub subdirectory under the root directory of ftp so that anonymous users can upload data.
- 4. Turn on the service, turn off the firewall and enhanced security features
- (2) Windows sets username and password to access ftp server
- (3) Windows anonymous access to ftp server
- Problem record
Preface
基于FTP协议实现Linux与Winodows实现文件传输,是大学期间的一个小实验。在这里做个总结。
(1) Building Linux FTP network environment
lab environment:
- Linux CentOS 7.9
- Xshell 7
- Win10
1.Install ftp package
Install vxftpd pacakge through yum and follow the following instructions
yum -y install vsftpd
Modify vsftpd.conf and back it up to vsftpd.conf.bak
to prevent the configuration file from being unable to run due to errors.
[root@localhost ~] cd /etc/vsftpd/
[root@localhost vsftpd] ls
ftpusers user_list vsftpd.conf vsftpd_conf_migrate.sh
[root@localhost vsftpd] cp vsftpd.conf vsftpd.conf.bak
[root@localhost vsftpd] ls
ftpusers user_list vsftpd.conf vsftpd.conf.bak vsftpd_conf_migrate.sh
[root@localhost vsftpd] vim vsftpd.conf
vsftpd.conf vsftpd.conf.bak
2. Set up the FTP service for anonymous users to access (maximum permissions)
Executevim vsftpd.conf
and add the configuration information shown in the red box in the figure below to allow anonymous users to enable read and write permissions.
Here you can exit the vim editing mode first. In order to conveniently find the location of the above red box configuration information in the file, execute the following command to see the specific line numbers of these files.
grep -n --color=auto 'anon*' vsftpd.conf
Thenvim vsftpd.conf
, exit the editing mode, execute: :set nu
to display the line number in the vim editor.
3. Set maximum permissions for anonymous access to the pub subdirectory under the root directory of ftp so that anonymous users can upload data.
chmod 777 /var/ftp/pub/
4. Turn on the service, turn off the firewall and enhanced security features
Execute the following three instructions respectively
systemctl start vsftpd
systemctl stop firewalld
setenforce 0
Execute:ifconfig
, see that the network card IP is 192.168.1.128, save it, it will be used for subsequent connections.
(2) Windows sets username and password to access ftp server
- Click My Computer on the desktop, then click Map Network Drive
· Select map network drive
Set the specified website address:ftp://virtual machine network card ip
Here you can set up anonymous user connection ftp or set up user access ftp connection . Here is a demonstration of logging in to FTP using a username.
Then click Login. If the FTP server address is filled in correctly, the contents of the virtual machine file will be displayed:
We open "This Computer", you can see the FTP connection we configured in the network configuration.
Now press Win+R keys to open Windows console
Execute:
ftp 192.168.1.128
Enter the account and password according to the instructions, which is the account password you filled in earlier to connect to the FTP server:
Then execute in the cmd console:
cd /etc
ls
Test: Windows downloads Linux files to local
Next, create a file on the virtual machine and write something. Then go to the windows interface and take a look.
[root@localhost vsftpd] cd /var/ftp/pub/
[root@localhost pub] touch test.txt
[root@localhost pub] vim test.txt # 往test.txt中写点东西
[root@localhost pub] ls
test.txt
Go back to the Windows console and enter /ftp/pub to view test.txt. Use get test.txt
, and Windows will download the content locally. C:\Users\Asus\test.txt
(The local path may be slightly different)
(3) Windows anonymous access to ftp server
The previous operations are the same. Since we previously set up anonymous users to allow FTP to connect to the pub folder, the process of selecting anonymous users to connect to the FTP server is as follows:
Anonymous users here can only access the pub folder.
We still use the cmd command and enter
ftp 192.168.1.128
At this time, the system will also prompt you to enter your username and password: Since you are logging in anonymously, the username is: anonymous
, 密码任意输入
. Login successful
The next steps are the same as before.
Problem record
1. "An error occurred while opening the folder on the ftp server, please check whether you have permission to access the folder"
This is an error when connecting to a virtual machine via Windows 10 FTP. The reason may be that the system firewall blocks the connection.
[Scheme] Open the Control Panel and search for the "Internet" option. Internet Options>>Advanced>>Uncheck the "Use passive FTP (for firewall and DSL modem compatibility)" option>>OK
2.[Linux/ CentOS】Boolean ftp_home_dir is not defined
After installing the vsftpd software, because the SELinux security policy of the CentOS system does not enable the FTP service by default, direct access will report an error of 500 OOPS, so it needs to be modified to allow the use of FTP Serve.
Goal: I hope ftp users can access their home directories
Try: command line input
sudo setsebool -P ftp_home_dir 1
An error will be reported: Boolean ftp_home_dir is not defined
After searching, it turns out that CentOS7 started to use tftp_home_dir instead of ftp_home_dir, so it should be modified as follows:
sudo setsebool -P tftp_home_dir
Then we execute:
getsebool -a | grep ftp
View the ftp process.
The selinux file configuration is changed below. After the changes are completed, reboot. The configuration will take effect.
vim /etc/sysconfig/selinux
3. FTP - 550 Failed to change directory
[root@localhost~]setfacl -R -m u:fy36:rwx /var/ftp/pub/
[root@localhost ~] usermod -a -G ftp fy36
[root@localhost ~] chmod g+s /var/ftp/pub/
4. Enter the IP address, root user, password, quick connection, and error: 530 Permission denied.
troubleshooting:
1. First check whether the vsftp service is enabled on the system. If not, enable the service first.
Method 1. setup-system service-self-start service
Method 2. Interface setting, service vsftpd restart
2. View Configuration
vsftpd configuration, the vsftpd user connection control configuration is limited in the configuration file.
vsftpd.ftpusers: located in the /etc directory. It specifies which user accounts cannot access the FTP server, such as root, etc.
vsftpd.user_list: located in the /etc directory. The user account in this file cannot access the FTP server by default. Access is only allowed when the userlist_enable=NO option is enabled in the vsftpd .conf configuration file.
vsftpd.conf: located in the /etc/vsftpd directory. Customize the configuration of the FTP server such as user login control, user permission control, timeout settings, server function options, server performance options, server response messages, etc.
3. After the configuration modification is completed, execute service vsftpd restart to restart the vsftpd service.
5. linux ftp failed open,Linux VSFTP prompts 500 OOPS: failed to open xferlog log file:/var/log/xferlog
For example, B reports this error when connecting to A using FTP. Let's try A FTP connection to B. The connection is mutual.