centos ftp的开通

如果没有安装 vsftpd

sudo yum install ftp vsftpd

设置开机启动

chkconfig vsftpd on

设定ftp主目录和用户名

sudo useradd -d 规定的目录 -s /sbin/nologin 用户名

修改密码

passwd 用户名

修改配置文件

sudo vim /etc/vsftpd/vsftpd.conf

对应修改

# 是否运行匿名登录(NO)
  2 anonymous_enable=NO
  3 # 是否允许本地用户登录
  4 local_enable=YES
  5 # 允许ftp的任何写方式
  6 write_enable=YES
  7 # 文件创建只有的权限是755=(777-022)
  8 local_umask=022
  9 # 是否允许匿名用户上传文件
 10 #anon_upload_enable=YES
 11 # 是否允许匿名用户创建文件或者删除文件
 12 #anon_mkdir_write_enable=YES
 13 # 用户进入目录信息提示
 14 dirmessage_enable=YES
 15 # 是否允许vsftp的日志
 16 xferlog_enable=YES
 17 # Make sure PORT transfer connections originate from port 20 (ftp-data).
 18 connect_from_port_20=YES
 19 #
 20 #chown_uploads=YES
 21 #chown_username=whoever
 22 # 日志文件的路径
 23 xferlog_file=/var/log/xferlog
 24 # 日志文件的格式
 25 xferlog_std_format=YES
 26 #
 27 #idle_session_timeout=600
 28 #
 29 #data_connection_timeout=120
 30 #
 31 # It is recommended that you define on your system a unique user which the
 32 # ftp server can use as a totally isolated and unprivileged user.
 33 #nopriv_user=ftpsecure
 34 #
 35 # Enable this and the server will recognise asynchronous ABOR requests. Not
 36 # recommended for security (the code is non-trivial). Not enabling it,
 37 # however, may confuse older FTP clients.
 38 #async_abor_enable=YES
 39 #
 40 # By default the server will pretend to allow ASCII mode but in fact ignore
 41 # the request. Turn on the below options to have the server actually do ASCII
 42 # mangling on files when in ASCII mode.
 43 # Beware that on some FTP servers, ASCII support allows a denial of service
 44 # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
 45 # predicted this attack and has always been safe, reporting the size of the
 46 # raw file.
 47 # ASCII mangling is a horrible feature of the protocol.
 48 #ascii_upload_enable=YES
 49 #ascii_download_enable=YES
 50 #
 51 # You may fully customise the login banner string:
 52 #ftpd_banner=Welcome to blah FTP service.
 53 #
 54 # You may specify a file of disallowed anonymous e-mail addresses. Apparently
 55 # useful for combatting certain DoS attacks.
 56 #deny_email_enable=YES
 57 # (default follows)
 58 #banned_email_file=/etc/vsftpd/banned_emails
 59 #
 60 # You may specify an explicit list of local users to chroot() to their home
 61 # directory. If chroot_local_user is YES, then this list becomes a list of
 62 # users to NOT chroot().
 63 # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
 64 # the user does not have write access to the top level directory within the
 65 # chroot)
 66 chroot_local_user=YES
 67 chroot_list_enable=YES
 68 # (default follows)
 69 #chroot_list_file=/etc/vsftpd/chroot_list
 70 #
 71 # You may activate the "-R" option to the builtin ls. This is disabled by
 72 # default to avoid remote users being able to cause excessive I/O on large
 73 # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
 74 # the presence of the "-R" option, so there is a strong case for enabling it.
 75 #ls_recurse_enable=YES
 76 #
 77 # When "listen" directive is enabled, vsftpd runs in standalone mode and
 78 # listens on IPv4 sockets. This directive cannot be used in conjunction
 79 # with the listen_ipv6 directive.
 80 # 只监听ipv4的地址
 81 listen=YES
 82 #
 83 # This directive enables listening on IPv6 sockets. By default, listening
 84 # on the IPv6 "any" address (::) will accept connections from both IPv6
 85 # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
 86 # sockets. If you want that (perhaps because you want to listen on specific
 87 # addresses) then you must run two copies of vsftpd with two configuration
 88 # files.
 89 # Make sure, that one of the listen options is commented !!
 90 #listen_ipv6=YES
 91 
 92 pam_service_name=vsftpd
 93 userlist_enable=YES
 94 tcp_wrappers=YES
 95 # 下面是自己添加的
 96 anon_root=/home/pageftp/open
 97 virtual_use_local_privs=YES
 98 guest_enable=YES
 99 guest_username=pageftp
100 # 虚拟用户的配置文件(可以对每一个虚拟用户进行单独的权限配置)
101 user_config_dir=/etc/vsftpd/vconf/
102 chroot_local_user=YES
103 allow_writeable_chroot=YES

启动ftp服务

1 sudo systemctl enable vsftpd 
2 sudo service vsftpd start

可能出现的问题

  • 出现“500 OOPS: vsftpd: refusing to run with writable root inside chroot ()”错误
vi /etc/vsftpd.conf (或者是在/etc/vsftpd/vsftpd.conf,总之知道自己服务器的配置文件)
添加 allow_writeable_chroot=YES

保存退出
service vsftpd restart 重启vsftp服务,即可正常登录
  • 出现不能修改目录的错误
    检查是否目录没有开通相应权限

ftp相关命令

1、连接ftp服务器

  • 格式:ftp [hostname | ip-address]a)在linux命令行下输入:ftp 网址/ip 询问你用户名和口令,分别输入用户名和相应密码,待认证通过即可。

2、下载文件
下载文件通常用get和mget这两条命令:

  • get 格式:get [remote-file] [local-file]将文件从远端主机中传送至本地主机中.如要获取服务器上/ftp/1.rar,则ftp> get /ftp/1.rar 1.rar (回车)
  • mget 格式:mget [remote-files]从远端主机接收一批文件至本地主机.如要获取服务器上/ftp下的所有文件,则ftp> cd /ftpftp> mget . (回车)
    注意:文件都下载到了linux主机的当前目录下。

3、上传文件

  • put 格式:put local-file [remote-file]将本地一个文件传送至远端主机中.如要把本地的1.zip传送到远端主机/ftp,并改名为1.rarftp> put 1.zip /ftp1.rar (回车)
  • mput 格式:mput local-files将本地主机中一批文件传送至远端主机.如要把本地当前目录下所有rar文件上传到服务器/ftp 下ftp> cd /ftp (回车)ftp> mput *.rar (回车)

4、断开连接

  • bye/by:中断与服务器的连接。

5、切换目录

  • lcd 查看本地目录
  • cd 查看远程目录
  • cd 目录 远程目录切换(可配置权限)
  • cd .. 返回上级
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,651评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,468评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,931评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,218评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,234评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,198评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,084评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,926评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,341评论 1 311
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,563评论 2 333
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,731评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,430评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,036评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,676评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,829评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,743评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,629评论 2 354

推荐阅读更多精彩内容