1. 程式人生 > >ubuntu 12.04使用vsftpd建立FTP的經驗整理

ubuntu 12.04使用vsftpd建立FTP的經驗整理


如果沒時間去學習vsftpd,想快速配置,則看這個

先大概瞭解下網上的經驗,都是說怎麼配置匿名登入的,但是照著弄沒配置成功,因此改為使用者名稱登入,參考基礎教程

步驟1:建立FTP系統賬戶

在Linux下新建一個ftpuser賬戶,和一個ftp組,並指定賬戶目錄到/home/ftpuser目錄(預設會產生這個路徑,如果你是其它名字,可以通過下面的命令指定directory),

useradd ftpuser

 usermod -s /usr/sbin/nologin -d /home/ftpuser -g ftp ftpuser
此命令將使用者ftpuser的登入Shell改動為nologin,主資料夾改為/home/ftpuser,使用者組改為ftp。

建立rockchip的路徑

[email protected]:/home/ftpuser# mkdir rockchip
[email protected]:/home/ftpuser# ll
total 40
dr-xr-x---  8 ftpuser   ftp  4096 Mar  6 17:23 ./
drwxr-xr-x 14 root      root 4096 Jan 21  2014 ../
-rw-------  1 ftpuser   ftp   419 Jul 11  2013 .bash_history
dr-x------  3 customer  ftp  4096 Jul 11  2013 customer/
dr-x------  3 customer2 ftp  4096 Jul 11  2013 customer_sec/
drwxr-xr-x  2 ftpuser   ftp  4096 Jul 11  2013 for_download_only/
d-wx-wx-wx  2 ftpuser   ftp  4096 Jul 11  2013 for_upload_only/
-rw-r--r--  1 root      root  411 Jul 11  2013 Readme
drwxr-xr-x  2 root      root 4096 Mar  6 17:23 rockchip/
dr-x------  3 ftpuser   ftp  4096 Jul 16  2013 sanshin/

[email protected]:/home/ftpuser# chown rockchip:ftp rockchip/
[email protected]:/home/ftpuser# ll
total 40
dr-xr-x---  8 ftpuser   ftp  4096 Mar  6 17:23 ./
drwxr-xr-x 14 root      root 4096 Jan 21  2014 ../
-rw-------  1 ftpuser   ftp   419 Jul 11  2013 .bash_history
dr-x------  3 customer  ftp  4096 Jul 11  2013 customer/
dr-x------  3 customer2 ftp  4096 Jul 11  2013 customer_sec/
drwxr-xr-x  2 ftpuser   ftp  4096 Jul 11  2013 for_download_only/
d-wx-wx-wx  2 ftpuser   ftp  4096 Jul 11  2013 for_upload_only/
-rw-r--r--  1 root      root  411 Jul 11  2013 Readme
drwxr-xr-x  2 rockchip  ftp  4096 Mar  6 17:23 rockchip/
dr-x------  3 ftpuser   ftp  4096 Jul 16  2013 sanshin/

這樣還不夠,還要作兩步:

1.把rockchip檔案改為500許可權,不然你登入不上去。報這個錯誤:

1.500 OOPS: vsftpd: refusing to run with writable root inside chroot()
Login failed.
--根目錄許可權應該設定為500

2.在rockchip裡面再建一個pub目錄,許可權為700,否則你無法修改pub裡面的內容。

下面是我的三個ftp賬戶的配置(檔案是/etc/passwd)

 
ftpuser:x:1001:133::/home/ftpuser:/usr/sbin/nologin
customer:x:1002:133::/home/ftpuser:/usr/sbin/nologin
customer2:x:1003:133::/home/ftpuser:/usr/sbin/nologin

配置成nologin,使用者就不能用這個帳號登入你的伺服器了,只能登入到指定的路徑下。步驟2就是指定路徑。

ftpuser的許可權配置如下:

GitServer:/home$ ll
total 28
drwxr-xr-x  5   root    root    4096 Jul  9 17:55 ./
drwxr-xr-x 24 root    root    4096 Jul  9 12:04 ../
drwxr-xr-x  3 root    root    4096 Jul  4 00:51 .ecryptfs/
drwx------  2  ftpuser ftp     4096 Jul  9 17:55 ftpuser/
drwx------ 32 norton  norton 12288 Jul  9 17:46 norton/

