当前位置: 首页 > news >正文

LINUX64 FTP 1; rsync inotify.sh脚本说明

FTP

vsftpd 文件配置


Last login: Tue Jun  3 19:06:10 2025 from 192.168.235.1
[root@code ~]# grep -v ^# /etc/vsftpd/vsftpd.conf
anonymous_enable=YES 
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YESpam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
[root@code ~]#

anonymous_enable=YES 支持匿名用户访问
local_enable=YES 支持非匿名用户,普通账户登录,默认进入到自己家目录
write_enable 写总开关
local_umask=022 反掩码 file:644 rw-r-- r-- dir:755
dirmessage_enable=YES 启用消息功能
xfelog_enable=YES 开启或启用xfelog日志
connect_from_port_20=YES 支持主动模式(默认被动模式)
xferlog_sft_format=YES xferlog日志格式
listen=YES ftp服务独立模式下的监听
pam_service_name=vsftpd 指定认证文件
userlist_enable=YES 启用用户列表
tcp_wrappers=YES 支持tcp_wrappers功能(Ftp限速)
在这里插入图片描述

RSYNC

rsync inotify 实现代码实时同步

客户端:安装inotify

tar -xf inotify-tools.tar.gz -C /usr/local
cd /usr/local
./configure
make
make install

客户端:编写Inotify.sh

#!/bin/bash
inotifywait -mrq -e create,delete,modify,attrib,move /app/java_project|while read events
do
rsync -av --delete /app/java_project/ root@192.168.235.100:/backup/app1_java
echo "$(date '+%F %T') 出现事件$events">>/var/log/rsync.log 2>&1
done

调用/usr/bin/下的inotifywait 对备份目录中的创造、删除、修改、移动、attrib(元数据属性发生改变)行为进行一直(m)递归(r 目录+文件)获取操作信息不输出(q)监控
行为|行为
左边行为的stdout 通过 管道符| 传给右边行为的stdin 右边行为执行stdin 当监控到事件发生时,传递给右边的events执行while read events

events理解

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
(修正):传递给右边的read命令的stdin read 将变量赋给events

read作用

在这里插入图片描述
此时执行while循环:
执行同步操作:本机的/app/java_project 和 192.168.235.100的/backup/app1_java 进行同步
读取

echo作用

在这里插入图片描述
将 时间$(date ‘+%F %T’) 加入到

