VMware – Linux – 外部使用 FTP 傳送檔案到虛擬伺服器

例如我在 Windows 寫 PHP,存檔後會傳送到 VMware 的虛擬機 CentOs 的 Server (算是我的 Linux 測試環靜),存檔傳輸希望透過 FTP 傳送。

XAMPP 安裝的 FTP 套件是 ProFTPD,打開使用者的設定檔路徑『/opt/lampp/etc/proftpd.conf』,可以看到下面的內容

# This is a basic ProFTPD configuration file (rename it to 
# 'proftpd.conf' for actual use.  It establishes a single server
# and a single anonymous login.  It assumes that you have a user/group
# "daemon" and "ftp" for normal operation and anon.

ServerName			"ProFTPD"
ServerType			standalone
DefaultServer			on

# Port 21 is the standard FTP port.
Port				21          <-- FTP 的 PORT,不用改
# Umask 022 is a good standard umask to prevent new dirs and files
# from being group and world writable.
Umask				022

# To prevent DoS attacks, set the maximum number of child processes
# to 30.  If you need to allow more than 30 concurrent connections
# at once, simply increase this value.  Note that this ONLY works
# in standalone mode, in inetd mode you should use an inetd server
# that allows you to limit maximum number of processes per service
# (such as xinetd)
MaxInstances			30

# Set the user and group that the server normally runs at.
User daemon          <-- 使用者,預設叫做 daemon ,若改成你自訂的名稱,下面密碼對應的也要改
#Group daemon

# Normally, we want files to be overwriteable.
<Directory /opt/lampp/htdocs/*> 
  AllowOverwrite		on
</Directory>

# only for the web servers content
DefaultRoot /opt/lampp/htdocs

<Limit SITE_CHMOD>                                                                                                                                                         
  DenyAll                                                                                                                                                                  
</Limit>  

# daemon gets the password "xampp"          <-- 他告訴你預設密碼是 xampp
UserPassword daemon 2TgxE8g184G9c           <-- 這裡的 2TgxE8g184G9c 是 xampp 加密過後字串,登入記得不是用它輸入密碼,若要更換密碼,參考下面註解(1

# daemon is no normal user so we have to allow users with no real shell
RequireValidShell off

# daemon may be in /etc/ftpusers so we also have to ignore this file
UseFtpUsers off

所以從設定檔得到 FTP 資訊是

  • host: 192.168.1.103:21 (IP 由虛擬機分配到的)
  • user: daemin
  • password: xampp

如果要讓使用者可以透過 FTP 修改檔案路徑權限,那就

<Limit SITE_CHMOD>                                                                       
  #DenyAll      <-- 改為註解                                                            
  AllowAll      <-- 添加允許使用 chmod 修改權限
</Limit>

參考關於 Limit 設定的官方說明

改好以後,我們確實可以從實體接透過 FTP 登入虛擬機的路徑 /opt/lampp/htdocs,但這時候不具有任何權限。所以我們要記得修改 /opt/lampp/htdocs 的權限。因為我是拿來自己連線 (架在 VMware 當作開發環境),所以帳號密碼我使用原本的,沒再做修改。但是,建議建立一個 FTP 專用的用戶,並指定該 FTP 使用者有一個專屬的家目錄。

建立使用者群組

自訂一個用戶群組名稱叫做 myteam
# groupadd myteam

建立使用者目錄、用戶、密碼

建立目錄 /opt/lampp/htdocs/myproject
# mkdir /opt/lampp/htdocs/myproject

修改目錄 /opt/lampp/htdocs/myproject 的權限為 777
# chmod -R 777 /opt/lampp/htdocs/myproject

在目錄 /opt/lampp/htdocs/myproject 增加群組 myteam 與用戶 jason
# useradd -d /opt/lampp/htdocs/myproject -g myteam -s /sbin/nologin jason

設定用戶 jason 密碼
# passwd jason

修改完記得重啟 ProFTPD,或是整個 xampp 重啟也可以。

# /opt/lampp/lampp restart

註解 1 ) 如果要更換 ProFTPD 的密碼,有2種方式,一種是直接修改文件,如前往密碼產生器 http://www.kxs.net/support/htaccess_pw.html ,輸入預設帳號 daemon、自訂密碼,按下送出後會得到加密過後的密文,把它替換掉即可。第二種是裝好 XAMPP 時就先做 XAMPP 安全設定

Comments

發表迴響