日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用Docker实现vsftpd配置——用户验证访问上传

發布時間:2023/12/31 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用Docker实现vsftpd配置——用户验证访问上传 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

你可能需要看一下:Docker系列-容器修改后保存為鏡像并導出

1、服務安裝

1.1、容器創建

創建一個容器

docker run -tid -p 20:20 -p 21:21 -v /ftp/:/home/liumou/ftp/ --name ftp_rw debian:10 /bin/bash

進入容器

docker exec -ti ftp_rw /bin/bash

1.2、安裝vsftpd

首先配置源,配置教程:Debian10常用國內源更換鏡像站匯總
安裝之前需要先:

apt update

然后再安裝

apt install -y vsftpd

安裝過程(部分):

root@bdbb277fd90b:/# apt install vftpd Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package vftpd root@bdbb277fd90b:/# apt update Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB] Get:2 http://mirrors.ustc.edu.cn/debian buster InRelease [121 kB] Get:3 http://security.debian.org/debian-security buster/updates/main Sources [152 kB] Get:4 http://mirrors.ustc.edu.cn/debian buster-updates InRelease [51.9 kB] Get:5 http://mirrors.ustc.edu.cn/debian buster-backports InRelease [46.7 kB] Get:6 http://mirrors.ustc.edu.cn/debian buster/main Sources [7841 kB] Get:7 http://security.debian.org/debian-security buster/updates/main arm64 Packages [237 kB] Get:8 http://mirrors.ustc.edu.cn/debian buster/main arm64 Packages [7736 kB] Get:9 http://mirrors.ustc.edu.cn/debian buster-updates/main Sources [3716 B] Get:10 http://mirrors.ustc.edu.cn/debian buster-updates/main arm64 Packages [7848 B]

只要網絡沒問題就能安裝成功

2、配置修改

修改之前先備份

cp /etc/vsftpd.conf /etc/vsftpd.conf.bak

2.1、配置文件內容

使用下面的命令進行配置vsftp服務

cat <<EOF > /etc/vsftpd.conf listen=YES listen_ipv6=NO anonymous_enable=NO local_enable=YES write_enable=YES anon_upload_enable=YES anon_mkdir_write_enable=YES dirmessage_enable=YES use_localtime=YES xferlog_enable=YES connect_from_port_20=YES chroot_local_user=YES chroot_list_enable=YES allow_writeable_chroot=YES chroot_list_file=/etc/vsftpd.chroot_list secure_chroot_dir=/var/run/vsftpd/empty pam_service_name=vsftpd rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key ssl_enable=NOtcp_wrappers=YES utf8_filesystem=YES local_root=/home/liumou/ftp EOF

2.2、用戶列表

touch /etc/vsftpd.chroot_list

PS:如果希望某個用戶可以登陸訪問其他目錄,請寫入該文件

3、權限配置

3.1、用戶創建

創建用戶目錄

mkdir -p /home/liumou/ftp/

創建用戶

useradd -d /home/liumou/ liumou

設置密碼

passwd liumou

執行過程:

root@b31e7fa60187:/# useradd -d /home/liumou/liumou root@b31e7fa60187:/# passwd liumou New password: Retype new password: passwd: password updated successfully

然后對這個目錄進行權限的設置,命令如下:

chown -R liumou:liumou /home/liumou/ftp/ chmod -R 755 /home/liumou/ftp/

執行過程:

root@b31e7fa60187:/# chown -R liumou:liumou /home/liumou/ftp/ root@b31e7fa60187:/# chmod -R 755 /home/liumou/ftp/

配置結果:

root@b31e7fa60187:/# ls -l /home/liumou/ total 4 drwxr-xr-x 2 liumou liumou 4096 Nov 2 02:12 ftp root@b31e7fa60187:/#

3.2、配置生效

配置完成之后,我們需要對服務進行重啟才能使其生效,方法如下:

cd /etc/init.d/ ./vsftpd restart

執行結果:

root@b31e7fa60187:/# cd /etc/init.d/ root@b31e7fa60187:/etc/init.d# ./vsftpd restart [....] Stopping FTP server: vsftpdNo /usr/sbin/vsftpd found running; none killed. . ok [ ok ] Starting FTP server: vsftpd. root@b31e7fa60187:/etc/init.d#

