天天看點

阿裡雲七天打卡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

繼續閱讀