GitServer:/var/ftp$ ll
total 16
drwxr-xr-x  3 root root 4096 Jul  9 17:32 ./
drwxr-xr-x 15 root root 4096 Jul  9 16:54 ../
-rw-r--r--  1 root root   31 Jul  9 17:32 .message
drwxrwxr-x  3 root ftp  4096 Jul  9 18:10 pub/

步驟2.為不同使用者配置不同的獨立路徑:

1.在/etc/vsftp.config檔案中增加如下內容:


local_root=/home/ftpuser/
user_config_dir=/etc/vsftpd/user_conf

第一行鎖定你的根目錄帳號,預設是/,這樣會讓你伺服器所有檔案都被檢視得到。

作用是使得你可以在/etc/vsftpd/user_conf路徑中,通過增加配置檔案來管理帳號路徑。


步驟3. 為FTP帳號設定登入許可權

3.1 為不同的賬戶設立一個同名的檔案,如下面資訊,我以賬戶名字建立了三個檔案

[email protected]:/etc/vsftpd/user_conf# ls
customer  customer2  ftpuser

3.2 開啟ftpuser檔案,裡面內容如下


[email protected]:/etc/vsftpd/user_conf# vim ftpuser

local_root=/home/ftpuser/sanshin
這樣,ftpuser賬戶就被指定到了sanshin資料夾下。

同時,在/etc目錄下,還要給賬戶許可權:

[email protected]:/etc# vim vsftpd.user_list 

像我這樣一行行的把賬戶名寫進去

ftpuser
customer
customer2
virtual
guest
anonymous

配置好後,重啟以下vsftpd後臺程式

sudo service vsftpd restart

除錯辦法:在命令端測試,例如輸入ftp 192.168.0.3,登入伺服器,然後會提示你輸入使用者名稱,輸入對應的使用者名稱,就可以了。登入進去後,如果不知道命令,可以輸入help。

[email protected]:~/work/gitolite-admin$ ftp 192.168.0.3
Connected to 192.168.0.3.
220-
220-
220-
220-
220-
220-
220-
220-
220-
220-***************************************************
220-*   <Welcome to FTP Server>      *
220-***************************************************
220-
220-
220-
220-
220-
220-
220
Name (192.168.0.3:norton): rockchip



使用到的命令:參照下面的常用命令

常用命令

檢視是否開啟21埠

$ sudo netstat -npltu | grep 21
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      15601/vsftpd    

useradd

passwd

chown 更改檔案擁有者

chmod

touch

rm

mv

mkdir

locate 檢視檔案所在的位置 如locate nologin。具體說明可以man locate看看。

updatedb 如果locate不到安裝過的檔案,就sudo updatedb更新一下資料庫

安全性配置

注意,FTP登入用的賬戶是系統賬戶,但傳輸過程中,密碼是明文的,所以不安全,要限制網路賬戶的shell,使用nologin,則不能用這個帳號登入系統。帳號丟了也不那麼危險。

用sudo許可權開啟/etc/passwd

把網路賬戶的shell改為nologin。我到路徑在/usr/sbin/nologin.

如果不知道,可以輸入locate nologin檢視位置

常見錯誤彙總

1.500 OOPS: vsftpd: refusing to run with writable root inside chroot()
Login failed.
文件許可權應該設定為不可寫--根目錄許可權應該設定為500


2.After following the tutorial and then trying to use FileZilla to copy a file to the home/username/files directory, I was getting this error: open for write:

permission denied
Error: File transfer failed

I got this working by executing: chown username home/username/files

After executing that I was able to copy a test file to the files folder.

3.路徑問題
To see what permissions you have already set for any directory

sudo ls -la /var/www/

Replace "/var/www/" with the directory you need to check!


[email protected]:~$ ftp 14.14.14.14
ftp: connect: Connection refused
一般是vsftpd.conf內容寫錯了,請檢查拼寫錯誤

4.Name (14.14.14.14:dark): customer
331 Please specify the password.
Password:
500 OOPS: missing value in config file for: /home/ftpuser/
Login failed.
421 Service not available, remote server has closed connection

這是因為我只寫了地址
Vsftp.conf檔案配置錯誤。
注意這裡的內容前面不要空格,=號前後不要有空格。
=後面一定要有內容。
否則註釋掉。


5.Name (14.14.14.14:dark): customer
331 Please specify the password.
Password:
500 OOPS: cannot change directory:/home/ftpuser/
Login failed.

不存在這樣到路徑

6. 331 Please specify the password.
Password:
530 Login incorrect.
Login failed.

密碼錯誤,檢視密碼配置檔案是否正確

========================================================================================

【附錄】