4、宿主機配置

由于我們是使用的容器進行部署,并且映射了宿主目錄,所以我們還需要對宿主目錄進行權限配置,命令如下:
首先退出容器,回到宿主機,命令如下:

exit

然后對映射目錄進行賦權

chmod -R 755 /ftp/ chown root:root /ftp/

PS:采用容器部署的好處就是一次配置,隨處可用,并且對于宿主目錄而言,只需要把需要分享的路徑進行掛載然后賦權即可,最多也就:導入Docker鏡像->創建容器->賦權,三步完成,還可以根據不同需要制定不同的鏡像,

執行過程:

root@b31e7fa60187:/etc/init.d# exit exit root@l:~# chmod -R 755 /ftp/ root@l:~# chown root:root /ftp/ root@l:~#

5、登錄驗證

首先查詢當前容器IP地址:

docker inspect ftp_rw | grep \"IPAddress\"

查詢結果:

root@l:~# docker inspect ftp_rw | grep \"IPAddress\""IPAddress": "172.17.0.2","IPAddress": "172.17.0.2", root@l:~#

創建文件進行驗證:

root@xxzx-PC:~# touch /ftp/t.txt root@xxzx-PC:~# ls /ftp/ 新建文件夾 t.txt root@xxzx-PC:~#

然后在宿主機通過瀏覽器進行訪問驗證:

ftp://172.17.0.2

提示輸入密碼
然后登錄成功

6、上傳驗證

瀏覽器登錄成功之后,我們使用資源管理器進行登錄

ftp://172.17.0.2

提示輸入用戶密碼
然后登錄成功,但是出現了意外現象,此時登錄目錄并不是主目錄

7、限制用戶登錄目錄

7.1、重啟驗證

cd /etc/init.d/ ./vsftpd restart

執行結果:

root@b31e7fa60187:/home/liumou/ftp# cd /etc/init.d/ root@b31e7fa60187:/etc/init.d# ./vsftpd restart [ ok ] Stopping FTP server: vsftpd. [ ok ] Starting FTP server: vsftpd. root@b31e7fa60187:/etc/init.d#

然后再次使用資源管理器進行登錄:

ftp://172.17.0.2

此時,直接進入了我們配置的主目錄,完美結束?No,因為我們是容器部署的,而容器部署的意義則在于一次部署,隨處可用。

8、添加/修改用戶名

如果希望使用其他用戶名進行訪問,那么請根據下面的方法進行配置

8.1、創建用戶

以下操作請進入容器進行,首先輸入下面的命令(沒錯,這是命令)

echo '#!/bin/bash ##add ftp user echo 'please Enter USER name' read user dir=/home/liumou/$user mkdir -p $dir useradd -g ftp -d $dir $user passwd $user chown -R $user:ftp $dir chmod -R 755 $dir' > /add_ftp-user.sh

執行結果:

root@1c75ddedd2f3:~# more /add_ftp-user.sh #!/bin/bash ##add ftp user echo please Enter USER name read user dir=/home/liumou/$user mkdir -p $dir useradd -g ftp -d $dir $user passwd $user chown -R $user:ftp $dir chmod -R 755 $dir cd cd /etc/init.d/ ./vsftpd restart if [[ $? -eq 0 ]];thenecho Modification successful elseecho Modification failed fi root@1c75ddedd2f3:~#

然后執行下面的命令

在這里插入代碼片 bash /add_ftp-user.sh

執行結果:

root@1c75ddedd2f3:~# bash /add_ftp-user.sh please Enter USER name liu New password: Retype new password: passwd: password updated successfully root@1c75ddedd2f3:~#

然后重新訪問ftp,輸入新的用戶名即可

所以你需要先看下面這篇文章:
Docker系列-容器修改后保存為鏡像并導出
上面這篇文章看完之后,相信你已經成功導出鏡像了,那么請看最后一篇吧!
Docker系列-自定義FTP服務Docker鏡像,實現一次部署,隨處可用

總結

以上是生活随笔為你收集整理的使用Docker实现vsftpd配置——用户验证访问上传的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。