特殊权限
[root@VM_141_154_centos ~]# ls -ld /tmp drwxrwxrwt. 8 root root 4096 Apr 5 08:11 /tmp
- /tmp/ 公共目录,凡是linux用户都可对这个目录下为所欲为
- 但是只有目录属主和root才能删除这个目录
- 用途一般是把一个目录放开,共享目录,但不安全
特殊权限对应的数字小结:
suid 4000 权限字符s(S),用户位上的x位上设置。 授权方法 chmod 4755 oldboy.txt sgid 2000 权限字符s(S),用户组位的x位上设置 chmod 2755 oldboy.txt 粘滞位1000 权限字符t(T),其他用户位的x位上设置。 chmod 1755 /tmp 如果对应位有x,则字符权限表现为小写,否则表现为大写
特殊权限设置方法:
chmod g+s test chmod u+s test chmod o+t test
chattr和lsattr(设置特殊属性和查看特殊属性)
- i 参数
[root@VM_141_154_centos oldboy]# chattr +i hello.py [root@VM_141_154_centos oldboy]# lsattr hello.py ----i----------- hello.py
- 删不了改不了
[root@VM_141_154_centos oldboy]# rm -f hello.py rm: cannot remove 'hello.py': Operation not permitted [root@VM_141_154_centos oldboy]# >hello.py -bash: hello.py: Permission denied
- 解除 i 属性
[root@VM_141_154_centos oldboy]# chattr -i hello.py [root@VM_141_154_centos oldboy]# ls -l hello.py -rwxr-xr-x 1 root root 46 Apr 3 10:29 hello.py
- a 参数 能加东西,删不了
网站集群防木马
根据不同的url找不同的服务器,有静态网站和动态网站
- 不同的服务器设置不同的文件权限
- 服务器中文件不可执行
- 从哪上传,就不能从哪访问
- http方法控制,上传post,下载get,其他方法一概不能用
- 80端口严格控制,后门22改为52113,修改端口
- 禁止root远程连接
- 只监听内网
- vpn
linux 定时任务Crond
-
Crond是什么
定期执行任务或程序
-
定时任务频率是分钟
-
为什么要定时任务
实时备份,定时备份,定时任务
linux 系统自身定期执行的任务工作:系统周期性自行执行的任务工作,
如:轮训系统日志,备份系统数据,清理系统缓存等,这些无需人为干预。
-
查看定时任务
1 [root@VM_141_154_centos ~]# crontab -l 2 #secu-tcs-agent monitor, install at Mon Oct 31 14:35:31 CST 2016 3 * * * * * /usr/local/sa/agent/secu-tcs-agent-mon-safe.sh /usr/local/sa/agent > /dev/null 2>&1 4 */1 * * * * /usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 & 5 */20 * * * * /usr/sbin/ntpdate ntpupdate.tencentyun.com >/dev/null &
- 定时任务软件种类
1 atd 执行一次就结束 2 3 crond 守护进程 一直运行着的
crontab指定参数(将要书写时)
1 [root@VM_141_154_centos ~]# crontab -h 2 crontab: invalid option -- 'h' 3 crontab: usage error: unrecognized option 4 Usage: 5 crontab [options] file 6 crontab [options] 7 crontab -n [hostname] 8 9 Options: 10 -u <user> define user 11 -e edit user's crontab 12 -l list user's crontab 13 -r delete user's crontab 14 -i prompt before deleting 15 -n <host> set host in cluster to run users' crontabs 16 -c get host in cluster to run users' crontabs 17 -s selinux context 18 -x <mask> enable debugging 19 20 Default operation is replace, per 1003.2
1 crontab -e 相当于 vi /var/spool/cron/root 2 crontab -l 相当于 cat /var/spool/cron/root
指定用户的定时任务
1 书写定时任务 2 [root@VM_141_154_centos ~]# crontab -u oldboy -e 3 查看定时任务 4 [root@VM_141_154_centos ~]# crontab -u oldboy -l 5 ###########
具体定时任务的语法(分时日月周 * 每的意思)
1 [root@VM_141_154_centos ~]# cat /etc/crontab 2 SHELL=/bin/bash 3 PATH=/sbin:/bin:/usr/sbin:/usr/bin 4 MAILTO=root 5 6 # For details see man 4 crontabs 7 8 # Example of job definition: 9 # .---------------- minute (0 - 59) 10 # | .------------- hour (0 - 23) 11 # | | .---------- day of month (1 - 31) 12 # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... 13 # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat 14 # | | | | | 15 # * * * * * user-name command to be executed
一些书写定时任务的语法
1 */5 每5分钟 2 3 00 23 * * * 每天23点 4 5 * * * * * 6 0-59/1 7 8 -范围 17-19 17,18,19(整数) 9 10 , 分割词段 17,18,19 11 12 /n 每单位时间 13 14 30 3-5,17-19 * * * /bin/sh/ 15 16 30 */6 * * * /bin/sh/ 每隔6个小时的半点时刻 17 18 30 8-18/2 * * * 早晨8点到下午18点之间每隔2小时的30分钟时刻 19 20 * 23,00-07/1 * * * 23点每分,00点到7点每隔一小时的每分 21 22 以上有误区 并不代表晚上23点和早上0-7点每隔一个小时
书写定时任务的准备
1.脚本有一个固定放脚本的地方 如:/server/scripts
[root@VM_141_154_centos ~]# mkdir /server/scripts -p
[root@VM_141_154_centos ~]# echo 'date +%F' >oldboy.sh
[root@VM_141_154_centos ~]# cat oldboy.sh
date +%F
2.脚本一般都无可执行权限,但是不用chmod +x而是用sh或/bin/sh
1 [root@VM_141_154_centos ~]# /server/scripts/oldboy.sh 2 -bash: /server/scripts/oldboy.sh: Permission denied 3 [root@VM_141_154_centos ~]# sh /server/scripts/oldboy.sh 4 2017-04-06 5 [root@VM_141_154_centos ~]# ll /server/scripts/oldboy.sh 6 -rw-r--r-- 1 root root 9 Apr 6 09:33 /server/scripts/oldboy.sh 7 [root@VM_141_154_centos ~]# /bin/sh /server/scripts/oldboy.sh 8 2017-04-06
书写定时任务的若干要领方法:
要领1:为定时任务规则加必要的注释 什么人,什么时间,因为谁,做了什么事 要领2:定时任务命令或程序最好写到脚本里执行 要领3:执行shell脚本任务前加/bin/sh 要领4:定时任务命令或脚本结尾加>/dev/null 2>&1不加可能将邮件队填满,磁盘inode填满 要领5:在指定用户下执行相关的定时任务 要领6:在生产任务程序不要随意打印输出信息 要领7:定时任务执行的脚本要规范化(/server/scripts) 要领8:配置定时任务规范操作过程 要领9:定时任务脚本中的程序命令尽量用全路径(和系统变量的识别关) 要领10:时间变量问题用\%转义,最好用脚本 要领11:环境变量问题