Ubuntu搭建FTP服务器方法

来源:百度文库 编辑:神马文学网 时间:2024/04/19 16:49:24
1系统----系统管理----新立得软件包管理器----搜索(vsftpd)----勾选vsftpd 安装
2 终端----sudo gedit /etc/vsftpd.conf 输入管理密码 去掉26行(local_enable=yes)29行(write_enable=yes)前的"#"保存
3 运行 sudo /etc/init.d/vsftpd restart 重启服务
ubuntu下开设FTP服务器,vsftpd
地狱使者 发表于 2007-9-11 16:32:00
apt-get install vsftpd
或者
apt-get install proftpd
或者
apt-get install pureftpd
参考下文:设置vsftpd
*********************************************************
发信人: alabaster(春天来了), 信区: Linux
标  题: debian做ftp服务器
发信站: 瀚海星云 (2006年03月24日15:41:39 星期五), 站内信件
修改ip地址
编辑 /etc/network/interfaces 文件,用 sudo vi /etc/network/i
nterfaces,修改 IP 地址。
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# This is a list of hotpluggable network interfaces.
# They will be activated automatically by the hotplug subsystem.
mapping hotplug
script grep
map eth0
# The primary network interface
auto eth0
iface eth0 inet static
address 202.38.??.??
netmask 255.255.255.0
network 202.38.??.??
broadcast 202.38.??.??
gateway 202.38.??.??
编辑 /etc/hosts 这个文件并且把新IP地址加进去,用 sudo vi /etc/hosts
127.0.0.1       localhost.localdomain   localhost       userftp
202.38.??.??   ???.ustc.edu.cn          userftp
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
编辑 /etc/hostname,内容改为 ???.ustc.edu.cn
/etc/init.d/networking restart 重新启动网络。
安装 SSH
apt-get install ssh openssh-server
现在可以通过其他电脑
ssh .??.??
来远程管理服务器了。
安装vsftp
apt-get install vsftpd
配置/etc/vsftpd/vsftpd.conf
以下是我的vsftpd.conf内容
===============================================================
#服务器以standalong模式运行,这样可以进行下面的控制
listen=YES
#接受匿名用户
anonymous_enable=YES
#匿名用户login时不询问口令
no_anon_password=YES
# 接受本地用户
local_enable=YES
# 可以上传(全局控制).若想要匿名用户也可上传则需要设置anon_upload_enable=YES,
# 若想要匿名用户可以建立目录则需要设置anon_mkdir_write_enable=YES.这里禁止匿
# 名用户上传,所以不设置这两项.
write_enable=YES
#本地用户上传文件的umask
local_umask=022
#如果设为YES,匿名登入者会被允许上传目录的权限,当然,匿名使用者必须要有对
#上层目录的写入权。
anon_upload_enable=YES
#定义匿名登入的使用者名称。默认值为ftp
ftp_username=ftp
#如果设为YES,匿名登入者会被允许新增目录,当然,匿名使用者必须要有对上层
#目录的写入权。
anon_mkdir_write_enable=YES
# 为YES则进入目录时显示此目录下由message_file选项指定的文本文件(,默认为.messa
ge)的内容
dirmessage_enable=YES
#本地用户login后所在目录,若没有设置此项,则本地用户login后将在他的home目录
#(/etc/passwd的第六个字段)中.匿名用户的对应选项是anon_root
#local_root=/home
anon_root=/home/ftp/
# 使用上传/下载日志,日志文件默认为/var/log/vsftpd.log,可以通过xferlog_file选
项修改
xferlog_enable=YES
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#日志使用标准xferlog格式
xferlog_std_format=YES
# You may change the default value for timing out a data connection.
data_connection_timeout=120
# 关闭本地用户chroot()
chroot_local_user=NO
#设置为yes则下面的控制有效。
#开启要设置chroot()用户项.
chroot_list_enable=YES
# (default follows)
#指定要设置chroot()的特定用户文件
chroot_list_file=/etc/vsftpd.chroot_list
#若设置为YES则记录在userlist_file选项指定文件(默认是/etc/vsftpd.user_list)中
的用
#户无法login,并且将检察下面的userlist_deny选项
userlist_enable=YES
#若为NO,则仅接受记录在userlist_file选项指定文件(默认是/etc/vsftpd.user_list)
中的
#用户的login请求.若为YES则不接受这些用户的请求.
userlist_deny=NO
#注意!!!vsftpd还要检察/etc/vsftpd.ftpusers文件,记录在这个文件中的用户将无法lo
gin!!
#匿名用户的传输比率(b/s)
anon_max_rate=512000
#本地用户的传输比率(b/s)
local_max_rate=1024000
#可接受的最大client数目
max_clients=100
#每个ip的最大client数目
max_per_ip=5
# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd
#
# This string is the name of the PAM service vsftpd will use.
pam_service_name=vsftpd
tcp_wrappers=YES
#
# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
# 每一个联机,都能以独立的process 来呈现.
setproctitle_enable=YES
#若是启动,所有匿名上传数据的拥有者将被更换为chown_username
#当中所设定的使用者。这样的选项对于安全及管理,是很有用的。
chown_uploads=YES
#这里可以定义当匿名登入者上传档案时,该档案的拥有者将被置换的
#使用者名称。预设值为root。
chown_username=root
====================================================================
增加用户名一堆(都属于ftpuser组的)
groupadd ftpuser
mkdir /home/john/
useradd -g ftpuser john
passwd john
更改文件所有者以及权限
chown -v -R john.ftpuser /home/john/
chmod -v -R 700 /home/john/
给ftpuser组所有用户共享一个文件夹,做一个连接
ln -v -s /home/ftpuser/ /home/john/ftpuser
在每个用户的文件夹中设置.message
做欢迎界面
编辑/etc/vsftpd.user_list
列举所有的用户列表。
编辑/etc/vsftpd.chroot_list
填写不准进入上层目录的用户名
给/home/ftp/中允许匿名写的目录修改权限。
chmod -v 777 /home/ftp/temp/
做两个定时工作
crontab -e
在里面写
0 4 * * 1 rm -rf /home/ftp/incoming/temp/*
# 每星期一凌晨4点清空/home/ftp/incoming/temp/文件夹
0 5 10 * * /sbin/reboot
# 每个月10日凌晨5点重新启动电脑
如何把用户限制在家目录中呢?
我们要自己建一个文件,在/etc目录中
#touch /etc/vsftpd.chroot_list
以beinan这个用户为例
在vsftpd.chroot_list这个文件中,把beinan添上去就行。
然后改/etc/vsftpd/vsftpd.conf文件,找如下的两行
#chroot_list_enable=YES
#chroot_list_file=/etc/vsftpd.chroot_list
把前面的#号去掉,也就是这样的
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
如果没有这样的两行,就可以自己添加上去也是一样的。
设置好后,重新vsFTPD服务器。
reboot或者重启vsftpd
好了,ftp服务器架构完成了。
************************************************************************
参考:
ubuntu下如何利用proftpd构架一个ftp服务器
1- 使用下面的命令安装proftpd:
sudo apt-get install proftpd
2- 在etc/shells 加入如下代码 (sudo gedit /etc/shells to open the file)(译注:命令行模式下sudo vi /etc/shells) :
/bin/false
新建一个 /home/FTP-shared 目录 :
cd /home
sudo mkdir FTP-shared
创建一个只能用来读取ftp的用户userftp. 这个用户不需要有效的shell(更安全) ,所以选择 /bin/false shell 给 userftp , /home/FTP-shared 作为主目录.
为了是这部分更清楚,我给取此操作的命令行:
sudo useradd userftp -p your_password -d /home/FTP-shared -s /bin/false
在FTP-shared 目录下新建一个download和一个upload 目录:
cd /home/FTP-shared/
sudo mkdir download
sudo mkdir upload
现在我们来给它们设置相应的权限:
cd /home
sudo chmod 755 FTP-shared
cd FTP-shared
sudo chmod 755 download
sudo chmod 777 upload
3- 好了,现在进入proftpd的配置文件:
sudo gedit /etc/proftpd.conf
当然你可以按你的需要编辑你自己的proftpd.conf:
# To really apply changes reload proftpd after modifications.
AllowOverwrite on
AuthAliasOnly on
# Choose here the user alias you want !!!!
UserAlias sauron userftp
ServerName   "ChezFrodon"
ServerType    standalone
DeferWelcome   on
MultilineRFC2228 on
DefaultServer   on
ShowSymlinks   off
TimeoutNoTransfer 600
TimeoutStalled 100
TimeoutIdle 2200
DisplayFirstChdir               .message
ListOptions                 "-l"
RequireValidShell   off
TimeoutLogin 20
RootLogin    off
# It's better for debug to create log files ;-)
ExtendedLog    /var/log/ftp.log
TransferLog    /var/log/xferlog
SystemLog   /var/log/syslog.log
#DenyFilter   \*.*/
# I don't choose to use /etc/ftpusers file (set inside the users you want to ban, not useful for me)
UseFtpUsers off
# Allow to restart a download
AllowStoreRestart  on
# Port 21 is the standard FTP port, so don't use it for security reasons (choose here the port you want)
Port    1980
# 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 8
# Set the user and group that the server normally runs at.
User                  nobody
Group                 nogroup
# Umask 022 is a good standard umask to prevent new files and dirs
# (second parm) from being group and world writable.
Umask    022 022
PersistentPasswd  off
MaxClients 8
MaxClientsPerHost 8
MaxClientsPerUser 8
MaxHostsPerUser 8
# Display a message after a successful login
AccessGrantMsg "welcome !!!"
# This message is displayed for each access good or not
ServerIdent                  on       "you're at home"
# Set /home/FTP-shared directory as home directory
DefaultRoot /home/FTP-shared
# Lock all the users in home directory, ***** really important *****
DefaultRoot ~
MaxLoginAttempts    5
#VALID LOGINS

AllowUser userftp
DenyALL


Umask 022 022
AllowOverwrite off

DenyAll



Umask 022 022
AllowOverwrite off

DenyAll


/home/FTP-shared/upload/>
Umask 022 022
AllowOverwrite on

DenyAll


AllowAll


好了,你已经完成了proftpd的配置,你的服务端口是1980,而读取的参数如下,用户:sauron,密码:你为userftp设置的那个.
4- 启动/停止/重启动你的服务:
sudo /etc/init.d/proftpd start
sudo /etc/init.d/proftpd stop
sudo /etc/init.d/proftpd restart
对你的proftpd进行一下语法检查:
sudo proftpd -td5
想知道谁现在连接到你的服务,用ftptop命令(使用字母”t”来转换显示频率),你也可以使用”ftpwho”命令
备注:我自己配置的时候,只是把匿名的取消了,然后把本地用户打开了,不过,现在我发现了一个问题,就是当我想把我自己上传的文件,给另外一个用户的时候,就有点问题了.