<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>FTP Server &#8211; 記下來</title>
	<atom:link href="https://noter.tw/tag/ftp-server/feed/" rel="self" type="application/rss+xml" />
	<link>https://noter.tw</link>
	<description>一路上踩到的坑、遇到的問題，一點一滴記下來，希望能幫助到需要的人~</description>
	<lastBuildDate>Wed, 14 Dec 2022 14:22:52 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.3</generator>

<image>
	<url>https://noter.tw/wp-content/uploads/cropped-old-1130742_1920-1-32x32.jpg</url>
	<title>FTP Server &#8211; 記下來</title>
	<link>https://noter.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Ubuntu 安裝及設定 vsftp</title>
		<link>https://noter.tw/10572/ubuntu-%e5%ae%89%e8%a3%9d%e5%8f%8a%e8%a8%ad%e5%ae%9a-vsftp/</link>
					<comments>https://noter.tw/10572/ubuntu-%e5%ae%89%e8%a3%9d%e5%8f%8a%e8%a8%ad%e5%ae%9a-vsftp/#respond</comments>
		
		<dc:creator><![CDATA[黃小蛙]]></dc:creator>
		<pubDate>Wed, 14 Dec 2022 14:22:51 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[技術相關]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[FTP Server]]></category>
		<category><![CDATA[VSFTPD]]></category>
		<category><![CDATA[FTP 架設]]></category>
		<guid isPermaLink="false">https://noter.tw/?p=10572</guid>

					<description><![CDATA[<p>好久沒有設定 FTP 了，最近遇到需要架設 FTP 的情況，這篇文章參考自：How to Setup FTP Server with VSFTPD on Ubuntu 20.04，小蛙把自己實際使用流程記錄下來。</p>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/10572/ubuntu-%e5%ae%89%e8%a3%9d%e5%8f%8a%e8%a8%ad%e5%ae%9a-vsftp/" data-wpel-link="internal">Ubuntu 安裝及設定 vsftp</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>好久沒有設定 FTP 了，最近遇到需要架設 FTP 的情況，這篇文章參考自：<a href="https://linuxize.com/post/how-to-setup-ftp-server-with-vsftpd-on-ubuntu-20-04/" target="_blank" rel="noopener nofollow external noreferrer" data-wpel-link="external" class="wpel-icon-right">How to Setup FTP Server with VSFTPD on Ubuntu 20.04<span class="wpel-icon wpel-image wpel-icon-6"></span></a>，小蛙把自己實際使用流程記錄下來。</p>



<span id="more-10572"></span>



<p>小蛙收到的需求是要架設 FTP Sever ，建立一個特定使用帳號，並將該帳號的家目錄設定在特定路徑下，該文章完全符合小蛙的需求，照著做之後把過程中文化並記錄下來，開始吧！</p>



<h2 class="para wp-block-heading">安裝 vsftp</h2>



<p>這邊使用較輕巧且設定簡單的 vsftp，透過以下指令進行安裝</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">sudo apt update
sudo apt install vsftpd</pre>



<p>安裝完成後可輸入<code>systemctl status vsftpd</code>查看是否正常安裝及運作</p>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEV3AgG8GoL9_WGoPcykIL-ymilahtGTXvqcfUXeNM0LEoixhPME-Vz3llgaX1xKm2hhcZcMBKYOap-BgzQAqQ-rmeW9ooWA_Nowtss-iNLwed2kYzd4h0B-TXSts0qVhHtN6zA21SAV5NqYVaXWeDuH=w2585-h570-no?authuser=2" alt="AL9nZEV3AgG8GoL9 WGoPcykIL ymilahtGTXvqcfUXeNM0LEoixhPME Vz3llgaX1xKm2hhcZcMBKYOap BgzQAqQ rmeW9ooWA Nowtss iNLwed2kYzd4h0B TXSts0qVhHtN6zA21SAV5NqYVaXWeDuH=w2585 h570 no?authuser=2 Ubuntu 安裝及設定 vsftp" title="Ubuntu 安裝及設定 vsftp"></figure></div>


<h2 class="para wp-block-heading">設定 vsftp</h2>



<p>vsftp 的設定檔在<code>/etc/vsftpd.conf</code>，小蛙這邊將進行以下 5 項設定，第 6 項傳輸加密部份因為沒有要用到，這邊就不另外提了。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">sudo vim /etc/vsftpd.conf</pre>



<h3 class="para wp-block-heading">1. 存取限制</h3>



<p>設定禁止匿名者登入，以及本地帳號皆可使用</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">anonymous_enable=NO
local_enable=YES</pre>



<h3 class="para wp-block-heading">2. 允許上傳</h3>



<p>若要讓使用者上傳檔案，須將以下設定開啟</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">write_enable=YES</pre>



<h3 class="para wp-block-heading">3. 限制目錄切換</h3>



<p>基於安全性問題，想將使用者限制在特定區域，避免有心人士的非法行為，加上以下這兩項設定</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">chroot_local_user=YES
allow_writeable_chroot=YES</pre>



<h3 class="para wp-block-heading">4. 被動連線 (PASV)</h3>



<p>FTP Server 可以設定 (1) <strong>主動模式</strong> 及 (2) <strong>被動模式</strong>，在設定檔加入<code>pasv_min_port</code>及<code>pasv_max_port</code>兩個參數可限縮被動模式使用的 port 區間。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>兩種模式各有優缺點，主動模式對伺服器來說比較安全，但對用戶端來說卻是可能帶來危險，因此很可能被用戶端的防火牆所阻擋了。使用被動模式雖然解決了用戶端的問題，但相對的伺服器必須開啟一定範圍的通訊埠供用戶端連線，好在目前絕大部分的 FTP 伺服器軟體，皆可以由管理者決定開啟哪些範圍的通訊埠。</p><cite><a href="https://matis.pixnet.net/blog/post/22918494" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">FTP 主動模式與被動模式<span class="wpel-icon wpel-image wpel-icon-6"></span></a></cite></blockquote>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">pasv_min_port=30000
pasv_max_port=31000</pre>



<h3 class="para wp-block-heading">5. 限制登入</h3>



<p>除了上面設定的本機使用者可以登入外，也可以使用下面這些設定，僅讓清單上的使用者登入 FTP，我們將設定檔放在<code>/etc/vsftpd.user_list</code>內，檔案內一行為一個使用者帳號</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
userlist_deny=NO</pre>



<h3 class="para wp-block-heading">6. 傳輸加密</h3>



<p>小蛙這次設定沒有要用到，可參考<a href="https://linuxize.com/post/how-to-setup-ftp-server-with-vsftpd-on-ubuntu-20-04/" target="_blank" rel="noreferrer noopener nofollow external" data-wpel-link="external" class="wpel-icon-right">原文<span class="wpel-icon wpel-image wpel-icon-6"></span></a>進行設定。</p>



<h2 class="para wp-block-heading">設定防火牆</h2>



<p>設定好 vsftp 之後，安全起見還是要把防火牆設定起來，FTP 需要開啟 port 20, port 21 以及上面設定的被動模式 port 區間</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">sudo ufw allow 20:21/tcp
sudo ufw allow 30000:31000/tcp</pre>



<h2 class="para wp-block-heading">建立及設定 FTP 使用者</h2>



<p>剛剛我們設定了只有<code>/etc/vsftpd.user_list</code>清單上的使用者才可以登入 FTP，現在就來新增一個 FTP 專用帳號</p>



<h3 class="para wp-block-heading">1. 新增使用者</h3>



<p>使用<code>adduser</code>建立一個使用者 <strong>newftpuser</strong> (帳號換成自己要的)，並且把該使用者加入到允許登入清單中</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">sudo adduser newftpuser
echo "newftpuser" | sudo tee -a /etc/vsftpd.user_list</pre>



<h2 class="para wp-block-heading">禁止 Shell 登入</h2>



<p>由於只想讓該帳號使用 FTP 的功能，不希望該帳號透過 SSH 的方式登入進主機，新增一個名為 ftponly 的 Shell</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">echo -e '#!/bin/sh\necho "This account is limited to FTP access only."' | sudo tee -a  /bin/ftponly
sudo chmod a+x /bin/ftponly</pre>



<p>將我們建立的<code>/bin/ftponly</code>加入到 shell 清單中</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">echo "/bin/ftponly" | sudo tee -a /etc/shells</pre>



<p>接著把 newftpuser 的 shell 指定為<code>/bin/ftponly</code></p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">sudo usermod newftpuser -s /bin/ftponly</pre>



<p>完成後如果嘗試使用該帳號登入 SSH，就會看到以下訊息 ~</p>


<div class="wp-block-image">
<figure class="aligncenter size-large is-resized"><img decoding="async" src="https://lh3.googleusercontent.com/pw/AL9nZEV2P6iHyGzhhoM3cYHRI4fKRncPUuLSCN2BKdVtY4uU3EKP7Lr1ugBZMF9YxX46KlpWUkzupDWKPlBVY_OJkhsQ9ei6sPmZjQytTaHh6uAp-6as18oigcFpIbBPUJEWXLPYgZAugbXJN_aR5k59X3Qf=w1499-h523-no?authuser=2" alt="AL9nZEV2P6iHyGzhhoM3cYHRI4fKRncPUuLSCN2BKdVtY4uU3EKP7Lr1ugBZMF9YxX46KlpWUkzupDWKPlBVY OJkhsQ9ei6sPmZjQytTaHh6uAp 6as18oigcFpIbBPUJEWXLPYgZAugbXJN aR5k59X3Qf=w1499 h523 no?authuser=2 Ubuntu 安裝及設定 vsftp" width="375" height="131" title="Ubuntu 安裝及設定 vsftp"></figure></div>


<p>打完收工！同場加映，因為小蛙還要重新設定使用者家目錄，透過以下指令即可完成。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="bash" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">sudo usermod -d /my/new/path newftpuser</pre>
<p>這篇文章 <a rel="nofollow" href="https://noter.tw/10572/ubuntu-%e5%ae%89%e8%a3%9d%e5%8f%8a%e8%a8%ad%e5%ae%9a-vsftp/" data-wpel-link="internal">Ubuntu 安裝及設定 vsftp</a> 最早出現於 <a rel="nofollow" href="https://noter.tw" data-wpel-link="internal">記下來</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://noter.tw/10572/ubuntu-%e5%ae%89%e8%a3%9d%e5%8f%8a%e8%a8%ad%e5%ae%9a-vsftp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
