天天看点

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

创建资源

  1. 在页面左侧,单击 云产品资源 下拉菜单,查看本次实验资源。
  2. 单击 免费开通 创建所需资源。
    阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

得到一上图片即为成功创建实例

远程连接服务器

接下来即可开始第二步

yu

远程连接ECS服务器 推荐使用XShell

此文章中使用windows自带的CMD实现

在CMD中输入 ssh -V可查看是否拥有ssh,如下图所示例

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

否则需要只能装openSSH

链接

https://www.mls-software.com/files/setupssh-8.2p1-1.exe?spm=a2c6h.13858378.0.0.5f2992d3oUyHvH&file=setupssh-8.2p1-1.exe

然后在终端中输入连接命令 ssh [username]@[ipaddress]。将其中的 username 和 ipaddress 替换为云产品资源提供的ECS服务器的 用户和 弹性IP。例如:ssh [email protected]

示例

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

输入yes(注意 不是y)

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

如上即为连接成功 其中 输入密码时 密码不会显示 注意正确性

安装vsftpd

接下来进行安装vsftp

yum install -y vsftpd           

如图所示即成功

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

配置FTP启动服务(注意是开机自启动)

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd
systemctl enable vsftpd.service           

接下来启动ftp

systemctl start vsftpd.service           

运行以下代码实现查看启动状态

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

可以看到端口是21

配置vsftpd

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd
# 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).
anonymous_enable=YES
#
# 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           

即可查看文件

按i即可进入编辑模式

文章中已经写了

#anon_upload_enable=YES           

所以去掉前面的#号即可

接下来按ESC退出文件编辑模式

:wq           

前面一定有 : 号 (注意)

然后更改目录权限,为FTP用户添加写权限

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd
chmod o+w /var/ftp/pub/           

做完之后重启FTP服务。如下图。

systemctl restart vsftpd.service           
阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

为FTP服务创建一个Linux用户。

adduser ftptest           

并且设置密码

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

创建一个供FTP服务使用的文件目录。

这个地方要注意,否则上传会出问题

更改/var/ftp/test目录的拥有者为ftptest。

新建一个文件夹供使用

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

配置FTP为主动模式执行如下命令:

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

我这里使用的是主动模式,如图

被动和主动已经放在这里了

配置FTP为主动模式请执行如下命令:

sed -i 's/anonymous_enable=YES/anonymous_enable=NO/' /etc/vsftpd/vsftpd.conf #禁止匿名登录FTP服务器 
sed -i 's/listen=NO/listen=YES/' /etc/vsftpd/vsftpd.conf #监听IPv4 sockets 
sed -i 's/listen_ipv6=YES/#listen_ipv6=YES/' /etc/vsftpd/vsftpd.conf #关闭监听IPv6 sockets 
sed -i 's/#chroot_local_user=YES/chroot_local_user=YES/' /etc/vsftpd/vsftpd.conf #全部用户被限制在主目录 
sed -i 's/#chroot_list_enable=YES/chroot_list_enable=YES/' /etc/vsftpd/vsftpd.conf #启用例外用户名单 
sed -i 's/#chroot_list_file=/chroot_list_file=/' /etc/vsftpd/vsftpd.conf #指定例外用户列表文件,列表中的用户不被锁定在主目录 
echo "allow_writeable_chroot=YES" >> /etc/vsftpd/vsftpd.conf 
echo "local_root=/var/ftp/test" >> /etc/vsftpd/vsftpd.conf #设置本地用户登录后所在的目录           

配置FTP为被动模式请执行如下命令:

sed -i 's/anonymous_enable=YES/anonymous_enable=NO/' /etc/vsftpd/vsftpd.conf #禁止匿名登录FTP服务器 
sed -i 's/listen=NO/listen=YES/' /etc/vsftpd/vsftpd.conf #监听IPv4 sockets 
sed -i 's/listen_ipv6=YES/#listen_ipv6=YES/' /etc/vsftpd/vsftpd.conf #关闭监听IPv6 sockets 
sed -i 's/#chroot_local_user=YES/chroot_local_user=YES/' /etc/vsftpd/vsftpd.conf #全部用户被限制在主目录 
sed -i 's/#chroot_list_enable=YES/chroot_list_enable=YES/' /etc/vsftpd/vsftpd.conf #启用例外用户名单 
sed -i 's/#chroot_list_file=/chroot_list_file=/' /etc/vsftpd/vsftpd.conf #指定例外用户列表文件,列表中的用户不被锁定在主目录 
echo "allow_writeable_chroot=YES" >> /etc/vsftpd/vsftpd.conf 
echo "local_root=/var/ftp/test" >> /etc/vsftpd/vsftpd.conf #设置本地用户登录后所在的目录 

echo "pasv_enable=YES" >> /etc/vsftpd/vsftpd.conf #开启被动模式 
echo "pasv_address=<FTP服务器公网IP地址>" >> /etc/vsftpd/vsftpd.conf #本教程中为ECS服务器弹性IP 
echo "pasv_min_port=20" >> /etc/vsftpd/vsftpd.conf #设置被动模式下,建立数据传输可使用的端口范围的最小值 
echo "pasv_max_port=21" >> /etc/vsftpd/vsftpd.conf #设置被动模式下,建立数据传输可使用的端口范围的最大值           

文件创建编写之前已经做过了

这个文件有个关键点,他可以为空,但是必须有

再次重启服务

systemctl restart vsftpd.service           

客户端测试

这里使用的是命令行,也可以使用Chrome浏览器

我在浏览器测试的时候是没有反应的,可能是因为一下浏览器设置的原因

阿里云七天打卡day01创建资源远程连接服务器安装vsftpd

继续阅读