<?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>琪埃信息系统（上海）有限公司 &#187; FTP</title>
	<atom:link href="http://www.qiais.com/achives/category/ftp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.qiais.com</link>
	<description>琪埃信息系统</description>
	<lastBuildDate>Tue, 11 Feb 2020 01:50:29 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0</generator>
	<item>
		<title>Linux(CentoOS)上安装ftp服务器，并且设置ssl安全链接</title>
		<link>http://www.qiais.com/achives/732/</link>
		<comments>http://www.qiais.com/achives/732/#comments</comments>
		<pubDate>Tue, 15 Jul 2014 02:15:21 +0000</pubDate>
		<dc:creator><![CDATA[sai]]></dc:creator>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[FTP]]></category>

		<guid isPermaLink="false">http://www.qiais.com/?p=732</guid>
		<description><![CDATA[FTP服务器虽然不是很安全，又很消耗带宽，但某些时候还是有必要安装的，特别是当我们的客户对网络不是很熟悉的时候...]]></description>
				<content:encoded><![CDATA[<p>FTP服务器虽然不是很安全，又很消耗带宽，但某些时候还是有必要安装的，特别是当我们的客户对网络不是很熟悉的时候，<br />
架设一台服务器很方便客户将文件上chuang</p>
<p>CentOS上安装FTP不是一件很难的事，但是需要加强服务器的安全，防止用户名与密码被盗。</p>
<p>1. 安装vsftpd</p>
<pre class="brush: plain; title: ; notranslate"># yum -y install vsftpd</pre>
<p>2.配置vsftpd.conf</p>
<pre class="brush: plain; title: ; notranslate">
# vi /etc/vsftpd/vsftpd.conf
</pre>
<pre class="brush: plain; title: ; notranslate">
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO　←　禁止anonymous（匿名）用户登录

# Activate logging of uploads/downloads.
xferlog_enable=YES　←　/var/log/vsftpd.log 启动连接，传送日志

# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log　←　日志文件为 /var/log/vsftpd.log

# If you want, you can have your log file in standard ftpd xferlog format
xferlog_std_format=NO　←　/var/log/vsftpd.log 设置日志格式

local_enable=YES
local_root=public_html ←　设置用户只能看到自己目录的public_html目录下的内容

# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command &quot;SIZE /big/file&quot; in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
ascii_upload_enable=YES　←　允许ascii模式上传
ascii_download_enable=YES　←　允许ascii模式下载

# You may fully customise the login banner string:
ftpd_banner=Welcome to blah FTP service.　←　登录FTP时隐藏软件名称以及版本号

# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_local_user=YES　←　限制用户只能在自己的目录下上传下载
chroot_list_enable=YES　←　允许chroot_list用户可以越过自己的目录
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list　←　chroot_list文件路径

# You may activate the &quot;-R&quot; option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as &quot;ncftp&quot; and &quot;mirror&quot; assume
# the presence of the &quot;-R&quot; option, so there is a strong case for enabling it.
ls_recurse_enable=YES　←　允许文件夹上传下载

#添加以下
use_localtime=YES　←　设置ftp显示时间为当地时间
pasv_addr_resolve=YES
pasv_address=shintoku-town.net
pasv_min_port=60000　←　PASV模式最小端口号
pasv_max_port=60030　←　PASV模式最大端口号
ssl_enable=YES　←　SSL有效
rsa_cert_file=/etc/ssl/private/vsftpd.pem　←　ssl证书
rsa_private_key_file=/etc/ssl/private/vsftpd.pem　←　ssl证书
force_local_logins_ssl=YES　←　强制SSL登录
force_local_data_ssl=YES　←　强制通过SSL进行文件传输

ssl_tlsv1=YES
ssl_sslv2=YES
ssl_sslv3=YES

require_ssl_reuse=NO
ssl_ciphers=HIGH    ← 使支持 DES-CSC3-SHA
</pre>
<p>3.添加可超越自己目录的用户(这里为qiais)</p>
<pre class="brush: plain; title: ; notranslate"># echo qiais &gt;&gt; /etc/vsftpd/chroot_list</pre>
<p>4.禁止某些用户登录ftp服务器，这里禁止sai用户登录服务器</p>
<pre class="brush: plain; title: ; notranslate">echo sai &gt;&gt; /etc/vsftpd/ftpusers</pre>
<p>5.生成服务器证书</p>
<pre class="brush: plain; title: ; notranslate"> # mkdir /etc/ssl/private </pre>
<pre class="brush: plain; title: ; notranslate">
[root@centos certs]
# openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout /etc/ssl/private/vsftpd.pem -out /etc/ssl/private/vsftpd.pem　←　生成证书
umask 77 ; \
PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
/usr/bin/openssl req -utf8 -newkey rsa:1024 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 -set_serial 0 ; \
cat $PEM1 &gt;  vsftpd.pem ; \
echo &quot;&quot;    &gt;&gt; vsftpd.pem ; \
cat $PEM2 &gt;&gt; vsftpd.pem ; \
rm -f $PEM1 $PEM2
Generating a 1024 bit RSA private key
.................................++++++
................................++++++
writing new private key to '/tmp/openssl.OH7090'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [GB]:CN　←　国家名
State or Province Name (full name) [Berkshire]:Shanghai　←　省市
Locality Name (eg, city) [Newbury]:Pudongxinqu　←　区
Organization Name (eg, company) [My Company Ltd]:Qiai　←　单位名称
Organizational Unit Name (eg, section) []:　←　空ENTER
Common Name (eg, your name or your server's hostname) []:ftp.qiais.com　←　主机名
Email Address []:user01@qiais.com
</pre>
<p>6. 连接测试<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; 从这开始为旧内容，不需要SSL的 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
 MAC电脑可以通过以下命令连接测试服务器</p>
<pre class="brush: plain; title: ; notranslate">
mac:~ sai$ ftp   ← 启动ftp
ftp&gt; open client.hanbai.jp    ← 连接ftp服务器
Connected to client.hanbai.jp.
220 Welcome to blah FTP service.
Name (client.hanbai.jp:sai): client  ←  用户名
331 Please specify the password.
Password:                            ← 密码
230 Login successful.                ← 成功登录  
Remote system type is UNIX.
Using binary mode to transfer files.
ftp&gt; 
</pre>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; 旧内容到此结束 &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>为了测试SSL的连接，我们需要安装 <a href="https://filezilla-project.org/" target="_blank">FileZilla</a></p>
<p>设置连接信息如下：<br />
<a href="http://www.qiais.com/wp-content/uploads/2014/07/file.png"><img src="http://www.qiais.com/wp-content/uploads/2014/07/file-600x325.png" alt="file" width="600" height="325" class="alignnone size-medium wp-image-741" /></a></p>
<p>点击连接后会弹出证书确认窗口，点击OK就可以，</p>
<p>成功连接后的界面如下：<br />
<a href="http://www.qiais.com/wp-content/uploads/2014/07/file2.png"><img src="http://www.qiais.com/wp-content/uploads/2014/07/file2-600x410.png" alt="file2" width="600" height="410" class="alignnone size-medium wp-image-742" /></a></p>
<p>上面我们可以看到连接头部的ftpes://****@*****<br />
表明我们的通过SSL连接的FTP服务器连接成功！</p>
<p>7. 附注说明</p>
<p>   1)确保21端口开放</p>
<p>   2)500 OOPS: cannot change directory:/home/***   错误，基本是由于CentOS的安全保护程序Selinux的缘故，可以通过停止Selinux保护</p>
<pre class="brush: plain; title: ; notranslate"># setenforce 0</pre>
<p>或者直接修改配置文件，使seliunx无效</p>
<pre class="brush: plain; title: ; notranslate">
# vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing　　　← 将 SELINUX=disabled 
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
</pre>
<p>如果不想停止selinux保护，也可以让sellinux允许ftp_home_dir</p>
<pre class="brush: plain; title: ; notranslate">
[root@test ~]# getenforce
Enforcing
[root@test ~]# getsebool -a | grep ftp
allow_ftpd_anon_write --&gt; off
allow_ftpd_full_access --&gt; off
allow_ftpd_use_cifs --&gt; off
allow_ftpd_use_nfs --&gt; off
ftp_home_dir --&gt; off
ftpd_connect_db --&gt; off
ftpd_use_passive_mode --&gt; off
httpd_enable_ftp_server --&gt; off
tftp_anon_write --&gt; off
[root@test ~]# setsebool -P ftp_home_dir on　　　← 通过 setsebool 命令，修改 ftp_home_dir 的 off 为 on
[root@test ~]# getsebool -a | grep ftp
allow_ftpd_anon_write --&gt; off
allow_ftpd_full_access --&gt; off
allow_ftpd_use_cifs --&gt; off
allow_ftpd_use_nfs --&gt; off
ftp_home_dir --&gt; on
ftpd_connect_db --&gt; off
ftpd_use_passive_mode --&gt; off
httpd_enable_ftp_serve
</pre>
<p>3) 只显示文件夹，没显示文件的情况<br />
  这种情况很有可能使Selinux保护的原因，我们可以先将Selinux停止再测试</p>
]]></content:encoded>
			<wfw:commentRss>http://www.qiais.com/achives/732/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