$作用

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
总结:将以下内容输出到stdout (echo “”)(疑问 ""作用,和’'区别 shell脚本中),
将时间结果:(date ‘+ %F %T’) 插入($)到字符串中 ( d a t e ′ + (date '+%F %T') 获取变量(events)的值,并插入到字符串中: (date+ $events

chmod +x rsync.sh

后台一直运行

nohup ./inotify.sh &

今日源码:

192.168.235.20

root@192.168.235.20's password:┌────────────────────────────────────────────────────────────────────┐│                        • MobaXterm 20.0 •                          ││            (SSH client, X-server and networking tools)             ││                                                                    ││ ➤ SSH session to root@192.168.235.20                               ││   • SSH compression : ✘                                            ││   • SSH-browser     : ✔                                            ││   • X11-forwarding  : ✔  (remote display is forwarded through SSH) ││   • DISPLAY         : ✔  (automatically set on remote server)      ││                                                                    ││ ➤ For more info, ctrl+click on help or visit our website           │└────────────────────────────────────────────────────────────────────┘Last login: Tue Jun  3 19:06:10 2025 from 192.168.235.1
[root@code ~]# grep -v ^# /etc/vsftpd/vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YESpam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
[root@code ~]# man 5 vsftpd.conf
您在 /var/spool/mail/root 中有新邮件
[root@code ~]# tail -6 /etc/userpasswd
tail: 无法打开"/etc/userpasswd" 读取数据: 没有那个文件或目录
[root@code ~]# tail -6 /etc/passwd
harry:x:1017:1017::/home/mahei/redhat/harry:/bin/bash
netasha:x:1018:1018::/home/netasha:/bin/bash
sarsh:x:1019:1228::/home/sarsh:/bin/bash
OOO:x:1020:1020::/home/OOO:/bin/bash
jerry:x:1021:1229::/home/jerry:/bin/bash
kefu:x:1022:1022::/home/kefu:/bin/bash
[root@code ~]# vim /etc/vsftpd/vsftpd.conf
您在 /var/spool/mail/root 中有邮件
[root@code ~]# cat /etc/vsftpd/vsftpd.conf
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# 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. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" 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_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# 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().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" 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 "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=NO
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
listen_ipv6=YESpam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
[root@code ~]# ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.235.20  netmask 255.255.255.0  broadcast 192.168.235.255inet6 fe80::20c:29ff:fe97:845e  prefixlen 64  scopeid 0x20<link>ether 00:0c:29:97:84:5e  txqueuelen 1000  (Ethernet)RX packets 1084621  bytes 442496040 (421.9 MiB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 955185  bytes 490671865 (467.9 MiB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0您在 /var/spool/mail/root 中有邮件
[root@code ~]# systemctl restart vsftpd
您在 /var/spool/mail/root 中有邮件
[root@code ~]# mkdir /date/kefu -p
[root@code ~]# vim /etc/vsftpd/vsftpd.conf
您在 /var/spool/mail/root 中有邮件
[root@code ~]# vim /etc/vsftp/vsftp.conf
[root@code ~]# vim /etc/vsftp/vsftpd.conf
您在 /var/spool/mail/root 中有邮件
[root@code ~]# vim /etc/vsftpd/vsftpd.conf
您在 /var/spool/mail/root 中有邮件
[root@code ~]# systemctl restart vsftpd
[root@code ~]# ls
2-1.java  alll1            app       axel-2.4.tar.gz  cc.conf  initial-setup-ks.cfg       ok   readme7
2.java    anaconda-ks.cfg  axel-2.4  bb.conf          code     inotify-tools-3.13.tar.gz  okl  readme.txt
您在 /var/spool/mail/root 中有邮件
[root@code ~]# cd /usr/local
[root@code local]# ls
bin  etc  games  include  inotify-tools-3.13  lib  lib64  libexec  sbin  share  src
[root@code local]#

192.168.235.100

     ┌────────────────────────────────────────────────────────────────────┐│                        • MobaXterm 20.0 •                          ││            (SSH client, X-server and networking tools)             ││                                                                    ││ ➤ SSH session to code@192.168.235.100                              ││   • SSH compression : ✘                                            ││   • SSH-browser     : ✔                                            ││   • X11-forwarding  :(remote display is forwarded through SSH) ││   • DISPLAY         :(automatically set on remote server)      ││                                                                    ││ ➤ For more info, ctrl+click on help or visit our website           │└────────────────────────────────────────────────────────────────────┘Last login: Tue Jun  3 19:06:01 2025 from 192.168.235.1
[code@code ~]$ su - caozx26
su: user caozx26 does not exist
[code@code ~]$ su - caozx26420
密码:
su: 鉴定故障
[code@code ~]$ su - caozx26420
密码:
上一次登录:二 63 22:35:28 CST 2025pts/3 上
最后一次失败的登录:三 64 20:57:11 CST 2025pts/2 上
最有一次成功登录后有 1 次失败的登录尝试。
[caozx26420@code ~]$ sudo su
[sudo] caozx26420 的密码:
[root@code caozx26420]# useradd kefu
[root@code caozx26420]# echo 123|passwd --stdin kefu
更改用户 kefu 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@code caozx26420]#

相关文章:

  • 【统计方法】蒙特卡洛
  • 分析Web3下数据保护的创新模式
  • 05.字母异位词分组
  • 量子通信:从科幻走向现实的未来通信技术
  • 线性模型选择中容易被忽视的关键洞察
  • Java八股文——Redis篇
  • 前端组件推荐 Swiper 轮播与 Lightbox 灯箱组件深度解析
  • grafana 批量视图备份及恢复(含数据源)
  • Spring Boot微服务架构(十一):独立部署是否抛弃了架构优势?
  • Windows下运行Redis并设置为开机自启的服务
  • 智慧城市建设方案
  • 小白的进阶之路系列之十四----人工智能从初步到精通pytorch综合运用的讲解第七部分
  • yaffs2目录搜索上下文数据结构struct yaffsfs_dirsearchcontext yaffsfs_dsc[] 详细解析
  • 10.MySQL索引特性
  • cv::FileStorage用法
  • Qt Creator工具编译器配置
  • Linux防火墙实战演练
  • 基于 PyTorch 的 VGG16 深度学习人脸识别检测系统的实现+ui界面
  • 机器学习的数学基础:线性模型
  • unix/linux,sudo,其高级使用
  • 开原网站制作/什么是seo网站优化
  • 动漫网站开发毕业设计/2022年今天新闻联播
  • 淘宝网站建设弄什么类目/如何推广平台
  • 怎么做网站表格/商丘seo外包
  • 邵阳网站建设的话术/市场营销四大基本策略
  • wordpress 当前页/企业seo顾问服务