如果要深入學習,可以參考

Web資訊

vsftpd主頁是vsftpd.beasts.org。

HOWTO

FTP mini-HOWTO

vsftpd匿名登入

網路上很少提及匿名登入的,可能不安全吧,但是有時候急著搭建FTP,就有必要配置了。

重點是加這個命令 anon_root=/var/run/vsftpd/empty  這個可以自定義,有些系統預設路徑是/var/ftp

這個empty資料夾保持755許可權(許可權不對是進不去的),然後進入裡面建立一個新的資料夾user(名字可以自定義),許可權為777,就可以在這個user下操作

好用的配置

簡介:這個命令可以用來為每個使用者建立單獨的目錄,或者其它許可權和功能設定。

user_config_dir

指定一個目錄,該目錄包含一些以本地使用者的使用者名稱來命名的檔案。每一個這樣的檔案(模仿vsftpd.conf)都包含著一些引數,這些引數覆蓋(根據每個使用者)預設引數以及在vsftpd.conf中指定的引數。舉例來說,假設user_config_dir設定為/etc/vsftpd/user_conf。如果預設的配置檔案(/etc/vsftpd/vsftpd.conf)設定了idlesession_timeout=300,而Sam的個人配置檔案(/etc/vsftpd/user_conf/sam)設定了idlesession_timeout=1200,那麼除了Sam之外,所有使用者的會話無活動超時時間都為300秒,而Sam的會話超時時間為1 200秒。

預設值:無

http://book.51cto.com/art/200810/92809.htm

可以利用這個方法,為不同使用者指定不同到根目錄,。預設情況下,所有登入使用者是用同一個根目錄的(詳情參考後面資訊)。

注意事項

listen

若設定為YES,則會使vsftpd在獨立模式下執行;而若設定為NO,則會使其在普通模式下執行。

如果不懂,就選YES,這是直接啟動vsftpd,如果選了預設到NO,則會經過xinet守護程式按需執行vsftpd,這個還需要其它設定,我照著做一遍,沒成功。

進階配置

學習配置xinet,這是一個提供高安全的超級守護程序,幫助管理各種網路服務,甚至系統服務。

http://wordpress.facesoho.com/server/what-is-xinetd.html


相關推薦

ubuntu 使用vsftpd 建立FTP服務(使用者名稱密碼登入,限制列出目錄)

vsftpd介紹 vsftpd 是“very secure FTP daemon”的縮寫,安全性是它的一個最大的特點。vsftpd 是一個 UNIX 類作業系統上執行的伺服器的名字,它可以執行在諸如 Linux、BSD、Solaris、 HP-

ubuntu 12.04使用vsftpd建立FTP經驗整理

如果沒時間去學習vsftpd,想快速配置,則看這個 先大概瞭解下網上的經驗,都是說怎麼配置匿名登入的,但是照著弄沒配置成功,因此改為使用者名稱登入,參考基礎教程 步驟1:建立FTP系統賬戶 在Linux下新建一個ftpuser賬戶,和一個ftp組,並指定賬戶目錄到

Linux Ubuntu 12.04 下安裝mysql 以及建立 遠端navicat 連線

安裝過程中需要用到的linux 命令: 1:sudo ****   以sudo 開頭的程式碼 表示 是以管理員執行 2:chmod 777 ***(*號代表檔名) 當你不是以ROOT許可權進入Ubuntu 的話 更改檔案配置  需要修改檔案的 許可權級別,777 代表最高

安裝Ubuntu 18.04經驗整理

原裝系統:Windows 10 電腦型號:聯想小新Air 15IKBR 使用教程: 安裝教程 分割槽設定 所有經驗都是基於上述教程,重點在一些小的tips而不是整個安裝過程。 新手上路,所以一些tips可能會看起來很無用。 一、啟動U盤製作 1.為了裝雙系統特地去買了一個32G的U盤,最後發

Linux - Ubuntu中文輸入法安裝(Ubuntu 12.04)

就會 strong end alt con soft 鍵盤 linux 過程 Ubuntu中文輸入法安裝(Ubuntu 12.04)本文地址:http://blog.csdn.net/caroline_wendyUbuntu作為Linux常見的操作系統,是須要熟練使用的。

Ubuntu 12.04 安裝Tomcat7

選擇 ubun 成功 rtu 配置 宋體 pac nload ria 1.下載Tomcat7 打開Tomcat官網 http://tomcat.apache.org,在左邊的導航欄的“Download"中找到Tomcat7.0目錄,點擊後進入Tomcat7的頁面,選擇

制作U盤啟動盤將Ubuntu 12.04升級為14.04的方法

windows ins u盤啟動 live use 版本 radi 啟動盤 ubunt 1 介紹 在周六的下午,我決定想高速瀏覽一下書籍[1]。看看這個關於Ubuntu的聖經到底在講什麽東東。感覺講的不錯,當我看到介紹文件標記語言—TeX和LaTeX的時候,該

Ubuntu 16.04安裝FTP客戶端filezilla

com log ubuntu file 安裝 targe blog clas code 1、安裝: sudo apt-get install filezilla 參考: http://os.51cto.com/art/201103/247564.htmU

Ubuntu 16.04搭建ftp服務器

http con tp服務器 新建 宋體 localhost ftp 用戶 ron Ubuntu 16.04安裝vsftpd 使用下列命令安裝 sudo apt-get install vsftpd 安裝完後,ftp的配置文件在 /etc/vsftpd.conf 可以使用下

Ubuntu 用vsftpd 配置FTP服務器

rdquo 其他 art etc apt-get 文件路徑 ftpd 帳號 服務器 http://www.cnblogs.com/CSGrandeur/p/3754126.html 網上的文章好難懂啊。。只想要簡單粗暴,弄好能用就行啊,復雜的以後研究不行嗎。。。折騰好久,

ubuntu 12 安裝bcm 43142無線網卡驅動

nbsp 成功 less tro 5.1 步驟 blog pool 網卡驅動 轉自:http://blog.csdn.net/u012833250/article/details/52493806 執行以下終端命令:   sudo apt-get install linux

制作ubuntu 12.04鏡像

guest ret 啟動 mod apt virtio figure ssh 錯誤 #啟動UFW防火墻 sudo ufw enable #允許所有的外部IP訪問本機的22/tcp (ssh)端口 sudo ufw allow 22/tcp 在

ubuntu 12.04 簡單配置samba服務,實現主機與虛擬機互通(設置Windows虛擬盤)

完成 sam inux ... conf restart bridged 要求 system 環境: virtualbox ubuntu12.04 首先,如果你到這步了,說明你的window與linux的網絡已經配好了,他們之間是可以互相Ping通的,如果沒有,請看我以

ubuntu服務器安裝FTP服務

介紹 add location pub ise 版本 實現 tin fec ubuntu服務器安裝FTP服務 [TOC] 參考教程 [ubuntu16.04搭建ftp服務器 一、實驗環境 騰訊雲學生機64位ubuntu16.04 騰訊雲已備案解析域名 使用騰訊雲websh

Ubuntu 12.04 之 虛擬主機的配置

剛才 local 創建 apache2 doc 添加 tar -a 連接 Ubuntu 12.04 之 虛擬主機的配置 (1)打開etc/hosts文件 增加: 127.0.0.1 study.ubuntu.com 127.0.0.1 hello.ubuntu.c

實驗12-06 建立新的名為“bookview”的視圖

class nbsp author from edi pre ubd lec date 在Exam數據庫中建立名為“bookview”的視圖,該視圖檢索“出版社A”出版的所有圖書的圖書名稱、作者和出版日期 c

Ubuntu 12.04安裝

openssh ges 定義 chang selection soft str fig figure 在出現的系統安裝窗口中根據需要使用方向鍵選擇相應的語言,在這裏我使用English(如圖4),單擊回車鍵進入下一步 ; 在出現的窗口中選中Install Ubuntu Se

在windows中建立ftp伺服器

大概流程敘述: 1.控制面板-程式-找到開啟或關閉windows功能,找到如下: 2.開啟管理,找到Internet資訊服務管理,建立ftp站點,如下: 3.建立完成後,在本地使用者和組裡面建立新的使用者,預設在user組下面,刪掉如下: 4.找到建立的ftp伺

Ubuntu 12.04.5下配置eclipse + tomcat

一、jre/jdk的安裝 JDK : Java Development ToolKit(Java開發工具包)。包括了JRE JRE:Java  Runtime  Enviromental(java執行時環境)。與JDK相比,它不包含開發工具——編譯器、偵錯程式和其它工具。 J

ubuntu資料夾建立軟連結方法

原文連結:https://blog.csdn.net/jiuyueguang/article/details/9350859 1:預備知識   -s 是代號(symbolic)的意思。   這裡有兩點要注意:第一,ln命令會保持每一處連結檔案的同步性,也就是說,不論你改動了哪一處,其它的檔案